-
Notifications
You must be signed in to change notification settings - Fork 16
/
Runner.php
111 lines (89 loc) · 3.49 KB
/
Runner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Behat\BehatBundle;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Behat\Behat\Event\SuiteEvent;
use Behat\Behat\Runner as BaseRunner;
/*
* This file is part of the Behat\BehatBundle.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Behat suite runner.
*
* @author Christophe Coevoet <[email protected]>
*/
class Runner extends BaseRunner
{
private $runAllBundles = false;
/**
* Sets runner to run all bundles.
*
* @param Boolean $runAll
*/
public function setRunAllBundles($runAll = true)
{
$this->runAllBundles = (bool) $runAll;
}
/**
* {@inheritdoc}
*/
public function getContextClassForBundle($bundleNamespace)
{
$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';
}
$prefix = $this->getContainer()->getParameter('behat.namespace.prefix') ? '\\'.trim($this->getContainer()->getParameter('behat.namespace.prefix'), '\\') : null ;
if (class_exists($bundleNamespace.$prefix.'\\Features\\Context\\FeatureContext')) {
return $bundleNamespace.$prefix.'\\Features\\Context\\FeatureContext';
}
}
/**
* Runs feature suite.
*
* @return integer CLI return code
*/
public function runSuite()
{
if (!$this->runAllBundles) {
return parent::runSuite();
}
$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->getContainer()->getParameter('behat.bundles');
$ignoreBundles = (array) $this->getContainer()->getParameter('behat.ignore_bundles');
$this->beforeSuite();
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 = $this->getContextClassForBundle($bundle->getNamespace());
if (!class_exists($contextClass)) {
continue;
}
$featuresPath = $bundle->getPath().DIRECTORY_SEPARATOR.'Features';
$this->setMainContextClass($contextClass);
$this->setLocatorBasePath($featuresPath);
$hooks->beforeSuite(new SuiteEvent($logger, $parameters, false));
$this->runFeatures($gherkin, $this->getFeaturesPaths());
$hooks->afterSuite(new SuiteEvent($logger, $parameters, true));
$this->cleanContextInformation();
}
$this->afterSuite();
return $this->getCliReturnCode();
}
}