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