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; |
12
|
|
|
|
13
|
|
|
use Behat\Testwork\ServiceContainer\Extension; |
14
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
15
|
|
|
use Behat\Testwork\ServiceContainer\ServiceProcessor; |
16
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
17
|
|
|
use Symfony\Component\Config\FileLocator; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
20
|
|
|
use Ynlo\GraphQLBundle\Behat\Transformer\TransformStringToExpression; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* GraphQLBundle extension for Behat. |
24
|
|
|
*/ |
25
|
|
|
class GraphQLApiExtension implements Extension |
26
|
|
|
{ |
27
|
|
|
const CONTEXTS_PARAMETER = 'graphql.contexts'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ServiceProcessor |
31
|
|
|
*/ |
32
|
|
|
private $processor; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initializes extension. |
36
|
|
|
* |
37
|
|
|
* @param null|ServiceProcessor $processor |
38
|
|
|
*/ |
39
|
|
|
public function __construct(ServiceProcessor $processor = null) |
40
|
|
|
{ |
41
|
|
|
$this->processor = $processor ? : new ServiceProcessor(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getConfigKey() |
45
|
|
|
{ |
46
|
|
|
return 'graphql'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function initialize(ExtensionManager $extensionManager) |
50
|
|
|
{ |
51
|
|
|
if (!$extensionManager->getExtension('symfony2')) { |
52
|
|
|
throw new \RuntimeException( |
53
|
|
|
'The behat "Symfony2Extension" is required to work with "GraphQLApiExtension". |
54
|
|
|
Ensure you have "Behat\Symfony2Extension" inside your behat config file.' |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function configure(ArrayNodeDefinition $builder) |
60
|
|
|
{ |
61
|
|
|
$root = $builder->addDefaultsIfNotSet()->children(); |
62
|
|
|
|
63
|
|
|
$client = $root->arrayNode('client')->addDefaultsIfNotSet()->children(); |
64
|
|
|
$client->booleanNode('insulated')->defaultFalse(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function process(ContainerBuilder $container) |
68
|
|
|
{ |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function load(ContainerBuilder $container, array $config) |
72
|
|
|
{ |
73
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Resources/config')); |
74
|
|
|
$loader->load('services.yml'); |
75
|
|
|
$container->setParameter('graphql.client_config', $config['client']); |
76
|
|
|
|
77
|
|
|
$this->processExpressionPreprocessors($container); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function processExpressionPreprocessors(ContainerBuilder $container) |
81
|
|
|
{ |
82
|
|
|
$references = $this->processor->findAndSortTaggedServices($container, 'graphql.expression_preprocessor'); |
83
|
|
|
$definition = $container->getDefinition(TransformStringToExpression::class); |
84
|
|
|
|
85
|
|
|
foreach ($references as $reference) { |
86
|
|
|
$definition->addMethodCall('registerPreprocessor', array($reference)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|