GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e88f87...0f9eb6 )
by Bruno
02:27
created

ScenarioBranchingFeatureTester   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 8
dl 0
loc 119
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setUp() 0 4 1
A test() 0 6 1
A preprocessFeature() 0 20 2
A splitScenarioPerVariants() 0 14 2
B forkScenario() 0 27 4
A tearDown() 0 4 1
1
<?php
2
namespace Ciandt\Behat\PlaceholdersExtension\Tester;
3
4
use Behat\Gherkin\Node\FeatureNode;
5
use Behat\Gherkin\Node\OutlineNode;
6
use Behat\Gherkin\Node\ScenarioInterface;
7
use Behat\Gherkin\Node\ScenarioNode;
8
use Behat\Testwork\Environment\Environment;
9
use Behat\Testwork\Tester\Result\TestResult;
10
use Behat\Testwork\Tester\Setup\SuccessfulSetup;
11
use Behat\Testwork\Tester\Setup\SuccessfulTeardown;
12
use Behat\Testwork\Tester\SpecificationTester;
13
use Ciandt\Behat\PlaceholdersExtension\Config\PlaceholdersRepository;
14
use Ciandt\Behat\PlaceholdersExtension\Utils\PlaceholderUtils;
15
16
/**
17
 * Tester executing feature tests in the runtime.
18
 *
19
 */
20
final class ScenarioBranchingFeatureTester implements SpecificationTester
21
{
22
23
    /**
24
     * @var SpecificationTester
25
     */
26
    private $baseTester;
27
28
    /**
29
     * @var array
30
     */
31
    private $variantTags;
0 ignored issues
show
Unused Code introduced by
The property $variantTags is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
32
33
    /**
34
     * @var array
35
     */
36
    private $configsRepo;
37
38
    /**
39
     * Initializes tester.
40
     *
41
     * @param SpecificationTester $baseTester
42
     */
43
    public function __construct(SpecificationTester $baseTester, PlaceholdersRepository $configsRepo)
44
    {
45
        $this->baseTester = $baseTester;
46
        $this->configsRepo = $configsRepo;
0 ignored issues
show
Documentation Bug introduced by
It seems like $configsRepo of type object<Ciandt\Behat\Plac...PlaceholdersRepository> is incompatible with the declared type array of property $configsRepo.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function setUp(Environment $env, $spec, $skip)
53
    {
54
        return new SuccessfulSetup();
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function test(Environment $env, $feature, $skip = false)
61
    {
62
        $tester = $this->baseTester;
63
        $reconstructedFeature = $this->preprocessFeature($feature);
64
        return $tester->test($env, $reconstructedFeature, $skip);
65
    }
66
67
    private function preprocessFeature(FeatureNode $feature)
68
    {
69
        $scenarios = array();
70
        
71
        foreach ($feature->getScenarios() as $scenario) {
72
            $scenarios = array_merge($scenarios,$this->splitScenarioPerVariants($scenario,$feature));
73
        }
74
75
        return new FeatureNode(
76
            $feature->getTitle(),
77
            $feature->getDescription(),
78
            $feature->getTags(),
79
            $feature->getBackground(),
80
            $scenarios,
81
            $feature->getKeyword(),
82
            $feature->getLanguage(),
83
            $feature->getFile(),
84
            $feature->getLine()
85
        );
86
    }
87
    
88
    private function splitScenarioPerVariants(ScenarioInterface $scenarioLike, FeatureNode $feature){
89
        $scenarioTags = $scenarioLike->getTags();
90
        $featureTags = $feature->getTags();
91
        $tags = array_merge($scenarioTags,$featureTags);
92
        
93
        $variants = PlaceholderUtils::filterVariantTags($tags,false);
94
        
95
            if (count($variants) <= 1) {
96
                return array($scenarioLike);
97
            } else {
98
                return $this->forkScenario($scenarioLike, $variants);
99
            }
100
        
101
    }
102
    
103
    private function forkScenario(ScenarioInterface $scenarioLike, $variants)
104
    {
105
        $scenarios = array();
106
        $nonVariantTags = PlaceholderUtils::filterVariantTags($scenarioLike->getTags(),true);
107
        foreach ($variants as $variant) {
108
            $tags = array_merge($nonVariantTags, array($variant));
109
            if ($scenarioLike instanceof ScenarioNode){
110
            $scenarios[] = new ScenarioNode(
111
                $scenarioLike->getTitle(),
112
                $tags,
113
                $scenarioLike->getSteps(),
114
                $scenarioLike->getKeyword(),
115
                $scenarioLike->getLine()
116
            );
117
            } elseif ($scenarioLike instanceof OutlineNode){
118
            $scenarios[] = new OutlineNode(
119
                $scenarioLike->getTitle(),
120
                $tags,
121
                $scenarioLike->getSteps(),
122
                $scenarioLike->getExampleTable(),
123
                $scenarioLike->getKeyword(),
124
                $scenarioLike->getLine()
125
            );    
126
            }
127
        }
128
        return $scenarios;
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function tearDown(Environment $env, $spec, $skip, TestResult $result)
135
    {
136
        return new SuccessfulTeardown();
137
    }
138
}
139