WordPress.org

Make WordPress Core

Changeset 46682


Ignore:
Timestamp:
11/09/2019 03:36:19 AM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Skip test_readme() if the HTTP request to secure.php.net or dev.mysql.com failed on timeout.

Move skipTestOnTimeout() to WP_UnitTestCase_Base to avoid duplication.

See #44613.

Location:
trunk/tests/phpunit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r46612 r46682  
    181181
    182182    /**
    183      * Allow tests to be skipped on some automated runs
     183     * Allow tests to be skipped on some automated runs.
    184184     *
    185185     * For test runs on Travis for something other than trunk/master
     
    221221            $this->markTestSkipped( 'Test does not run on Multisite' );
    222222        }
     223    }
     224
     225    /**
     226     * Allow tests to be skipped if the HTTP request times out.
     227     *
     228     * @param array|WP_Error $response HTTP response.
     229     */
     230    public function skipTestOnTimeout( $response ) {
     231        if ( ! is_wp_error( $response ) ) {
     232            return;
     233        }
     234        if ( 'connect() timed out!' === $response->get_error_message() ) {
     235            $this->markTestSkipped( 'HTTP timeout' );
     236        }
     237
     238        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     239            $this->markTestSkipped( 'HTTP timeout' );
     240        }
     241
     242        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     243            $this->markTestSkipped( 'HTTP timeout' );
     244        }
     245
    223246    }
    224247
  • trunk/tests/phpunit/tests/external-http/basic.php

    r46586 r46682  
    1414
    1515        $response = wp_remote_get( 'https://secure.php.net/supported-versions.php' );
     16
     17        $this->skipTestOnTimeout( $response );
     18
    1619        if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
    1720            $this->fail( 'Could not contact PHP.net to check versions.' );
    1821        }
     22
    1923        $php = wp_remote_retrieve_body( $response );
    2024
     
    2630
    2731        $response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" );
     32
     33        $this->skipTestOnTimeout( $response );
     34
    2835        if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
    2936            $this->fail( 'Could not contact dev.MySQL.com to check versions.' );
    3037        }
     38
    3139        $mysql = wp_remote_retrieve_body( $response );
    3240
  • trunk/tests/phpunit/tests/http/base.php

    r46586 r46682  
    1818    protected $http_request_args;
    1919
    20     /**
    21      * Mark test as skipped if the HTTP request times out.
    22      */
    23     function skipTestOnTimeout( $response ) {
    24         if ( ! is_wp_error( $response ) ) {
    25             return;
    26         }
    27         if ( 'connect() timed out!' === $response->get_error_message() ) {
    28             $this->markTestSkipped( 'HTTP timeout' );
    29         }
    30 
    31         if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
    32             $this->markTestSkipped( 'HTTP timeout' );
    33         }
    34 
    35         if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
    36             $this->markTestSkipped( 'HTTP timeout' );
    37         }
    38 
    39     }
    40 
    4120    function setUp() {
    4221        parent::setUp();
  • trunk/tests/phpunit/tests/http/functions.php

    r46586 r46682  
    66 */
    77class Tests_HTTP_Functions extends WP_UnitTestCase {
    8 
    9     /**
    10      * Mark test as skipped if the HTTP request times out.
    11      */
    12     function skipTestOnTimeout( $response ) {
    13         if ( ! is_wp_error( $response ) ) {
    14             return;
    15         }
    16         if ( 'connect() timed out!' === $response->get_error_message() ) {
    17             $this->markTestSkipped( 'HTTP timeout' );
    18         }
    19 
    20         if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
    21             $this->markTestSkipped( 'HTTP timeout' );
    22         }
    23 
    24         if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
    25             $this->markTestSkipped( 'HTTP timeout' );
    26         }
    27 
    28     }
    298
    309    public function setUp() {
Note: See TracChangeset for help on using the changeset viewer.