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

ClientVariablesValueProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 22
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 3
A __construct() 0 3 1
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\ExpressionLanguage;
12
13
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
14
use Ynlo\GraphQLBundle\Behat\Client\GraphQLClient;
15
16
/**
17
 * Allow the use of client query variables in expressions
18
 * helpful to compare sent values with response
19
 *
20
 * @example "{variables.id}" => "VXNlcjox"
21
 * @example "{variables.input.name}" => "admin"
22
 */
23
class ClientVariablesValueProvider implements ExpressionPreprocessorInterface
24
{
25
    /**
26
     * @var GraphQLClient
27
     */
28
    protected $client;
29
30
    /**
31
     * ResponseValueProvider constructor.
32
     *
33
     * @param GraphQLClient $client
34
     */
35
    public function __construct(GraphQLClient $client)
36
    {
37
        $this->client = $client;
38
    }
39
40
    public function setUp(ExpressionLanguage $el, string &$expression, array &$values)
41
    {
42
        if ($this->client->getVariables() && preg_match('/variables\./', $expression)) {
43
            //encode and decode to allow access using "variables.name" instead of "variables[name]"
44
            $values['variables'] = json_decode(json_encode($this->client->getVariables()));
45
        }
46
    }
47
}