Completed
Push — master ( 8adc65...bd90c3 )
by Jonathan
11s
created

ScenarioTagTrait::getCurrentScenarioTags()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Drupal\DrupalExtension;
4
5
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
6
use Behat\Behat\Hook\Scope\StepScope;
7
use Behat\Gherkin\Node\ScenarioInterface;
8
9
/**
10
 * A workaround to discover the current scenario.
11
 *
12
 * @see https://github.com/Behat/Behat/issues/653
13
 * @see https://github.com/Behat/Behat/issues/650
14
 *
15
 * The solution is documented in this issue: https://github.com/Behat/Behat/issues/703#issuecomment-86687563
16
 *
17
 * @package Drupal\DrupalExtension
18
 */
19
trait ScenarioTagTrait
20
{
21
22
    /**
23
     * The registered scenario.
24
     *
25
     * @var ScenarioInterface
26
     */
27
    protected $currentScenario;
28
29
    /**
30
     * Register the scenario.
31
     *
32
     * @param BeforeScenarioScope $scope
33
     *
34
     * @BeforeScenario
35
     */
36
    public function registerScenario(BeforeScenarioScope $scope)
37
    {
38
        $this->currentScenario = $scope->getScenario();
39
    }
40
41
    /**
42
     * @return ScenarioInterface
43
     */
44
    protected function getScenario()
45
    {
46
        return $this->currentScenario;
47
    }
48
49
    /**
50
     * Get all tags for the current scenario.
51
     *
52
     * @param StepScope $scope
53
     * @return string[]
54
     */
55
    protected function getCurrentScenarioTags(StepScope $scope)
56
    {
57
        $featureTags = $scope->getFeature()->getTags();
58
        $scenarioTags = $this->getScenario()->getTags();
59
        return array_merge($featureTags, $scenarioTags);
60
    }
61
}
62