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\Transformer; |
12
|
|
|
|
13
|
|
|
use Behat\Behat\Definition\Call\DefinitionCall; |
14
|
|
|
use Behat\Behat\Transformation\Transformer\ArgumentTransformer; |
15
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
16
|
|
|
use Ynlo\GraphQLBundle\Behat\Fixtures\FixtureManager; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Transform named fixtures to object reference, |
20
|
|
|
* the fixture name should be prefixed with @ |
21
|
|
|
* |
22
|
|
|
* @example "@user1" => User (object) |
23
|
|
|
*/ |
24
|
|
|
class TransformFixtureNameToObject implements ArgumentTransformer |
25
|
|
|
{ |
26
|
|
|
private const PATTERN = '/^@/'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var KernelInterface |
30
|
|
|
*/ |
31
|
|
|
protected $kernel; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var FixtureManager |
35
|
|
|
*/ |
36
|
|
|
protected $fixtureManager; |
37
|
|
|
|
38
|
|
|
public function __construct(KernelInterface $kernel, FixtureManager $fixtureManager) |
39
|
|
|
{ |
40
|
|
|
$this->kernel = $kernel; |
41
|
|
|
$this->fixtureManager = $fixtureManager; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue) |
45
|
|
|
{ |
46
|
|
|
return preg_match(self::PATTERN, $argumentValue); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function transformArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue) |
50
|
|
|
{ |
51
|
|
|
$name = preg_replace(self::PATTERN, null, $argumentValue); |
52
|
|
|
|
53
|
|
|
return $this->fixtureManager->getFixture($name); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: