. /** * CLI script to set up all the behat test environment. * * @package tool_behat * @copyright 2013 David MonllaĆ³ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ if (isset($_SERVER['REMOTE_ADDR'])) { die(); // No access from web! } // Force OPcache reset if used, we do not want any stale caches // when preparing test environment. if (function_exists('opcache_reset')) { opcache_reset(); } // Is not really necessary but adding it as is a CLI_SCRIPT. define('CLI_SCRIPT', true); define('CACHE_DISABLE_ALL', true); // Basic functions. require_once(__DIR__ . '/../../../../lib/clilib.php'); require_once(__DIR__ . '/../../../../lib/behat/lib.php'); // Changing the cwd to admin/tool/behat/cli. chdir(__DIR__); $output = null; exec("php util.php --diag", $output, $code); if ($code == 0) { 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); } passthru("php util.php --install", $code); if ($code != 0) { exit($code); } } else if ($code == BEHAT_EXITCODE_COMPOSER) { // Missing Behat dependencies. testing_update_composer_dependencies(); // Returning to admin/tool/behat/cli. chdir(__DIR__); passthru("php util.php --install", $code); if ($code != 0) { exit($code); } } else { // Generic error, we just output it. echo implode("\n", $output)."\n"; exit($code); } // Enable editing mode according to config.php vars. passthru("php util.php --enable", $code); if ($code != 0) { exit($code); } exit(0);