Passed
Pull Request — master (#9)
by Rafael
03:29
created

ClientAwareInitializer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 38
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 3 1
A __construct() 0 4 1
A setUp() 0 3 1
A test() 0 10 3
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Behat\Client;
12
13
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
14
use Behat\Behat\Tester\Result\StepResult;
15
use Behat\Behat\Tester\StepTester;
16
use Behat\Gherkin\Node\FeatureNode;
17
use Behat\Gherkin\Node\StepNode;
18
use Behat\Testwork\Environment\Environment;
19
20
/**
21
 * Inject GraphQLClient instance on very context implementing ClientAwareInterface
22
 */
23
class ClientAwareInitializer implements StepTester
24
{
25
    /**
26
     * @var StepTester
27
     */
28
    private $baseTester;
29
30
    /**
31
     * @var GraphQLClient
32
     */
33
    private $client;
34
35
    public function __construct(StepTester $baseTester, GraphQLClient $client)
36
    {
37
        $this->baseTester = $baseTester;
38
        $this->client = $client;
39
    }
40
41
    public function setUp(Environment $env, FeatureNode $feature, StepNode $step, $skip)
42
    {
43
        return $this->baseTester->setUp($env, $feature, $step, $skip);
44
    }
45
46
    public function test(Environment $env, FeatureNode $feature, StepNode $step, $skip)
47
    {
48
        /** @var InitializedContextEnvironment $env */
49
        foreach ($env->getContexts() as $context) {
0 ignored issues
show
Bug introduced by
The method getContexts() does not exist on Behat\Testwork\Environment\Environment. It seems like you code against a sub-type of Behat\Testwork\Environment\Environment such as Behat\Behat\Context\Envi...lizedContextEnvironment or Behat\Behat\Context\Envi...lizedContextEnvironment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        foreach ($env->/** @scrutinizer ignore-call */ getContexts() as $context) {
Loading history...
50
            if ($context instanceof ClientAwareInterface) {
51
                $context->setClient($this->client);
52
            }
53
        }
54
55
        return $this->baseTester->test($env, $feature, $step, $skip);
56
    }
57
58
    public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result)
59
    {
60
        return $this->baseTester->tearDown($env, $feature, $step, $skip, $result);
61
    }
62
}