Skip to content

Commit

Permalink
MDL-38878 behat: Also update composer dependencies after site install…
Browse files Browse the repository at this point in the history
…/reinstall
  • Loading branch information
David Monllao committed Apr 8, 2013
1 parent 422f68f commit 7b33327
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
22 changes: 9 additions & 13 deletions admin/tool/behat/cli/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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__);
Expand Down
39 changes: 39 additions & 0 deletions lib/testing/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 7b33327

Please sign in to comment.