MDL-37046 behat: Integrating build config file into runtests action

This commit is contained in:
David Monllao 2012-10-15 16:00:36 +08:00
parent 6d994c510f
commit 8cdc0ce8a4
4 changed files with 53 additions and 54 deletions

View File

@ -33,7 +33,6 @@ list($options, $unrecognized) = cli_get_params(
array(
'help' => false,
'stepsdefinitions' => false,
'buildconfigfile' => false,
'runtests' => false,
'filter' => false,
'tags' => false,
@ -51,7 +50,6 @@ Ensure the user who executes the action has permissions over behat installation
Options:
--stepsdefinitions Displays the available steps definitions (accepts --filter=\"\" option to restrict the list to the matching definitions)
--buildconfigfile Updates the Moodle components config file
--runtests Runs the tests (accepts --tags=\"\" option to execute only the matching tests and --extra=\"\" to specify extra behat options)
-h, --help Print out this help
@ -70,7 +68,7 @@ if ($unrecognized) {
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
$commands = array('stepsdefinitions', 'buildconfigfile', 'runtests');
$commands = array('stepsdefinitions', 'runtests');
foreach ($commands as $command) {
if ($options[$command]) {
$action = $command;
@ -92,10 +90,6 @@ switch ($action) {
case 'runtests':
tool_behat::runtests($options['tags'], $options['extra']);
break;
case 'buildconfigfile':
tool_behat::buildconfigfile();
break;
}

View File

@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Behat info page
* Behat web runner
*
* @package tool_behat
* @copyright 2012 David Monllaó

View File

@ -24,8 +24,6 @@
$string['actionnotsupported'] = 'Action not supported';
$string['buildconfigfileinfo'] = 'Update the list of available acceptance tests';
$string['configfilesuccess'] = 'Config file successfully built';
$string['commandbuildconfigfile'] = 'Build config file';
$string['commandinfo'] = 'Info';
$string['commandruntests'] = 'Run tests';
$string['commandstepsdefinitions'] = 'Steps definitions list';

View File

@ -131,38 +131,6 @@ class tool_behat {
redirect(get_login_url());
}
/**
* Creates a file listing all the moodle with features and steps definitions
*/
public static function buildconfigfile() {
global $CFG;
if (!CLI_SCRIPT) {
confirm_sesskey();
}
// Gets all the components with features
$components = tests_finder::get_components_with_tests('features');
if ($components) {
$contents = 'features:' . PHP_EOL;
foreach ($components as $componentname => $path) {
$contents .= ' - ' . $path . PHP_EOL;
}
}
// Gets all the components with steps definitions
// TODO
$fullfilename = $CFG->dataroot . '/behat/config.yml';
if (!file_put_contents($fullfilename, $contents)) {
throw new file_exception('cannotcreatefile', $fullfilename);
}
echo self::get_header();
echo self::output_success(get_string('configfilesuccess', 'tool_behat'));
echo self::get_footer();
}
/**
* Runs the acceptance tests
* @param string $tags Restricts the executed tests to the ones that matches the tags
@ -176,6 +144,8 @@ class tool_behat {
}
self::check_behat_setup();
self::update_config_file();
echo self::get_header();
@set_time_limit(0);
@ -216,6 +186,30 @@ class tool_behat {
echo self::get_footer();
}
/**
* Updates the config file
* @throws file_exception
*/
private static function update_config_file() {
// Gets all the components with features
$components = tests_finder::get_components_with_tests('features');
if ($components) {
$contents = 'features:' . PHP_EOL;
foreach ($components as $componentname => $path) {
$contents .= ' - ' . $path . PHP_EOL;
}
}
// Gets all the components with steps definitions
// TODO
// Stores the file
$fullfilepath = self::get_behat_dir() . '/config.yml';
if (!file_put_contents($fullfilepath, $contents)) {
throw new file_exception('cannotcreatefile', $fullfilepath);
}
}
/**
* Checks whether the test database and dataroot is ready
@ -273,7 +267,6 @@ class tool_behat {
* @throws file_exception
*/
private static function enable_test_environment() {
global $CFG;
if (self::is_test_environment_enabled()) {
debugging('Test environment was already enabled');
@ -283,17 +276,7 @@ class tool_behat {
// Check that PHPUnit test environment is correctly set up.
self::test_environment_problem();
$behatdir = $CFG->dataroot . '/behat';
if (!is_dir($behatdir)) {
if (!mkdir($behatdir, $CFG->directorypermissions, true)) {
throw new file_exception('storedfilecannotcreatefiledirs');
}
}
if (!is_writable($behatdir)) {
throw new file_exception('storedfilecannotcreatefiledirs');
}
$behatdir = self::get_behat_dir();
$contents = '$CFG->phpunit_prefix and $CFG->phpunit_dataroot are currently used as $CFG->prefix and $CFG->dataroot';
$filepath = $behatdir . '/test_environment_enabled.txt';
@ -367,6 +350,30 @@ class tool_behat {
return $testenvfile;
}
/**
* Ensures the behat dir exists in moodledata
* @throws file_exception
* @return string Full path
*/
private static function get_behat_dir() {
global $CFG;
$behatdir = $CFG->dataroot . '/behat';
if (!is_dir($behatdir)) {
if (!mkdir($behatdir, $CFG->directorypermissions, true)) {
throw new file_exception('storedfilecannotcreatefiledirs');
}
}
if (!is_writable($behatdir)) {
throw new file_exception('storedfilecannotcreatefiledirs');
}
return $behatdir;
}
/**
* Returns header output
* @return string