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) { |
|
|
|
|
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
|
|
|
} |