mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 12:58:25 +01:00
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. Merges [46682] and [46996] to the 4.9 branch. See #51669. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@50096 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ca40f23840
commit
8b24b94ede
@ -182,7 +182,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow tests to be skipped on some automated runs
|
||||
* Allow tests to be skipped on some automated runs.
|
||||
*
|
||||
* For test runs on Travis for something other than trunk/master
|
||||
* we want to skip tests that only need to run for master.
|
||||
@ -224,6 +224,29 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow tests to be skipped if the HTTP request times out.
|
||||
*
|
||||
* @param array|WP_Error $response HTTP response.
|
||||
*/
|
||||
public function skipTestOnTimeout( $response ) {
|
||||
if ( ! is_wp_error( $response ) ) {
|
||||
return;
|
||||
}
|
||||
if ( 'connect() timed out!' === $response->get_error_message() ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister existing post types and register defaults.
|
||||
*
|
||||
|
@ -13,9 +13,14 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase {
|
||||
preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches );
|
||||
|
||||
$response = wp_remote_get( 'https://secure.php.net/supported-versions.php' );
|
||||
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
|
||||
$this->fail( 'Could not contact PHP.net to check versions.' );
|
||||
|
||||
$this->skipTestOnTimeout( $response );
|
||||
|
||||
$response_code = wp_remote_retrieve_response_code( $response );
|
||||
if ( 200 !== $response_code ) {
|
||||
$this->fail( sprintf( 'Could not contact PHP.net to check versions. Response code: %s', $response_code ) );
|
||||
}
|
||||
|
||||
$php = wp_remote_retrieve_body( $response );
|
||||
|
||||
preg_match_all( '#<tr class="stable">\s*<td>\s*<a [^>]*>\s*([0-9.]*)#s', $php, $phpmatches );
|
||||
@ -25,9 +30,14 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase {
|
||||
preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches );
|
||||
|
||||
$response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" );
|
||||
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
|
||||
$this->fail( 'Could not contact dev.MySQL.com to check versions.' );
|
||||
|
||||
$this->skipTestOnTimeout( $response );
|
||||
|
||||
$response_code = wp_remote_retrieve_response_code( $response );
|
||||
if ( 200 !== $response_code ) {
|
||||
$this->fail( sprintf( 'Could not contact dev.MySQL.com to check versions. Response code: %s', $response_code ) );
|
||||
}
|
||||
|
||||
$mysql = wp_remote_retrieve_body( $response );
|
||||
|
||||
preg_match( '#(\d{4}-\d{2}-\d{2}), General Availability#', $mysql, $mysqlmatches );
|
||||
|
@ -17,27 +17,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
|
||||
|
||||
protected $http_request_args;
|
||||
|
||||
/**
|
||||
* Mark test as skipped if the HTTP request times out.
|
||||
*/
|
||||
function skipTestOnTimeout( $response ) {
|
||||
if( ! is_wp_error( $response ) ){
|
||||
return;
|
||||
}
|
||||
if ( 'connect() timed out!' === $response->get_error_message() ){
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
|
||||
if ( is_callable( array('WP_Http', '_getTransport') ) ) {
|
||||
|
@ -6,27 +6,6 @@
|
||||
*/
|
||||
class Tests_HTTP_Functions extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Mark test as skipped if the HTTP request times out.
|
||||
*/
|
||||
function skipTestOnTimeout( $response ) {
|
||||
if ( ! is_wp_error( $response ) ) {
|
||||
return;
|
||||
}
|
||||
if ( 'connect() timed out!' === $response->get_error_message() ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
|
||||
$this->markTestSkipped( 'HTTP timeout' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
if ( ! extension_loaded( 'openssl' ) ) {
|
||||
$this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' );
|
||||
|
Loading…
x
Reference in New Issue
Block a user