|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Tests\Config; |
|
4
|
|
|
|
|
5
|
|
|
use Overblog\GraphQLBundle\Config\Processor\BuilderProcessor; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
|
8
|
|
|
|
|
9
|
|
|
class BuilderProcessorTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @dataProvider apiAbuseProvider |
|
13
|
|
|
* |
|
14
|
|
|
* @param string $name |
|
15
|
|
|
* @param string $type |
|
16
|
|
|
* @param string $builderClass |
|
17
|
|
|
* @param string $exceptionClass |
|
18
|
|
|
* @param string $exceptionMessage |
|
19
|
|
|
*/ |
|
20
|
|
|
public function testApiAbuse($name, $type, $builderClass, $exceptionClass, $exceptionMessage) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->expectException($exceptionClass); |
|
23
|
|
|
$this->expectExceptionMessage($exceptionMessage); |
|
24
|
|
|
BuilderProcessor::addBuilderClass($name, $type, $builderClass); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @dataProvider processApiAbuseProvider |
|
29
|
|
|
* |
|
30
|
|
|
* @param array $config |
|
31
|
|
|
* @param string $exceptionClass |
|
32
|
|
|
* @param string $exceptionMessage |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testProcessApiAbuse(array $config, $exceptionClass, $exceptionMessage) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->expectException($exceptionClass); |
|
37
|
|
|
$this->expectExceptionMessage($exceptionMessage); |
|
38
|
|
|
BuilderProcessor::process($config); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function apiAbuseProvider() |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
['foo', BuilderProcessor::BUILDER_FIELD_TYPE, [], \InvalidArgumentException::class, 'Field builder class should be string, but array given.'], |
|
45
|
|
|
['foo', BuilderProcessor::BUILDER_ARGS_TYPE, [], \InvalidArgumentException::class, 'Args builder class should be string, but array given.'], |
|
46
|
|
|
['bar', BuilderProcessor::BUILDER_FIELD_TYPE, null, \InvalidArgumentException::class, 'Field builder class should be string, but NULL given.'], |
|
47
|
|
|
['foo', BuilderProcessor::BUILDER_FIELD_TYPE, 'Fake\Foo', \InvalidArgumentException::class, 'Field builder class "Fake\Foo" not found.'], |
|
48
|
|
|
['foo', BuilderProcessor::BUILDER_FIELD_TYPE, \stdClass::class, \InvalidArgumentException::class, 'Field builder class should implement "Overblog\GraphQLBundle\Definition\Builder\MappingInterface", but "stdClass" given.'], |
|
49
|
|
|
['foo', BuilderProcessor::BUILDER_ARGS_TYPE, \stdClass::class, \InvalidArgumentException::class, 'Args builder class should implement "Overblog\GraphQLBundle\Definition\Builder\MappingInterface", but "stdClass" given.'], |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function processApiAbuseProvider() |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
[ |
|
57
|
|
|
[ |
|
58
|
|
|
'foo' => [ |
|
59
|
|
|
'type' => 'object', |
|
60
|
|
|
'config' => [ |
|
61
|
|
|
'fields' => ['id' => ['builder' => 'notExists']], |
|
62
|
|
|
], |
|
63
|
|
|
], |
|
64
|
|
|
], |
|
65
|
|
|
InvalidConfigurationException::class, |
|
66
|
|
|
'Field builder "notExists" not found.', |
|
67
|
|
|
], |
|
68
|
|
|
[ |
|
69
|
|
|
[ |
|
70
|
|
|
'bar' => [ |
|
71
|
|
|
'type' => 'object', |
|
72
|
|
|
'config' => [ |
|
73
|
|
|
'fields' => ['id' => ['argsBuilder' => 'notExists']], |
|
74
|
|
|
], |
|
75
|
|
|
], |
|
76
|
|
|
], |
|
77
|
|
|
InvalidConfigurationException::class, |
|
78
|
|
|
'Args builder "notExists" not found.', |
|
79
|
|
|
], |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|