@@ -32,7 +32,6 @@ |
||
32 | 32 | |
33 | 33 | /** |
34 | 34 | * |
35 | - * @param type $config_files |
|
36 | 35 | * @todo user %paths.base% value |
37 | 36 | */ |
38 | 37 | private function loadConfigFiles($configs_mapping){ |
@@ -31,10 +31,10 @@ |
||
31 | 31 | |
32 | 32 | |
33 | 33 | /** |
34 | - * |
|
35 | - * @param type $config_files |
|
36 | - * @todo user %paths.base% value |
|
37 | - */ |
|
34 | + * |
|
35 | + * @param type $config_files |
|
36 | + * @todo user %paths.base% value |
|
37 | + */ |
|
38 | 38 | private function loadConfigFiles($configs_mapping){ |
39 | 39 | $placeholder_maps = array(); |
40 | 40 | foreach ($configs_mapping as $tag => $file_path){ |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @return string[] |
26 | 26 | * @todo read configs and also bring alternative @config:section tags |
27 | 27 | */ |
28 | - public function getTags(){ |
|
28 | + public function getTags() { |
|
29 | 29 | return array_keys($this->configs); |
30 | 30 | } |
31 | 31 | |
@@ -35,26 +35,26 @@ discard block |
||
35 | 35 | * @param type $config_files |
36 | 36 | * @todo user %paths.base% value |
37 | 37 | */ |
38 | - private function loadConfigFiles($configs_mapping){ |
|
38 | + private function loadConfigFiles($configs_mapping) { |
|
39 | 39 | $placeholder_maps = array(); |
40 | - foreach ($configs_mapping as $tag => $file_path){ |
|
40 | + foreach ($configs_mapping as $tag => $file_path) { |
|
41 | 41 | $placeholder_maps[$tag]['config'] = Yaml::parse(file_get_contents($file_path)); |
42 | 42 | $placeholder_maps[$tag]['path'] = $file_path; |
43 | 43 | } |
44 | 44 | $this->configs = $placeholder_maps; |
45 | 45 | } |
46 | 46 | |
47 | - public function getConfigSection($tag, $section){ |
|
47 | + public function getConfigSection($tag, $section) { |
|
48 | 48 | if ($this->hasTag($tag)) return $this->configs[$tag]['config'][$section]; |
49 | 49 | return NULL; |
50 | 50 | } |
51 | 51 | |
52 | - public function getFilePath($tag){ |
|
52 | + public function getFilePath($tag) { |
|
53 | 53 | if ($this->hasTag($tag)) return $this->configs[$tag]['path']; |
54 | 54 | return NULL; |
55 | 55 | } |
56 | 56 | |
57 | - public function hasTag($tag){ |
|
57 | + public function hasTag($tag) { |
|
58 | 58 | if (key_exists($tag, $this->configs)) return true; |
59 | 59 | else return false; |
60 | 60 | } |
@@ -45,17 +45,24 @@ |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | public function getConfigSection($tag, $section){ |
48 | - if ($this->hasTag($tag)) return $this->configs[$tag]['config'][$section]; |
|
48 | + if ($this->hasTag($tag)) { |
|
49 | + return $this->configs[$tag]['config'][$section]; |
|
50 | + } |
|
49 | 51 | return NULL; |
50 | 52 | } |
51 | 53 | |
52 | 54 | public function getFilePath($tag){ |
53 | - if ($this->hasTag($tag)) return $this->configs[$tag]['path']; |
|
55 | + if ($this->hasTag($tag)) { |
|
56 | + return $this->configs[$tag]['path']; |
|
57 | + } |
|
54 | 58 | return NULL; |
55 | 59 | } |
56 | 60 | |
57 | 61 | public function hasTag($tag){ |
58 | - if (key_exists($tag, $this->configs)) return true; |
|
59 | - else return false; |
|
62 | + if (key_exists($tag, $this->configs)) { |
|
63 | + return true; |
|
64 | + } else { |
|
65 | + return false; |
|
66 | + } |
|
60 | 67 | } |
61 | 68 | } |
@@ -104,6 +104,10 @@ |
||
104 | 104 | $step->getKeyword(), $text, $arguments, $step->getLine(), $step->getKeywordType()); |
105 | 105 | } |
106 | 106 | |
107 | + /** |
|
108 | + * @param string $string |
|
109 | + * @param string $env |
|
110 | + */ |
|
107 | 111 | private function replacePlaceholders($string, $var, $env) { |
108 | 112 | preg_match_all('/\${(?P<key>[^}]+)}/i', $string, $placeholders, PREG_SET_ORDER); |
109 | 113 | foreach ($placeholders as $placeholder) { |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $this->configSection = 'default'; |
75 | 75 | $this->placeholders = $this->configsRepo->getConfigSection($step->configTag, $this->configSection)['placeholders']; |
76 | 76 | $this->configPath = $this->configsRepo->getFilePath($step->configTag); |
77 | - if ($step->variant){ |
|
77 | + if ($step->variant) { |
|
78 | 78 | $this->variant = $step->variant; |
79 | 79 | } |
80 | 80 | |
@@ -122,21 +122,21 @@ discard block |
||
122 | 122 | $variant = $this->variant; |
123 | 123 | $environment = $this->environment; |
124 | 124 | |
125 | - $keys = array('$'.$variant,'$'.$environment,$placeholderKey); |
|
125 | + $keys = array('$' . $variant, '$' . $environment, $placeholderKey); |
|
126 | 126 | $treePosition = "$configPath>$section>placeholders"; |
127 | 127 | |
128 | 128 | return $this->recursivePlaceholderSearch($keys, $values, $treePosition); |
129 | 129 | } |
130 | 130 | |
131 | 131 | private function recursivePlaceholderSearch($keys, $values, $treePosition) { |
132 | - if (empty($keys) || !is_array($values) ){ |
|
132 | + if (empty($keys) || !is_array($values)) { |
|
133 | 133 | return $values; |
134 | 134 | } |
135 | 135 | $key = array_pop($keys); |
136 | - if (key_exists($key, $values)){ |
|
137 | - return $this->recursivePlaceholderSearch($keys,$values[$key],"$treePosition>$key"); |
|
138 | - } elseif (key_exists('$default', $values)){ |
|
139 | - return $this->recursivePlaceholderSearch($keys,$values['$default'],$treePosition.'>$default'); |
|
136 | + if (key_exists($key, $values)) { |
|
137 | + return $this->recursivePlaceholderSearch($keys, $values[$key], "$treePosition>$key"); |
|
138 | + } elseif (key_exists('$default', $values)) { |
|
139 | + return $this->recursivePlaceholderSearch($keys, $values['$default'], $treePosition . '>$default'); |
|
140 | 140 | } else { |
141 | 141 | throw new \Exception("no placeholder is defined on $treePosition>[$key or \$default]"); |
142 | 142 | } |
@@ -120,6 +120,9 @@ discard block |
||
120 | 120 | } |
121 | 121 | |
122 | 122 | |
123 | + /** |
|
124 | + * @param string[] $variants |
|
125 | + */ |
|
123 | 126 | private function forkScenario(ScenarioNode $scenario, $variants, $configTag) { |
124 | 127 | $scenarios = array(); |
125 | 128 | $nonVariantTags = array_filter($scenario->getTags(), function ($val) { |
@@ -141,6 +144,9 @@ discard block |
||
141 | 144 | return $scenarios; |
142 | 145 | } |
143 | 146 | |
147 | + /** |
|
148 | + * @param StepNode[] $steps |
|
149 | + */ |
|
144 | 150 | private function injectParametersOnSteps($steps, $variant, $configTag) { |
145 | 151 | $injectedSteps = array(); |
146 | 152 | foreach ($steps as $step) { |
@@ -3,21 +3,13 @@ |
||
3 | 3 | |
4 | 4 | namespace Ciandt\Behat\PlaceholdersExtension\Tester; |
5 | 5 | |
6 | -use Behat\Behat\Tester\OutlineTester; |
|
7 | -use Behat\Behat\Tester\ScenarioTester; |
|
8 | -use Behat\Gherkin\Node\OutlineNode; |
|
9 | 6 | use Behat\Testwork\Environment\Environment; |
10 | -use Behat\Testwork\Environment\EnvironmentManager; |
|
11 | -use Behat\Testwork\Tester\Result\IntegerTestResult; |
|
12 | 7 | use Behat\Testwork\Tester\Result\TestResult; |
13 | -use Behat\Testwork\Tester\Result\TestResults; |
|
14 | -use Behat\Testwork\Tester\Result\TestWithSetupResult; |
|
15 | 8 | use Behat\Testwork\Tester\Setup\SuccessfulSetup; |
16 | 9 | use Behat\Testwork\Tester\Setup\SuccessfulTeardown; |
17 | 10 | use Behat\Testwork\Tester\SpecificationTester; |
18 | 11 | use Behat\Gherkin\Node\FeatureNode; |
19 | 12 | use Behat\Gherkin\Node\ScenarioNode; |
20 | -use Behat\Gherkin\Node\StepNode; |
|
21 | 13 | use Ciandt\Behat\PlaceholdersExtension\Config\ConfigsRepository; |
22 | 14 | |
23 | 15 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @param SpecificationTester $baseTester |
48 | 48 | */ |
49 | - public function __construct(SpecificationTester $baseTester, $variantTags, ConfigsRepository $configsRepo ) { |
|
49 | + public function __construct(SpecificationTester $baseTester, $variantTags, ConfigsRepository $configsRepo) { |
|
50 | 50 | $this->baseTester = $baseTester; |
51 | 51 | $this->variantTags = $variantTags; |
52 | 52 | $this->configsRepo = $configsRepo; |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | foreach ($feature->getScenarios() as $scenario) { |
80 | 80 | $configTag = $this->getScenarioConfigTag($scenario); |
81 | 81 | $scenarioVariants = array_intersect($scenario->getTags(), $this->variantTags); |
82 | - if (count($scenarioVariants) == 1){ |
|
82 | + if (count($scenarioVariants) == 1) { |
|
83 | 83 | $injectedScenario = new ScenarioNode( |
84 | 84 | $scenario->getTitle(), |
85 | 85 | $scenario->getTags(), |
86 | - $this->injectParametersOnSteps($scenario->getSteps(), end($scenarioVariants),$configTag), |
|
86 | + $this->injectParametersOnSteps($scenario->getSteps(), end($scenarioVariants), $configTag), |
|
87 | 87 | $scenario->getKeyword(), |
88 | 88 | $scenario->getLine()); |
89 | 89 | $scenarios[] = $injectedScenario; |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | ); |
102 | 102 | } |
103 | 103 | |
104 | - private function getScenarioConfigTag(ScenarioNode $scenario){ |
|
104 | + private function getScenarioConfigTag(ScenarioNode $scenario) { |
|
105 | 105 | $availableTags = $this->configsRepo->getTags(); |
106 | - $configTags = array_intersect($scenario->getTags(),$availableTags ); |
|
106 | + $configTags = array_intersect($scenario->getTags(), $availableTags); |
|
107 | 107 | |
108 | 108 | if (count($configTags) > 1) { |
109 | - throw new \Exception ("Scenario {$scenario->getTitle()}" |
|
109 | + throw new \Exception("Scenario {$scenario->getTitle()}" |
|
110 | 110 | . " should have only ONE of the following Placeholder" |
111 | 111 | . " File Tags: " . implode(',', $availableTags)); |
112 | 112 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | private function forkScenario(ScenarioNode $scenario, $variants, $configTag) { |
124 | 124 | $scenarios = array(); |
125 | - $nonVariantTags = array_filter($scenario->getTags(), function ($val) { |
|
125 | + $nonVariantTags = array_filter($scenario->getTags(), function($val) { |
|
126 | 126 | if (!in_array($val, $this->variantTags)) |
127 | 127 | return TRUE; |
128 | 128 | } |
@@ -68,8 +68,7 @@ discard block |
||
68 | 68 | $variantTags = $this->variantTags; |
69 | 69 | if ($variantTags) { |
70 | 70 | return $tester->test($env, $this->reconstructFeature($feature), $skip); |
71 | - } |
|
72 | - else { |
|
71 | + } else { |
|
73 | 72 | return $tester->test($env, $feature, $skip); |
74 | 73 | } |
75 | 74 | } |
@@ -87,11 +86,9 @@ discard block |
||
87 | 86 | $scenario->getKeyword(), |
88 | 87 | $scenario->getLine()); |
89 | 88 | $scenarios[] = $injectedScenario; |
90 | - } |
|
91 | - elseif (count($scenarioVariants) > 1) { |
|
89 | + } elseif (count($scenarioVariants) > 1) { |
|
92 | 90 | $scenarios = array_merge($scenarios, $this->forkScenario($scenario, $scenarioVariants, $configTag)); |
93 | - } |
|
94 | - else { |
|
91 | + } else { |
|
95 | 92 | $scenarios[] = $scenario; |
96 | 93 | } |
97 | 94 | } |
@@ -123,8 +120,9 @@ discard block |
||
123 | 120 | private function forkScenario(ScenarioNode $scenario, $variants, $configTag) { |
124 | 121 | $scenarios = array(); |
125 | 122 | $nonVariantTags = array_filter($scenario->getTags(), function ($val) { |
126 | - if (!in_array($val, $this->variantTags)) |
|
127 | - return TRUE; |
|
123 | + if (!in_array($val, $this->variantTags)) { |
|
124 | + return TRUE; |
|
125 | + } |
|
128 | 126 | } |
129 | 127 | ); |
130 | 128 | foreach ($variants as $variant) { |
@@ -146,7 +144,9 @@ discard block |
||
146 | 144 | foreach ($steps as $step) { |
147 | 145 | $newStep = clone $step; |
148 | 146 | $newStep->variant = $variant; |
149 | - if ($configTag) $newStep->configTag = $configTag; |
|
147 | + if ($configTag) { |
|
148 | + $newStep->configTag = $configTag; |
|
149 | + } |
|
150 | 150 | $injectedSteps[] = $newStep; |
151 | 151 | } |
152 | 152 | return $injectedSteps; |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function load(ContainerBuilder $container, array $config) { |
75 | 75 | $this->loadPlaceholdersController($container); |
76 | - $this->loadScenarioForkingFeatureTester($container,$config['variant_tags']); |
|
76 | + $this->loadScenarioForkingFeatureTester($container, $config['variant_tags']); |
|
77 | 77 | $this->loadConfigsRepository($container, $config['config_files']); |
78 | - $this->loadStepTester($container, $config['variant_tags'],'default'); |
|
78 | + $this->loadStepTester($container, $config['variant_tags'], 'default'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param ContainerBuilder $container |
127 | 127 | */ |
128 | - protected function loadStepTester(ContainerBuilder $container, $variantTags,$environment) |
|
128 | + protected function loadStepTester(ContainerBuilder $container, $variantTags, $environment) |
|
129 | 129 | { |
130 | 130 | $definition = new Definition('Ciandt\Behat\PlaceholdersExtension\Tester\PlaceholdersReplacer', array( |
131 | 131 | new Reference(TesterExtension::STEP_TESTER_ID), |