container = $container; } /** * Configures command to be able to process it later. * * @param Command $command */ public function configure(Command $command) { $command->addArgument('features', InputArgument::OPTIONAL, "Feature(s) to run. Could be:". "\n- a dir (src/to/module/Features/), " . "\n- a feature (src/to/module/Features/*.feature), " . "\n- a scenario at specific line (src/to/module/Features/*.feature:10). " . "\n- Also, you can use short module notation (@moduleName/*.feature:10)" ); } /** * Processes data from container and console input. * * @param InputInterface $input * @param OutputInterface $output * * @throws \RuntimeException */ public function process(InputInterface $input, OutputInterface $output) { $featuresPath = $input->getArgument('features'); // Can't use 'behat.paths.base' since that's locked at this point to base folder (not module) $pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix'); $currentModuleName = null; $modules = \SS_ClassLoader::instance()->getManifest()->getModules(); // get module specified in behat.yml $currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module'); // get module from short notation if path starts from @ if ($featuresPath && preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) { $currentModuleName = $matches[1]; // TODO Replace with proper module loader once AJShort's changes are merged into core $currentModulePath = $modules[$currentModuleName]; $featuresPath = str_replace( '@'.$currentModuleName, $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix, $featuresPath ); // get module from provided features path } elseif (!$currentModuleName && $featuresPath) { $path = realpath(preg_replace('/\.feature\:.*$/', '.feature', $featuresPath)); foreach ($modules as $moduleName => $modulePath) { if (false !== strpos($path, realpath($modulePath))) { $currentModuleName = $moduleName; $currentModulePath = realpath($modulePath); break; } } $featuresPath = $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix.DIRECTORY_SEPARATOR.$featuresPath; // if module is configured for profile and feature provided } elseif ($currentModuleName && $featuresPath) { $currentModulePath = $modules[$currentModuleName]; $featuresPath = $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix.DIRECTORY_SEPARATOR.$featuresPath; } if($input->getOption('namespace')) { $namespace = $input->getOption('namespace'); } else { $namespace = ucfirst($currentModuleName); } if ($currentModuleName) { $this->container ->get('behat.silverstripe_extension.context.class_guesser') // TODO Improve once modules can declare their own namespaces consistently ->setNamespaceBase($namespace); } $this->container ->get('behat.console.command') ->setFeaturesPaths($featuresPath ? array($featuresPath) : array()); } }