1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\GraphQL\Controllers; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestController; |
8
|
|
|
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject; |
9
|
|
|
use TheCodingMachine\GraphQL\Controllers\Security\VoidAuthenticationService; |
10
|
|
|
use TheCodingMachine\GraphQL\Controllers\Security\VoidAuthorizationService; |
11
|
|
|
use Youshido\GraphQL\Execution\ResolveInfo; |
12
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
13
|
|
|
use Youshido\GraphQL\Type\NonNullType; |
14
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
15
|
|
|
use Youshido\GraphQL\Type\Scalar\IntType; |
16
|
|
|
use Youshido\GraphQL\Type\Scalar\StringType; |
17
|
|
|
use Youshido\GraphQL\Type\TypeInterface; |
18
|
|
|
|
19
|
|
|
class ControllerQueryProviderTest extends AbstractQueryProviderTest |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
public function testQueryProvider() |
23
|
|
|
{ |
24
|
|
|
$controller = new TestController(); |
25
|
|
|
$reader = new AnnotationReader(); |
26
|
|
|
|
27
|
|
|
$queryProvider = new ControllerQueryProvider($controller, $reader, $this->getTypeMapper(), $this->getHydrator(), new VoidAuthenticationService(), new VoidAuthorizationService()); |
28
|
|
|
|
29
|
|
|
$queries = $queryProvider->getQueries(); |
30
|
|
|
|
31
|
|
|
$this->assertCount(1, $queries); |
32
|
|
|
$usersQuery = $queries[0]; |
33
|
|
|
$this->assertSame('test', $usersQuery->getName()); |
34
|
|
|
|
35
|
|
|
$this->assertCount(3, $usersQuery->getArguments()); |
36
|
|
|
$this->assertInstanceOf(NonNullType::class, $usersQuery->getArgument('int')->getType()); |
37
|
|
|
$this->assertInstanceOf(IntType::class, $usersQuery->getArgument('int')->getType()->getTypeOf()); |
38
|
|
|
$this->assertInstanceOf(StringType::class, $usersQuery->getArgument('string')->getType()); |
39
|
|
|
$this->assertInstanceOf(NonNullType::class, $usersQuery->getArgument('list')->getType()); |
40
|
|
|
$this->assertInstanceOf(ListType::class, $usersQuery->getArgument('list')->getType()->getTypeOf()); |
41
|
|
|
$this->assertInstanceOf(NonNullType::class, $usersQuery->getArgument('list')->getType()->getTypeOf()->getItemType()); |
42
|
|
|
$this->assertInstanceOf(ObjectType::class, $usersQuery->getArgument('list')->getType()->getTypeOf()->getItemType()->getTypeOf()); |
43
|
|
|
$this->assertSame('TestObject', $usersQuery->getArgument('list')->getType()->getTypeOf()->getItemType()->getTypeOf()->getName()); |
44
|
|
|
|
45
|
|
|
$mockResolveInfo = $this->createMock(ResolveInfo::class); |
46
|
|
|
|
47
|
|
|
$result = $usersQuery->resolve('foo', ['int'=>42, 'string'=>'foo', 'list'=>[ |
48
|
|
|
['test'=>42], |
49
|
|
|
['test'=>12], |
50
|
|
|
]], $mockResolveInfo); |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf(TestObject::class, $result); |
53
|
|
|
$this->assertSame('foo424212', $result->getTest()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testMutations() |
57
|
|
|
{ |
58
|
|
|
$controller = new TestController(); |
59
|
|
|
$reader = new AnnotationReader(); |
60
|
|
|
|
61
|
|
|
$queryProvider = new ControllerQueryProvider($controller, $reader, $this->getTypeMapper(), $this->getHydrator(), new VoidAuthenticationService(), new VoidAuthorizationService()); |
62
|
|
|
|
63
|
|
|
$mutations = $queryProvider->getMutations(); |
64
|
|
|
|
65
|
|
|
$this->assertCount(1, $mutations); |
66
|
|
|
$mutation = $mutations[0]; |
67
|
|
|
$this->assertSame('mutation', $mutation->getName()); |
68
|
|
|
|
69
|
|
|
$mockResolveInfo = $this->createMock(ResolveInfo::class); |
70
|
|
|
|
71
|
|
|
$result = $mutation->resolve('foo', ['testObject'=>['test'=>42]], $mockResolveInfo); |
72
|
|
|
|
73
|
|
|
$this->assertInstanceOf(TestObject::class, $result); |
74
|
|
|
$this->assertEquals('42', $result->getTest()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|