MDL-50611 testing: Extra http status code checking
authorDavid Monllao <davidm@moodle.com>
Tue, 23 Jun 2015 02:11:56 +0000 (10:11 +0800)
committerDavid Monllao <davidm@moodle.com>
Tue, 23 Jun 2015 02:34:18 +0000 (10:34 +0800)
lib/testing/lib.php

index bfe0c30..7bfd3c0 100644 (file)
@@ -28,7 +28,7 @@
 /**
  * Composer error exit status.
  *
 /**
  * Composer error exit status.
  *
- * @var integer
+ * @var int
  */
 define('TESTING_EXITCODE_COMPOSER', 255);
 
  */
 define('TESTING_EXITCODE_COMPOSER', 255);
 
@@ -191,10 +191,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)) {
     // 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();
         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);
         }
                              $errordetails['message']);
             testing_error(TESTING_EXITCODE_COMPOSER, $error);
         }
@@ -206,6 +206,7 @@ function testing_update_composer_dependencies() {
 
         $curlerrno = curl_errno($curl);
         $curlerror = curl_error($curl);
 
         $curlerrno = curl_errno($curl);
         $curlerror = curl_error($curl);
+        $curlinfo = curl_getinfo($curl);
 
         curl_close($curl);
         fclose($file);
 
         curl_close($curl);
         fclose($file);
@@ -214,6 +215,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);
             $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);
         }
     } else {
         passthru("php composer.phar self-update", $code);