Total Complexity | 8 |
Total Lines | 135 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
21 | class TypesTest extends \PHPUnit\Framework\TestCase |
||
22 | { |
||
23 | use TypesTrait; |
||
24 | |||
25 | public function testBlogMapping(): void |
||
26 | { |
||
27 | $validator = new SchemaValidator($this->entityManager); |
||
28 | $errors = $validator->validateMapping(); |
||
29 | |||
30 | self::assertEmpty($errors, 'doctrine annotations should be valid'); |
||
31 | } |
||
32 | |||
33 | public function testGraphQLSchemaFromDocumentationMustBeValid(): void |
||
34 | { |
||
35 | $schema = new Schema([ |
||
36 | 'query' => new ObjectType([ |
||
37 | 'name' => 'query', |
||
38 | 'fields' => [ |
||
39 | 'users' => [ |
||
40 | 'type' => Type::listOf($this->types->getOutput(User::class)), // Use automated ObjectType for output |
||
41 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
42 | // call to repository... |
||
43 | }, |
||
44 | ], |
||
45 | 'posts' => [ |
||
46 | 'type' => Type::listOf($this->types->getOutput(Post::class)), // Use automated ObjectType for output |
||
47 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
48 | // call to repository... |
||
49 | }, |
||
50 | ], |
||
51 | ], |
||
52 | ]), |
||
53 | 'mutation' => new ObjectType([ |
||
54 | 'name' => 'mutation', |
||
55 | 'fields' => [ |
||
56 | 'createUser' => [ |
||
57 | 'type' => Type::nonNull($this->types->getOutput(User::class)), |
||
58 | 'args' => [ |
||
59 | 'input' => Type::nonNull($this->types->getInput(User::class)), // Use automated InputObjectType for input |
||
60 | ], |
||
61 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
62 | // create new user and flush... |
||
63 | }, |
||
64 | ], |
||
65 | 'updateUser' => [ |
||
66 | 'type' => Type::nonNull($this->types->getOutput(User::class)), |
||
67 | 'args' => [ |
||
68 | 'id' => Type::nonNull(Type::id()), // Use standard API when needed |
||
69 | 'input' => $this->types->getInput(User::class), |
||
70 | ], |
||
71 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
72 | // update existing user and flush... |
||
73 | }, |
||
74 | ], |
||
75 | 'createPost' => [ |
||
76 | 'type' => Type::nonNull($this->types->getOutput(Post::class)), |
||
77 | 'args' => [ |
||
78 | 'input' => Type::nonNull($this->types->getInput(Post::class)), // Use automated InputObjectType for input |
||
79 | ], |
||
80 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
81 | // create new post and flush... |
||
82 | }, |
||
83 | ], |
||
84 | 'updatePost' => [ |
||
85 | 'type' => Type::nonNull($this->types->getOutput(Post::class)), |
||
86 | 'args' => [ |
||
87 | 'id' => Type::nonNull(Type::id()), // Use standard API when needed |
||
88 | 'input' => $this->types->getInput(Post::class), |
||
89 | ], |
||
90 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
91 | // update existing post and flush... |
||
92 | }, |
||
93 | ], |
||
94 | ], |
||
95 | ]), |
||
96 | ]); |
||
97 | |||
98 | $schema->assertValid(); |
||
99 | self::assertTrue(true, 'passed validation successfully'); |
||
100 | } |
||
101 | |||
102 | public function testCanGetUserDefinedScalarTypes(): void |
||
112 | } |
||
113 | |||
114 | public function testCanGetUserMappedTypes(): void |
||
115 | { |
||
116 | $type = $this->types->get(stdClass::class); |
||
117 | |||
118 | self::assertInstanceOf(CustomType::class, $type, 'must be a instance of CustomType'); |
||
119 | self::assertSame($type, $this->types->get('customName')); |
||
120 | } |
||
121 | |||
122 | public function testCanGetMappedTypesEitherByMappedPhpClassOrDirectTypeClass(): void |
||
123 | { |
||
124 | $viaPhp = $this->types->get(DateTime::class); |
||
125 | $viaType = $this->types->get(DateTimeType::class); |
||
126 | self::assertSame($viaPhp, $viaType); |
||
127 | } |
||
128 | |||
129 | public function testDoctrineWithoutAnnotationDriverMustThrow(): void |
||
141 | } |
||
142 | |||
143 | public function testNonRegisteredCustomTypeMustThrow(): void |
||
144 | { |
||
145 | $this->expectExceptionMessage('No type registered with key `foo`. Either correct the usage, or register it in your custom types container when instantiating `GraphQL\Doctrine\Types`'); |
||
146 | $this->types->get('foo'); |
||
147 | } |
||
148 | |||
149 | public function testHas(): void |
||
156 | } |
||
157 | } |
||
158 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.