|
2 | 2 |
|
3 | 3 | namespace TheCodingMachine\GraphQLite\Mappers\Root;
|
4 | 4 |
|
| 5 | +use Generator; |
5 | 6 | use GraphQL\Type\Definition\InputType;
|
6 | 7 | use GraphQL\Type\Definition\NamedType;
|
7 | 8 | use GraphQL\Type\Definition\NonNull;
|
|
10 | 11 | use GraphQL\Type\Definition\Type as GraphQLType;
|
11 | 12 | use phpDocumentor\Reflection\DocBlock;
|
12 | 13 | use phpDocumentor\Reflection\Type;
|
| 14 | +use phpDocumentor\Reflection\Types\Nullable; |
13 | 15 | use ReflectionMethod;
|
14 | 16 | use TheCodingMachine\GraphQLite\AbstractQueryProviderTest;
|
15 | 17 | use TheCodingMachine\GraphQLite\Fixtures\TestObject;
|
|
18 | 20 |
|
19 | 21 | class NullableTypeMapperAdapterTest extends AbstractQueryProviderTest
|
20 | 22 | {
|
21 |
| - public function testMultipleCompound(): void |
| 23 | + /** |
| 24 | + * @dataProvider nullableVariationsProvider |
| 25 | + */ |
| 26 | + public function testMultipleCompound(callable $type): void |
22 | 27 | {
|
23 | 28 | $compoundTypeMapper = $this->getRootTypeMapper();
|
24 | 29 |
|
25 |
| - $result = $compoundTypeMapper->toGraphQLOutputType($this->resolveType(TestObject::class.'|'.TestObject2::class.'|null'), null, new ReflectionMethod(__CLASS__, 'testMultipleCompound'), new DocBlock()); |
| 30 | + $result = $compoundTypeMapper->toGraphQLOutputType($type(), null, new ReflectionMethod(__CLASS__, 'testMultipleCompound'), new DocBlock()); |
26 | 31 | $this->assertNotInstanceOf(NonNull::class, $result);
|
27 | 32 | }
|
28 | 33 |
|
| 34 | + public function nullableVariationsProvider(): Generator |
| 35 | + { |
| 36 | + yield 'php documentor generated from phpdoc' => [ |
| 37 | + fn () => $this->resolveType(TestObject::class . '|' . TestObject2::class . '|null'), |
| 38 | + ]; |
| 39 | + |
| 40 | + yield 'type handler nullable wrapped native reflection union type' => [ |
| 41 | + fn () => new Nullable($this->resolveType(TestObject::class . '|' . TestObject2::class . '|null')), |
| 42 | + ]; |
| 43 | + } |
| 44 | + |
29 | 45 | public function testOnlyNull(): void
|
30 | 46 | {
|
31 | 47 | $compoundTypeMapper = $this->getRootTypeMapper();
|
@@ -69,6 +85,6 @@ public function mapNameToType(string $typeName): NamedType&GraphQLType
|
69 | 85 |
|
70 | 86 | $this->expectException(CannotMapTypeException::class);
|
71 | 87 | $this->expectExceptionMessage('a type mapper returned a GraphQL\\Type\\Definition\\NonNull instance.');
|
72 |
| - $typeMapper->toGraphQLOutputType($this->resolveType(TestObject::class.'|'.TestObject2::class.'|null'), null, new ReflectionMethod(__CLASS__, 'testMultipleCompound'), new DocBlock()); |
| 88 | + $typeMapper->toGraphQLOutputType($this->resolveType(TestObject::class . '|' . TestObject2::class . '|null'), null, new ReflectionMethod(__CLASS__, 'testMultipleCompound'), new DocBlock()); |
73 | 89 | }
|
74 | 90 | }
|
0 commit comments