1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Tests\Relay\Node; |
13
|
|
|
|
14
|
|
|
use Overblog\GraphQLBundle\Relay\Node\NodeFieldDefinition; |
15
|
|
|
|
16
|
|
|
class NodeFieldDefinitionTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var NodeFieldDefinition |
20
|
|
|
*/ |
21
|
|
|
private $definition; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->definition = new NodeFieldDefinition(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @expectedException \InvalidArgumentException |
30
|
|
|
* @expectedExceptionMessage Node "idFetcher" config is invalid. |
31
|
|
|
*/ |
32
|
|
|
public function testUndefinedIdFetcherConfig() |
33
|
|
|
{ |
34
|
|
|
$this->definition->toMappingDefinition([]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @expectedException \InvalidArgumentException |
39
|
|
|
* @expectedExceptionMessage Node "idFetcher" config is invalid. |
40
|
|
|
*/ |
41
|
|
|
public function testIdFetcherConfigSetButIsNotString() |
42
|
|
|
{ |
43
|
|
|
$this->definition->toMappingDefinition(['idFetcher' => 45]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @dataProvider validConfigProvider |
48
|
|
|
* |
49
|
|
|
* @param $idFetcher |
50
|
|
|
* @param $idFetcherCallbackArg |
51
|
|
|
* @param $nodeInterfaceType |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function testValidConfig($idFetcher, $idFetcherCallbackArg, $nodeInterfaceType = 'node') |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$config = [ |
56
|
|
|
'idFetcher' => $idFetcher, |
57
|
|
|
'inputType' => 'UserInput', |
58
|
|
|
'nodeInterfaceType' => $nodeInterfaceType, |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
$expected = [ |
62
|
|
|
'description' => 'Fetches an object given its ID', |
63
|
|
|
'type' => $nodeInterfaceType, |
64
|
|
|
'args' => ['id' => ['type' => 'ID!', 'description' => 'The ID of an object']], |
65
|
|
|
'resolve' => '@=resolver(\'relay_node_field\', [args, idFetcherCallback('.$idFetcherCallbackArg.')])', |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
$this->assertEquals($expected, $this->definition->toMappingDefinition($config)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function validConfigProvider() |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
['@=user.username', 'user.username'], |
75
|
|
|
['toto', 'toto'], |
76
|
|
|
['50', '50'], |
77
|
|
|
['@=user.id', 'user.id', 'NodeInterface'], |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.