From 7b333271262b00789addaa04ebd99d1765e822b4 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 8 Apr 2013 09:01:07 +0800 Subject: [PATCH] MDL-38878 behat: Also update composer dependencies after site install/reinstall --- admin/tool/behat/cli/init.php | 22 ++++++++------------ lib/testing/lib.php | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/admin/tool/behat/cli/init.php b/admin/tool/behat/cli/init.php index ca68c16b29181..fd11b088bca8e 100644 --- a/admin/tool/behat/cli/init.php +++ b/admin/tool/behat/cli/init.php @@ -41,14 +41,22 @@ echo "Behat test environment already installed\n"; } else if ($code == BEHAT_EXITCODE_INSTALL) { + + testing_update_composer_dependencies(); + // Behat and dependencies are installed and we need to install the test site. + chdir(__DIR__); passthru("php util.php --install", $code); if ($code != 0) { exit($code); } } else if ($code == BEHAT_EXITCODE_REINSTALL) { + + testing_update_composer_dependencies(); + // Test site data is outdated. + chdir(__DIR__); passthru("php util.php --drop", $code); if ($code != 0) { exit($code); @@ -62,19 +70,7 @@ } else if ($code == BEHAT_EXITCODE_COMPOSER) { // Missing Behat dependencies. - // Changing to moodle dirroot to run composer related commands at project level. - chdir(__DIR__ . '/../../../..'); - if (!file_exists(__DIR__ . '/../../../../composer.phar')) { - passthru("curl http://getcomposer.org/installer | php", $code); - if ($code != 0) { - exit($code); - } - } - - passthru("php composer.phar update --dev", $code); - if ($code != 0) { - exit($code); - } + testing_update_composer_dependencies(); // Returning to admin/tool/behat/cli. chdir(__DIR__); diff --git a/lib/testing/lib.php b/lib/testing/lib.php index 0713d6bde982e..4cee9b1b61c31 100644 --- a/lib/testing/lib.php +++ b/lib/testing/lib.php @@ -128,3 +128,42 @@ function testing_error($errorcode, $text = '') { echo($text."\n"); exit($errorcode); } + +/** + * Updates the composer installer and the dependencies. + * + * Includes --dev dependencies. + * + * @return void exit() if something goes wrong + */ +function testing_update_composer_dependencies() { + + // To restore the value after finishing. + $cwd = getcwd(); + + // Dirroot. + chdir(__DIR__ . '/../..'); + + // Download composer.phar if we can. + if (!file_exists(__DIR__ . '/../../composer.phar')) { + passthru("curl http://getcomposer.org/installer | php", $code); + if ($code != 0) { + exit($code); + } + } else { + + // If it is already there update the installer. + passthru("php composer.phar self-update", $code); + if ($code != 0) { + exit($code); + } + } + + // Update composer dependencies. + passthru("php composer.phar update --dev", $code); + if ($code != 0) { + exit($code); + } + + chdir($cwd); +}