|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of GraphQL project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 5/12/16 7:46 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\Tests\Library\Field; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Config\Field\FieldConfig; |
|
13
|
|
|
use Youshido\GraphQL\Field\InputField; |
|
14
|
|
|
use Youshido\GraphQL\Type\Scalar\IntType; |
|
15
|
|
|
use Youshido\GraphQL\Type\Scalar\StringType; |
|
16
|
|
|
|
|
17
|
|
|
class ArgumentsAwareConfigTraitTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
public function testArguments() |
|
21
|
|
|
{ |
|
22
|
|
|
$argsData = [ |
|
23
|
|
|
'id' => new IntType() |
|
24
|
|
|
]; |
|
25
|
|
|
$config = new FieldConfig([ |
|
26
|
|
|
'name' => 'UserType', |
|
27
|
|
|
'type' => new IntType(), |
|
28
|
|
|
'args' => $argsData |
|
29
|
|
|
]); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertTrue($config->hasArguments()); |
|
32
|
|
|
$this->assertEquals([ |
|
33
|
|
|
'id' => new InputField(['name' => 'id', 'type' => new IntType()]), |
|
34
|
|
|
], $config->getArguments()); |
|
35
|
|
|
|
|
36
|
|
|
$config->addArgument('name', new StringType()); |
|
37
|
|
|
$this->assertEquals([ |
|
38
|
|
|
'id' => new InputField(['name' => 'id', 'type' => new IntType()]), |
|
39
|
|
|
'name' => new InputField(['name' => 'name', 'type' => new StringType()]) |
|
40
|
|
|
], $config->getArguments()); |
|
41
|
|
|
|
|
42
|
|
|
$config->removeArgument('id'); |
|
43
|
|
|
$this->assertEquals([ |
|
44
|
|
|
'name' => new InputField(['name' => 'name', 'type' => new StringType()]) |
|
45
|
|
|
], $config->getArguments()); |
|
46
|
|
|
|
|
47
|
|
|
$config->addArguments([ |
|
48
|
|
|
'id' => new InputField(['name' => 'id', 'type' => new IntType()]) |
|
49
|
|
|
]); |
|
50
|
|
|
$this->assertEquals([ |
|
51
|
|
|
'name' => new InputField(['name' => 'name', 'type' => new StringType()]), |
|
52
|
|
|
'id' => new InputField(['name' => 'id', 'type' => new IntType()]), |
|
53
|
|
|
], $config->getArguments()); |
|
54
|
|
|
|
|
55
|
|
|
$config->addArguments([ |
|
56
|
|
|
new InputField(['name' => 'level', 'type' => new IntType()]) |
|
57
|
|
|
]); |
|
58
|
|
|
$this->assertEquals([ |
|
59
|
|
|
'name' => new InputField(['name' => 'name', 'type' => new StringType()]), |
|
60
|
|
|
'id' => new InputField(['name' => 'id', 'type' => new IntType()]), |
|
61
|
|
|
'level' => new InputField(['name' => 'level', 'type' => new IntType()]), |
|
62
|
|
|
], $config->getArguments()); |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|