Skip to content

Commit

Permalink
MDL-37046 behat: Windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Jan 29, 2013
1 parent 1c36cb2 commit 0922ef8
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions admin/tool/behat/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
*/
class tool_behat {

/**
* @var string Path where each component's tests are stored */
private static $behat_tests_path = '/tests/behat';

/** @var array Steps types */
private static $steps_types = array('given', 'when', 'then');

Expand Down Expand Up @@ -138,9 +134,10 @@ protected static function update_config_file($component = '', $testsrunner = tru
$components = tests_finder::get_components_with_tests('features');
if ($components) {
foreach ($components as $componentname => $path) {
$path = self::clean_path($path) . self::$behat_tests_path;
$path = self::clean_path($path) . self::get_behat_tests_path();
if (empty($featurespaths[$path]) && file_exists($path)) {
$featurespaths[$path] = $path;
$uniquekey = str_replace('\\', '/', $path);
$featurespaths[$uniquekey] = $path;
}
}
$features = array_values($featurespaths);
Expand Down Expand Up @@ -274,10 +271,10 @@ public static function get_components_steps_definitions() {
$stepsdefinitions = array();
foreach ($components as $componentname => $componentpath) {
$componentpath = self::clean_path($componentpath);
$diriterator = new DirectoryIterator($componentpath . self::$behat_tests_path);
$diriterator = new DirectoryIterator($componentpath . self::get_behat_tests_path());
$regite = new RegexIterator($diriterator, '|behat_.*\.php$|');

// All behat_*.php inside self::$behat_tests_path are added as steps definitions files.
// All behat_*.php inside self::get_behat_tests_path() are added as steps definitions files.
foreach ($regite as $file) {
$key = $file->getBasename('.php');
$stepsdefinitions[$key] = $file->getPathname();
Expand Down Expand Up @@ -309,16 +306,16 @@ public static function is_server_running() {
*/
protected static function clean_path($path) {

$path = rtrim($path, '/');
$path = rtrim($path, DIRECTORY_SEPARATOR);

$parttoremove = '/tests';
$parttoremove = DIRECTORY_SEPARATOR . 'tests';

$substr = substr($path, strlen($path) - strlen($parttoremove));
if ($substr == $parttoremove) {
$path = substr($path, 0, strlen($path) - strlen($parttoremove));
}

return rtrim($path, '/');
return rtrim($path, DIRECTORY_SEPARATOR);
}

/**
Expand Down Expand Up @@ -498,6 +495,16 @@ protected static function get_test_filepath() {
return $prefix . '/behat/test_environment_enabled.txt';
}


/**
* The relative path where components stores their behat tests
*
* @return string
*/
protected static function get_behat_tests_path() {
return DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'behat';
}

/**
* Ensures the behat dir exists in moodledata
* @throws file_exception
Expand Down

0 comments on commit 0922ef8

Please sign in to comment.