1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Tests\Config\Parser; |
4
|
|
|
|
5
|
|
|
use Overblog\GraphQLBundle\Config\Parser\GraphQLParser; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
9
|
|
|
|
10
|
|
|
class GraphQLParserTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** @var ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject */ |
13
|
|
|
private $containerBuilder; |
14
|
|
|
|
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->containerBuilder = $this->getMockBuilder(ContainerBuilder::class)->setMethods(['addResource'])->getMock(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testParse() |
21
|
|
|
{ |
22
|
|
|
$fileName = __DIR__.'/fixtures/graphql/schema.graphql'; |
23
|
|
|
$expected = include __DIR__.'/fixtures/graphql/schema.php'; |
24
|
|
|
|
25
|
|
|
$this->assertContainerAddFileToResources($fileName); |
26
|
|
|
$config = GraphQLParser::parse(new \SplFileInfo($fileName), $this->containerBuilder); |
27
|
|
|
$this->assertEquals($expected, $config); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testParseEmptyFile() |
31
|
|
|
{ |
32
|
|
|
$fileName = __DIR__.'/fixtures/graphql/empty.graphql'; |
33
|
|
|
|
34
|
|
|
$this->assertContainerAddFileToResources($fileName); |
35
|
|
|
|
36
|
|
|
$config = GraphQLParser::parse(new \SplFileInfo($fileName), $this->containerBuilder); |
37
|
|
|
$this->assertEquals([], $config); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testParseInvalidFile() |
41
|
|
|
{ |
42
|
|
|
$fileName = __DIR__.'/fixtures/graphql/invalid.graphql'; |
43
|
|
|
$this->expectException(InvalidArgumentException::class); |
44
|
|
|
$this->expectExceptionMessage(sprintf('An error occurred while parsing the file "%s"', $fileName)); |
45
|
|
|
GraphQLParser::parse(new \SplFileInfo($fileName), $this->containerBuilder); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testParseNotSupportedSchemaDefinition() |
49
|
|
|
{ |
50
|
|
|
$this->expectException(InvalidArgumentException::class); |
51
|
|
|
$this->expectExceptionMessage('Schema definition is not supported right now.'); |
52
|
|
|
GraphQLParser::parse(new \SplFileInfo(__DIR__.'/fixtures/graphql/not-supported-schema-definition.graphql'), $this->containerBuilder); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testCustomScalarTypeDefaultFieldValue() |
56
|
|
|
{ |
57
|
|
|
$this->expectException(\Exception::class); |
58
|
|
|
$this->expectExceptionMessage('Config entry must be override with ResolverMap to be used.'); |
59
|
|
|
GraphQLParser::mustOverrideConfig(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function assertContainerAddFileToResources($fileName) |
63
|
|
|
{ |
64
|
|
|
$this->containerBuilder->expects($this->once()) |
|
|
|
|
65
|
|
|
->method('addResource') |
66
|
|
|
->with($fileName); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: