Permalink
Browse files

updated to support latest Behat

  • Loading branch information...
1 parent 4062918 commit 752263c6f092380f51ba3c367939a04f6695178d @everzet everzet committed Jan 18, 2012
Showing with 41 additions and 84 deletions.
  1. +2 −0 Command/BehatCommand.php
  2. +6 −20 Console/Processor/ContextProcessor.php
  3. +32 −63 Runner.php
  4. +1 −1 composer.json
View
@@ -8,6 +8,7 @@
Symfony\Component\Console\Output\OutputInterface;
use Behat\Behat\Console\Command\BehatCommand as BaseCommand,
+ Behat\Behat\Console\Input\InputDefinition,
Behat\Behat\Console\Processor,
Behat\Behat\Event\SuiteEvent;
@@ -36,6 +37,7 @@ protected function configure()
$this
->setName('behat')
->setDescription('Tests Behat feature(s) in specified bundle')
+ ->setDefinition(new InputDefinition)
->setProcessors(array(
new BundleProcessor\LocatorProcessor(),
new BundleProcessor\InitProcessor(),
@@ -33,42 +33,28 @@ public function process(ContainerInterface $container, InputInterface $input, Ou
return;
}
- $contextDispatcher = $container->get('behat.context_dispatcher');
- $contextDispatcher->setContextClass($this->getContextClass($container, $input));
-
- $contextReader = $container->get('behat.context_reader');
- $contextReader->read();
+ $container->get('behat.runner')->setMainContextClass(
+ $this->getContextClass($container, $input)
+ );
}
/**
* {@inheritdoc}
*/
protected function getContextClass(ContainerInterface $container, InputInterface $input)
{
- $contextClass = $container->getParameter('behat.context.class');
- if (class_exists($contextClass)) {
- return $contextClass;
- }
-
$featuresPath = preg_replace('/\:\d+$/', '', $input->getArgument('features'));
-
- $namespacedContext = null;
if (preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) {
- $bundle = $container->get('kernel')->getBundle($matches[1]);
- $namespacedContext = $bundle->getNamespace() . '\Features\Context\FeatureContext';
+ $bundleNamespace = $container->get('kernel')->getBundle($matches[1])->getNamespace();
} else {
foreach ($container->get('kernel')->getBundles() as $bundle) {
if (false !== strpos(realpath($featuresPath), realpath($bundle->getPath()))) {
- $namespacedContext = $bundle->getNamespace() . '\Features\Context\FeatureContext';
+ $bundleNamespace = $bundle->getNamespace();
break;
}
}
}
- if (null !== $namespacedContext && class_exists($namespacedContext)) {
- return $namespacedContext;
- }
-
- throw new \RuntimeException('Behat context class not found');
+ return $container->get('behat.runner')->getContextClassForBundle($bundleNamespace);
}
}
View
@@ -22,108 +22,77 @@
*/
class Runner extends BaseRunner
{
- private $container;
private $runAllBundles = false;
/**
- * Initializes runner.
+ * Sets runner to run all bundles.
*
- * @param Symfony\Component\DependencyInjection\ContainerInterface $container
+ * @param Boolean $runAll
*/
- public function __construct(ContainerInterface $container)
+ public function setRunAllBundles($runAll = true)
{
- parent::__construct($container);
- $this->container = $container;
+ $this->runAllBundles = (bool) $runAll;
}
/**
- * Sets runner to run all bundles.
- *
- * @param Boolean $runAll
+ * {@inheritdoc}
*/
- public function setRunAllBundles($runAll = true)
+ public function getContextClassForBundle($bundleNamespace)
{
- $this->runAllBundles = (bool) $runAll;
+ $contextClass = $this->getContainer()->getParameter('behat.context.class');
+
+ if (null !== $contextClass && class_exists($bundleNamespace.'\\'.$contextClass)) {
+ return $bundleNamespace.'\\'.$contextClass;
+ }
+
+ if (null !== $contextClass && class_exists($contextClass)) {
+ return $contextClass;
+ }
+
+ if (class_exists($bundleNamespace.'\\Features\\Context\\FeatureContext')) {
+ return $bundleNamespace.'\\Features\\Context\\FeatureContext';
+ }
}
/**
* Runs feature suite.
*
* @return integer CLI return code
*/
- public function run()
+ public function runSuite()
{
if (!$this->runAllBundles) {
- return parent::run();
+ return parent::runSuite();
}
- return $this->runAllRegisteredBundles();
- }
-
- protected function runAllRegisteredBundles()
- {
- $gherkin = $this->container->get('gherkin');
-
+ $gherkin = $this->getContainer()->get('gherkin');
+ $logger = $this->getContainer()->get('behat.logger');
+ $hooks = $this->getContainer()->get('behat.hook_dispatcher');
+ $parameters = $this->getContainer()->get('behat.context_dispatcher')->getContextParameters();
$testBundles = (array) $this->container->getParameter('behat.bundles');
@Entea

Entea Jan 19, 2012

$this->container

is causing
ErrorException
Notice: Undefined property: Behat\BehatBundle\Runner::$container in vendor/bundles/Behat/BehatBundle/Runner.php line 72

@stof

stof Jan 19, 2012

Owner

should be fixed now

@Entea

Entea Jan 19, 2012

Yep, it works!

$ignoreBundles = (array) $this->container->getParameter('behat.ignore_bundles');
$this->beforeSuite();
- foreach ($this->container->get('kernel')->getBundles() as $bundle) {
+ foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
if (count($testBundles) && !in_array($bundle->getName(), $testBundles)) {
continue;
}
if (count($ignoreBundles) && in_array($bundle->getName(), $ignoreBundles)) {
continue;
}
- $contextClass = $bundle->getNamespace().'\Features\Context\FeatureContext';
- $featuresPath = $bundle->getPath().DIRECTORY_SEPARATOR.'Features';
+ $contextClass = $this->getContextClassForBundle($bundle->getNamespace());
if (!class_exists($contextClass)) {
continue;
}
- // get all the needed services
- $pathsLocator = $this->container->get('behat.path_locator');
- $definitionDisp = $this->container->get('behat.definition_dispatcher');
- $hookDisp = $this->container->get('behat.hook_dispatcher');
- $contextDisp = $this->container->get('behat.context_dispatcher');
- $contextReader = $this->container->get('behat.context_reader');
- $logger = $this->container->get('behat.logger');
- $parameters = $contextDisp->getContextParameters();
-
- // load context information
- $contextDisp->setContextClass($contextClass);
- $contextReader->read();
-
- // locate bundle features
- $pathsLocator->locateBasePath($featuresPath);
- $paths = $pathsLocator->locateFeaturesPaths();
-
- // run bundle beforeSuite hooks
- $hookDisp->beforeSuite(new SuiteEvent($logger, $parameters, false));
-
- // read all features from their paths
- foreach ($paths as $path) {
- // parse every feature with Gherkin
- $features = $gherkin->load((string) $path);
-
- // and run it in FeatureTester
- foreach ($features as $feature) {
- $tester = $this->container->get('behat.tester.feature');
- $tester->setDryRun($this->isDryRun());
-
- $feature->accept($tester);
- }
- }
-
- // run bundle afterSuite hooks
- $hookDisp->afterSuite(new SuiteEvent($logger, $parameters, true));
+ $this->setMainContextClass($contextClass);
+ $this->setLocatorBasePath($featuresPath);
- // clean definitions, transformations and hooks
- $definitionDisp->removeDefinitions();
- $definitionDisp->removeTransformations();
- $hookDisp->removeHooks();
+ $hooks->beforeSuite(new SuiteEvent($logger, $parameters, false));
+ $this->runFeatures($gherkin, $this->getFeaturesPaths());
+ $hooks->afterSuite(new SuiteEvent($logger, $parameters, true));
}
$this->afterSuite();
View
@@ -14,7 +14,7 @@
"require": {
"php": ">=5.3.2",
- "behat/behat": ">=2.2.2",
+ "behat/behat": ">=2.3.0",
"symfony/framework-bundle": ">=2.0.0"
},

0 comments on commit 752263c

Please sign in to comment.