From cd7544d403a9096eaadbee61eee21513a72cb7c8 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Tue, 23 Jun 2015 10:11:56 +0800 Subject: [PATCH] MDL-50611 testing: Extra http status code checking --- admin/tool/behat/cli/init.php | 2 +- lib/behat/lib.php | 3 ++- lib/testing/lib.php | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/admin/tool/behat/cli/init.php b/admin/tool/behat/cli/init.php index 8a3fa88602e..9a7c9da4183 100644 --- a/admin/tool/behat/cli/init.php +++ b/admin/tool/behat/cli/init.php @@ -46,7 +46,7 @@ $output = null; exec("php util.php --diag", $output, $code); // Ensure we have composer installed, before we install or re-install test site. -if ($code == BEHAT_EXITCODE_COMPOSER || $code == BEHAT_EXITCODE_INSTALL || $code == BEHAT_EXITCODE_REINSTALL) { +if ($code == TESTING_EXITCODE_COMPOSER || $code == BEHAT_EXITCODE_INSTALL || $code == BEHAT_EXITCODE_REINSTALL) { testing_update_composer_dependencies(); chdir(__DIR__); exec("php util.php --diag", $output, $code); diff --git a/lib/behat/lib.php b/lib/behat/lib.php index 4868d7ff87f..86718a92a8a 100644 --- a/lib/behat/lib.php +++ b/lib/behat/lib.php @@ -38,6 +38,7 @@ define('BEHAT_EXITCODE_REQUIREMENT', 251); define('BEHAT_EXITCODE_PERMISSIONS', 252); define('BEHAT_EXITCODE_REINSTALL', 253); define('BEHAT_EXITCODE_INSTALL', 254); +define('BEHAT_EXITCODE_COMPOSER', 255); define('BEHAT_EXITCODE_INSTALLED', 256); /** @@ -304,4 +305,4 @@ function behat_is_requested_url($url) { } return false; -} \ No newline at end of file +} diff --git a/lib/testing/lib.php b/lib/testing/lib.php index bf567e6a0bc..04bf85cd5db 100644 --- a/lib/testing/lib.php +++ b/lib/testing/lib.php @@ -28,7 +28,7 @@ /** * Composer error exit status. * - * @var integer + * @var int */ define('TESTING_EXITCODE_COMPOSER', 255); @@ -188,10 +188,10 @@ function testing_update_composer_dependencies() { // Download or update composer.phar. Unfortunately we can't use the curl // class in filelib.php as we're running within one of the test platforms. if (!file_exists($composerpath)) { - $file = @fopen($composerpath, 'w+'); + $file = @fopen($composerpath, 'w'); if ($file === false) { $errordetails = error_get_last(); - $error = sprintf("Unable to open composer.phar\nPHP error: %s", + $error = sprintf("Unable to create composer.phar\nPHP error: %s", $errordetails['message']); testing_error(TESTING_EXITCODE_COMPOSER, $error); } @@ -203,6 +203,7 @@ function testing_update_composer_dependencies() { $curlerrno = curl_errno($curl); $curlerror = curl_error($curl); + $curlinfo = curl_getinfo($curl); curl_close($curl); fclose($file); @@ -211,6 +212,14 @@ function testing_update_composer_dependencies() { $error = sprintf("Unable to download composer.phar\ncURL error (%d): %s", $curlerrno, $curlerror); testing_error(TESTING_EXITCODE_COMPOSER, $error); + } else if ($curlinfo['http_code'] === 404) { + if (file_exists($composerpath)) { + // Deleting the resource as it would contain HTML. + unlink($composerpath); + } + $error = sprintf("Unable to download composer.phar\n" . + "404 http status code fetching $composerurl"); + testing_error(TESTING_EXITCODE_COMPOSER, $error); } } else { passthru("php composer.phar self-update", $code);