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 ( 66c291...444f0e )
by Bruno
03:49
created

splitScenarioPerVariants()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
namespace Ciandt\Behat\PlaceholdersExtension\Tester;
3
4
use Behat\Behat\Tester\OutlineTester;
5
use Behat\Behat\Tester\ScenarioTester;
6
use Behat\Gherkin\Node\OutlineNode;
7
use Behat\Testwork\Environment\Environment;
8
use Behat\Testwork\Environment\EnvironmentManager;
9
use Behat\Testwork\Tester\Result\IntegerTestResult;
10
use Behat\Testwork\Tester\Result\TestResult;
11
use Behat\Testwork\Tester\Result\TestResults;
12
use Behat\Testwork\Tester\Result\TestWithSetupResult;
13
use Behat\Testwork\Tester\Setup\SuccessfulSetup;
14
use Behat\Testwork\Tester\Setup\SuccessfulTeardown;
15
use Behat\Testwork\Tester\SpecificationTester;
16
use Behat\Gherkin\Node\FeatureNode;
17
use Behat\Gherkin\Node\ScenarioNode;
18
use Behat\Gherkin\Node\StepNode;
19
use Ciandt\Behat\PlaceholdersExtension\Config\PlaceholdersRepository;
20
use Ciandt\Behat\PlaceholdersExtension\Utils\PlaceholderUtils;
21
22
/**
23
 * Tester executing feature tests in the runtime.
24
 *
25
 */
26
final class ScenarioBranchingFeatureTester implements SpecificationTester
27
{
28
29
    /**
30
     * @var SpecificationTester
31
     */
32
    private $baseTester;
33
34
    /**
35
     * @var array
36
     */
37
    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...
38
39
    /**
40
     * @var array
41
     */
42
    private $configsRepo;
43
44
    /**
45
     * Initializes tester.
46
     *
47
     * @param SpecificationTester $baseTester
48
     */
49
    public function __construct(SpecificationTester $baseTester, PlaceholdersRepository $configsRepo)
50
    {
51
        $this->baseTester = $baseTester;
52
        $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...
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function setUp(Environment $env, $spec, $skip)
59
    {
60
        return new SuccessfulSetup();
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function test(Environment $env, $feature, $skip = false)
67
    {
68
        $tester = $this->baseTester;
69
        $reconstructedFeature = $this->preprocessFeature($feature);
70
        return $tester->test($env, $reconstructedFeature, $skip);
71
    }
72
73
    private function preprocessFeature(FeatureNode $feature)
74
    {
75
        $scenarios = array();
76
        
77
        foreach ($feature->getScenarios() as $scenario) {
78
            $scenarios = array_merge($scenarios,$this->splitScenarioPerVariants($scenario,$feature));
0 ignored issues
show
Compatibility introduced by
$scenario of type object<Behat\Gherkin\Node\ScenarioInterface> is not a sub-type of object<Behat\Gherkin\Node\ScenarioNode>. It seems like you assume a concrete implementation of the interface Behat\Gherkin\Node\ScenarioInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
79
        }
80
81
        return new FeatureNode(
82
            $feature->getTitle(),
83
            $feature->getDescription(),
84
            $feature->getTags(),
85
            $feature->getBackground(),
86
            $scenarios,
87
            $feature->getKeyword(),
88
            $feature->getLanguage(),
89
            $feature->getFile(),
90
            $feature->getLine()
91
        );
92
    }
93
    
94
    private function splitScenarioPerVariants(ScenarioNode $scenario, FeatureNode $feature){
95
        $scenarioTags = $scenario->getTags();
96
        $featureTags = $feature->getTags();
97
        $tags = array_merge($scenarioTags,$featureTags);
98
        
99
        $variants = PlaceholderUtils::filterVariantTags($tags,false);
100
        
101
            if (count($variants) <= 1) {
102
                return array($scenario);
103
            } else {
104
                return $this->forkScenario($scenario, $variants);
105
            }
106
        
107
    }
108
    
109
    private function forkScenario(ScenarioNode $scenario, $variants)
110
    {
111
        $scenarios = array();
112
        $nonVariantTags = PlaceholderUtils::filterVariantTags($scenario->getTags(),true);
113
        foreach ($variants as $variant) {
114
            $tags = array_merge($nonVariantTags, array($variant));
115
            $scenarios[] = new ScenarioNode(
116
                $scenario->getTitle(),
117
                $tags,
118
                $scenario->getSteps(),
119
                $scenario->getKeyword(),
120
                $scenario->getLine()
121
            );
122
        }
123
        return $scenarios;
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function tearDown(Environment $env, $spec, $skip, TestResult $result)
130
    {
131
        return new SuccessfulTeardown();
132
    }
133
}
134