From 26cc3cfd19b13a42cc1f5e1474e0f274ed9ee419 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 19 Dec 2019 20:27:16 +0000 Subject: [PATCH] Tests: Skip external HTTP test for recommended PHP and MySQL versions on 503 errors. Fixes #49049. git-svn-id: https://develop.svn.wordpress.org/trunk@46998 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/external-http/basic.php | 40 +++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/external-http/basic.php b/tests/phpunit/tests/external-http/basic.php index 0da6b33511..1038e66c33 100644 --- a/tests/phpunit/tests/external-http/basic.php +++ b/tests/phpunit/tests/external-http/basic.php @@ -5,25 +5,35 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { function test_readme() { - // This test is designed to only run on trunk/master + // This test is designed to only run on trunk/master. $this->skipOnAutomatedBranches(); $readme = file_get_contents( ABSPATH . 'readme.html' ); preg_match( '#Recommendations.*PHP version ([0-9.]*)#s', $readme, $matches ); - $response = wp_remote_get( 'https://secure.php.net/supported-versions.php' ); + $response = wp_remote_get( 'https://www.php.net/supported-versions.php' ); $this->skipTestOnTimeout( $response ); $response_code = wp_remote_retrieve_response_code( $response ); + $response_body = wp_remote_retrieve_body( $response ); + if ( 200 !== $response_code ) { - $this->fail( sprintf( 'Could not contact PHP.net to check versions. Response code: %s', $response_code ) ); + $error_message = sprintf( + 'Could not contact PHP.net to check versions. Response code: %s. Response body: %s', + $response_code, + $response_body + ); + + if ( 503 === $response_code ) { + $this->markTestSkipped( $error_message ); + } + + $this->fail( $error_message ); } - $php = wp_remote_retrieve_body( $response ); - - preg_match_all( '#\s*\s*]*>\s*([0-9.]*)#s', $php, $phpmatches ); + preg_match_all( '#\s*\s*]*>\s*([0-9.]*)#s', $response_body, $phpmatches ); $this->assertContains( $matches[1], $phpmatches[1], "readme.html's Recommended PHP version is too old. Remember to update the WordPress.org Requirements page, too." ); @@ -34,13 +44,23 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { $this->skipTestOnTimeout( $response ); $response_code = wp_remote_retrieve_response_code( $response ); + $response_body = wp_remote_retrieve_body( $response ); + if ( 200 !== $response_code ) { - $this->fail( sprintf( 'Could not contact dev.MySQL.com to check versions. Response code: %s', $response_code ) ); + $error_message = sprintf( + 'Could not contact dev.MySQL.com to check versions. Response code: %s. Response body: %s', + $response_code, + $response_body + ); + + if ( 503 === $response_code ) { + $this->markTestSkipped( $error_message ); + } + + $this->fail( $error_message ); } - $mysql = wp_remote_retrieve_body( $response ); - - preg_match( '#(\d{4}-\d{2}-\d{2}), General Availability#', $mysql, $mysqlmatches ); + preg_match( '#(\d{4}-\d{2}-\d{2}), General Availability#', $response_body, $mysqlmatches ); // Per https://www.mysql.com/support/, Oracle actively supports MySQL releases for 5 years from GA release $mysql_eol = strtotime( $mysqlmatches[1] . ' +5 years' );