|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of GraphQL project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 5/15/16 3:51 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\Tests\Parser; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Execution\Request; |
|
13
|
|
|
use Youshido\GraphQL\Parser\Ast\Fragment; |
|
14
|
|
|
|
|
15
|
|
|
class RequestTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
public function testMethods() |
|
19
|
|
|
{ |
|
20
|
|
|
$fragment1 = new Fragment('fragmentName1', 'test', []); |
|
21
|
|
|
$fragment2 = new Fragment('fragmentName2', 'test', []); |
|
22
|
|
|
$queriesData = ['query1', 'query2']; |
|
23
|
|
|
$mutationsData = ['mutation1', 'mutation2']; |
|
24
|
|
|
$fragmentsData = [$fragment1]; |
|
25
|
|
|
$variables = [ |
|
26
|
|
|
'page' => 2 |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
$request = new Request([ |
|
30
|
|
|
'queries' => $queriesData, |
|
31
|
|
|
'mutations' => $mutationsData, |
|
32
|
|
|
'fragments' => $fragmentsData, |
|
33
|
|
|
]); |
|
34
|
|
|
$request->setVariables($variables); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertEquals($queriesData, $request->getQueries()); |
|
37
|
|
|
$this->assertEquals($mutationsData, $request->getMutations()); |
|
38
|
|
|
$this->assertEquals($fragmentsData, $request->getFragments()); |
|
39
|
|
|
$this->assertEquals($variables, $request->getVariables()); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertTrue($request->hasFragments()); |
|
42
|
|
|
$this->assertTrue($request->hasMutations()); |
|
43
|
|
|
$this->assertTrue($request->hasQueries()); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertTrue($request->hasVariable('page')); |
|
46
|
|
|
$this->assertEquals(2, $request->getVariable('page')); |
|
47
|
|
|
|
|
48
|
|
|
$request->addFragment($fragment2); |
|
49
|
|
|
$this->assertEquals($fragment2, $request->getFragment('fragmentName2')); |
|
50
|
|
|
$this->assertNull($request->getFragment('unknown fragment')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testSetVariableParseJson() |
|
54
|
|
|
{ |
|
55
|
|
|
$variables = '{"foo": "bar"}'; |
|
56
|
|
|
$expectedVariableArray = [ 'foo' => 'bar' ]; |
|
57
|
|
|
|
|
58
|
|
|
$request = new Request([], $variables); |
|
|
|
|
|
|
59
|
|
|
$this->assertEquals($expectedVariableArray, $request->getVariables()); |
|
60
|
|
|
|
|
61
|
|
|
$request = new Request(); |
|
62
|
|
|
$request->setVariables($variables); |
|
|
|
|
|
|
63
|
|
|
$this->assertEquals($expectedVariableArray, $request->getVariables()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: