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

ResponseValueProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
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
 * Give access to the latest response inside expressions
18
 *
19
 * @example "{response.data.id}" => "VXNlcjox"
20
 */
21
class ResponseValueProvider implements ExpressionPreprocessorInterface
22
{
23
    /**
24
     * @var GraphQLClient
25
     */
26
    protected $client;
27
28
    /**
29
     * ResponseValueProvider constructor.
30
     *
31
     * @param GraphQLClient $client
32
     */
33
    public function __construct(GraphQLClient $client)
34
    {
35
        $this->client = $client;
36
    }
37
38
    public function setUp(ExpressionLanguage $el, string &$expression, array &$values)
39
    {
40
        if ($this->client->getResponse() && preg_match('/response[.) ]/', $expression)) {
41
            $values['response'] = json_decode($this->client->getResponse()->getContent());
42
        }
43
    }
44
}