コード例 #1
0
ファイル: BehatConfigManager.php プロジェクト: rboyatt/mahara
 /**
  * Updates a config file
  *
  * The tests runner and the steps definitions list uses different
  * config files to avoid problems with concurrent executions.
  *
  * The steps definitions list can be filtered by plugin so it's
  * behat.yml is different from the $CFG->docroot one.
  *
  * @param  string $plugin Restricts the obtained steps definitions to the specified plugin
  * @param  string $testsrunner If the config file will be used to run tests
  * @return void
  */
 public static function update_config_file($plugin = '', $testsrunner = true)
 {
     global $CFG;
     // Behat must have a separate behat.yml to have access to the whole set of features and steps definitions.
     if ($testsrunner === true) {
         $configfilepath = BehatCommand::get_behat_dir() . '/behat.yml';
     } else {
         // Alternative for steps definitions filtering, one for each user.
         $configfilepath = self::get_steps_list_config_filepath();
     }
     // Get core features
     $features = array(dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/test/behat/features');
     // Gets all the plugins with features.
     $plugins = TestsFinder::get_plugins_with_tests('features');
     if ($plugins) {
         foreach ($plugins as $pluginname => $path) {
             $path = self::clean_path($path) . self::get_behat_tests_path();
             if (empty($featurespaths[$path]) && file_exists($path)) {
                 // Standarizes separator (some dirs. comes with OS-dependant separator).
                 $uniquekey = str_replace('\\', '/', $path);
                 $featurespaths[$uniquekey] = $path;
             }
         }
         $features = array_merge($features, array_values($featurespaths));
     }
     // Optionally include features from additional directories.
     if (!empty($CFG->behat_additionalfeatures)) {
         $features = array_merge($features, array_map("realpath", $CFG->behat_additionalfeatures));
     }
     $stepsdefinitions = array();
     // Find step definitions from core. They must be in the folder $MAHARA_ROOT/test/behat/stepdefinitions
     // The file name must be /^Behat[A-z0-9_]+\.php$/
     $regite = new RegexIterator(new DirectoryIterator(get_mahararoot_dir() . '/test/behat/stepdefinitions'), '|^Behat[A-z0-9_\\-]+\\.php$|');
     foreach ($regite as $file) {
         $key = $file->getBasename('.php');
         $stepsdefinitions[$key] = $file->getPathname();
     }
     // Gets all the plugins with steps definitions.
     $steps = self::get_plugins_steps_definitions();
     if ($steps) {
         foreach ($steps as $key => $filepath) {
             if ($plugin === '' || $plugin === $key) {
                 $stepsdefinitions[$key] = $filepath;
             }
         }
     }
     // We don't want the deprecated steps definitions here.
     if (!$testsrunner) {
         unset($stepsdefinitions['behat_deprecated']);
     }
     // Behat config file specifing the main context class,
     // the required Behat extensions and Mahara test wwwroot.
     $contents = self::get_config_file_contents($features, $stepsdefinitions);
     // Stores the file.
     if (!file_put_contents($configfilepath, $contents)) {
         behat_error(BEHAT_EXITCODE_PERMISSIONS, 'File ' . $configfilepath . ' can not be created');
     }
 }
コード例 #2
0
ファイル: util.php プロジェクト: sarahjcotton/mahara
 /**
  * Returns the path to behat YML config file
  * @return string
  */
 public static function get_behat_config_path()
 {
     return BehatCommand::get_behat_dir() . '/behat.yml';
 }
コード例 #3
0
ファイル: util.php プロジェクト: rboyatt/mahara
$settings->options = $options;
$settings->info = 'CLI tool to manage Behat integration in Mahara';
$cli->setup($settings);
try {
    if ($cli->get_cli_param('install')) {
        BehatTestingUtil::install_site();
        cli::cli_exit("\nAcceptance test site is installed\n");
    } else {
        if ($cli->get_cli_param('drop')) {
            TestLock::acquire('behat');
            BehatTestingUtil::drop_site();
            cli::cli_exit("\nAcceptance tests site dropped\n");
        } else {
            if ($cli->get_cli_param('enable')) {
                BehatTestingUtil::start_test_mode();
                $runtestscommand = BehatCommand::get_behat_command(true) . ' --config ' . BehatConfigManager::get_behat_cli_config_filepath();
                cli::cli_exit("\nAcceptance tests environment enabled on {$CFG->behat_wwwroot}, to run the tests use:\n " . $runtestscommand . "\n");
            } else {
                if ($cli->get_cli_param('disable')) {
                    BehatTestingUtil::stop_test_mode();
                    cli::cli_exit("\nAcceptance test site is disabled\n");
                } else {
                    if ($cli->get_cli_param('diag')) {
                        $code = BehatTestingUtil::get_behat_status();
                        exit($code);
                    } else {
                        if ($cli->get_cli_param('config')) {
                            $code = BehatTestingUtil::get_behat_status();
                            if ($code == 0) {
                                echo BehatTestingUtil::get_behat_config_path();
                            }