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\Definition; |
13
|
|
|
|
14
|
|
|
use Overblog\GraphQLBundle\Definition\MergeFieldTrait; |
15
|
|
|
|
16
|
|
|
class MergeFieldTraitTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
use MergeFieldTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param $fields |
22
|
|
|
* @param array $defaultFields |
23
|
|
|
* @param $forceArray |
24
|
|
|
* @param $expectedFields |
25
|
|
|
* |
26
|
|
|
* @dataProvider getFieldsDataProvider |
27
|
|
|
*/ |
28
|
|
|
public function testGetFieldsWithDefaults($fields, array $defaultFields, $forceArray, $expectedFields) |
29
|
|
|
{ |
30
|
|
|
$this->assertEquals($expectedFields, $this->getFieldsWithDefaults($fields, $defaultFields, $forceArray)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getFieldsDataProvider() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
[ |
37
|
|
|
['toto', 'tata', 'titi'], |
38
|
|
|
['foo', 'bar'], |
39
|
|
|
true, |
40
|
|
|
['toto', 'tata', 'titi', 'foo', 'bar'], |
41
|
|
|
], |
42
|
|
|
[ |
43
|
|
|
[], |
44
|
|
|
['foo'], |
45
|
|
|
true, |
46
|
|
|
['foo'], |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
function () { |
50
|
|
|
return ['test']; |
51
|
|
|
}, |
52
|
|
|
['bar'], |
53
|
|
|
true, |
54
|
|
|
['test', 'bar'], |
55
|
|
|
], |
56
|
|
|
[ |
57
|
|
|
'toto', |
58
|
|
|
['tata'], |
59
|
|
|
true, |
60
|
|
|
['toto', 'tata'], |
61
|
|
|
], |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testGetFieldsWithDefaultsForceArray() |
66
|
|
|
{ |
67
|
|
|
$fields = $this->getFieldsWithDefaults(function () { return ['bar']; }, ['toto'], false); |
68
|
|
|
$this->assertInstanceOf('Closure', $fields); |
69
|
|
|
$this->assertEquals(['bar', 'toto'], $fields()); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|