Passed
Push — master ( 31fbb7...0157df )
by Tibor
03:27
created

ScenarioTesterDecorator::shouldSkipScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Bex\Behat\SkipTestsExtension\Decorator;
4
5
use Behat\Behat\Tester\ScenarioTester;
6
use Behat\Gherkin\Node\FeatureNode;
7
use Behat\Gherkin\Node\ScenarioInterface as Scenario;
8
use Behat\Testwork\Environment\Environment;
9
use Behat\Testwork\Tester\Result\TestResult;
10
use Behat\Testwork\Tester\Setup\Setup;
11
use Behat\Testwork\Tester\Setup\Teardown;
12
use Bex\Behat\SkipTestsExtension\ServiceContainer\Config;
13
14
class ScenarioTesterDecorator implements ScenarioTester
15
{
16
    /**
17
     * @var ScenarioTester
18
     */
19
    private $scenarioTester;
20
    
21
    /**
22
     * @var Config
23
     */
24
    private $config;
25
    
26
    /**
27
     * @param ScenarioTester $scenarioTester
28
     * @param Config         $config
29
     */
30
    public function __construct(ScenarioTester $scenarioTester, Config $config)
31
    {
32
        $this->scenarioTester = $scenarioTester;
33
        $this->config = $config;
34
    }
35
36
    /**
37
     * Sets up example for a test.
38
     *
39
     * @param Environment $env
40
     * @param FeatureNode $feature
41
     * @param Scenario    $scenario
42
     * @param Boolean     $skip
43
     *
44
     * @return Setup
45
     */
46
    public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
47
    {
48
        return $this->scenarioTester->setUp($env, $feature, $scenario, $skip);
49
    }
50
51
    /**
52
     * Tests example.
53
     *
54
     * @param Environment $env
55
     * @param FeatureNode $feature
56
     * @param Scenario    $scenario
57
     * @param Boolean     $skip
58
     *
59
     * @return TestResult
60
     */
61
    public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
62
    {
63
        if ($this->shouldSkipScenario($scenario)) {
64
            $skip = true;
65
        }
66
        
67
        return $this->scenarioTester->test($env, $feature, $scenario, $skip);
68
    }
69
70
    /**
71
     * Tears down example after a test.
72
     *
73
     * @param Environment $env
74
     * @param FeatureNode $feature
75
     * @param Scenario    $scenario
76
     * @param Boolean     $skip
77
     * @param TestResult  $result
78
     *
79
     * @return Teardown
80
     */
81
    public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result)
82
    {
83
        return $this->scenarioTester->tearDown($env, $feature, $scenario, $skip, $result);
84
    }
85
86
    /**
87
     * @param Scenario $scenario
88
     *
89
     * @return bool
90
     */
91
    private function shouldSkipScenario(Scenario $scenario)
92
    {
93
        $matchingSkipTags = array_intersect($scenario->getTags(), $this->config->getScenarioSkipTags());
94
        
95
        return !empty($matchingSkipTags);
96
    }
97
}
98