1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Youshido\Tests\Parser; |
4
|
|
|
|
5
|
|
|
use Youshido\GraphQL\Parser\Ast\ArgumentValue\Variable; |
6
|
|
|
use Youshido\GraphQL\Parser\Location; |
7
|
|
|
|
8
|
|
|
class VariableTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Test if variable value equals expected value |
12
|
|
|
* |
13
|
|
|
* @dataProvider variableProvider |
14
|
|
|
*/ |
15
|
|
|
public function testGetValue($actual, $expected) |
16
|
|
|
{ |
17
|
|
|
$var = new Variable('foo', 'bar', false, false, true, new Location(1,1)); |
18
|
|
|
$var->setValue($actual); |
19
|
|
|
$this->assertEquals($var->getValue(), $expected); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @expectedException \LogicException |
24
|
|
|
* @expectedExceptionMessage Value is not set for variable "foo" |
25
|
|
|
*/ |
26
|
|
|
public function testGetNullValueException() |
27
|
|
|
{ |
28
|
|
|
$var = new Variable('foo', 'bar', false, false, true, new Location(1,1)); |
29
|
|
|
$var->getValue(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function testGetValueReturnsDefaultValueIfNoValueSet() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$var = new Variable('foo', 'bar', false, false, true, new Location(1,1)); |
35
|
|
|
$var->setDefaultValue('default-value'); |
36
|
|
|
|
37
|
|
|
$this->assertEquals( |
38
|
|
|
'default-value', |
39
|
|
|
$var->getValue() |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testGetValueReturnsSetValueEvenWithDefaultValue() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$var = new Variable('foo', 'bar', false, false, true, new Location(1,1)); |
46
|
|
|
$var->setValue('real-value'); |
47
|
|
|
$var->setDefaultValue('default-value'); |
48
|
|
|
|
49
|
|
|
$this->assertEquals( |
50
|
|
|
'real-value', |
51
|
|
|
$var->getValue() |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function testIndicatesDefaultValuePresent() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$var = new Variable('foo', 'bar', false, false, true, new Location(1,1)); |
58
|
|
|
$var->setDefaultValue('default-value'); |
59
|
|
|
|
60
|
|
|
$this->assertTrue( |
61
|
|
|
$var->hasDefaultValue() |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testHasNoDefaultValue() |
66
|
|
|
{ |
67
|
|
|
$var = new Variable('foo', 'bar', false, false, true, new Location(1,1)); |
68
|
|
|
|
69
|
|
|
$this->assertFalse( |
70
|
|
|
$var->hasDefaultValue() |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return array Array of <mixed: value to set, mixed: expected value> |
76
|
|
|
*/ |
77
|
|
|
public static function variableProvider() |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
[ |
81
|
|
|
0, |
82
|
|
|
0 |
83
|
|
|
] |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.