22
33namespace TheCodingMachine \GraphQLite \Mappers \Root ;
44
5+ use Closure ;
56use Generator ;
67use GraphQL \Type \Definition \InputType ;
78use GraphQL \Type \Definition \NamedType ;
1011use GraphQL \Type \Definition \StringType ;
1112use GraphQL \Type \Definition \Type as GraphQLType ;
1213use phpDocumentor \Reflection \DocBlock ;
14+ use phpDocumentor \Reflection \Fqsen ;
1315use phpDocumentor \Reflection \Type ;
1416use phpDocumentor \Reflection \Types \Array_ ;
1517use phpDocumentor \Reflection \Types \Callable_ ;
1618use phpDocumentor \Reflection \Types \CallableParameter ;
19+ use phpDocumentor \Reflection \Types \Compound ;
1720use phpDocumentor \Reflection \Types \Nullable ;
1821use phpDocumentor \Reflection \Types \Object_ ;
1922use phpDocumentor \Reflection \Types \String_ ;
2528use TheCodingMachine \GraphQLite \Fixtures \TestObject2 ;
2629use TheCodingMachine \GraphQLite \Mappers \CannotMapTypeException ;
2730
28- #[CoversClass(CallableTypeMapper ::class)]
31+ #[CoversClass(ClosureTypeMapper ::class)]
2932#[CoversClass(CannotMapTypeException::class)]
30- class CallableTypeMapperTest extends AbstractQueryProvider
33+ class ClosureTypeMapperTest extends AbstractQueryProvider
3134{
3235 public function testMapsCallableReturnTypeUsingTopRootMapper (): void
3336 {
@@ -42,51 +45,77 @@ public function testMapsCallableReturnTypeUsingTopRootMapper(): void
4245 ->with ($ returnType , null , $ reflection , $ docBlock )
4346 ->willReturn (GraphQLType::string ());
4447
45- $ mapper = new CallableTypeMapper (
48+ $ mapper = new ClosureTypeMapper (
4649 $ this ->createMock (RootTypeMapperInterface::class),
4750 $ topRootMapper ,
4851 );
4952
50- $ result = $ mapper ->toGraphQLOutputType (new Callable_ (returnType: $ returnType ), null , $ reflection , $ docBlock );
53+ $ type = new Compound ([
54+ new Callable_ (returnType: $ returnType ),
55+ new Object_ (new Fqsen ('\\' . Closure::class))
56+ ]);
57+
58+ $ result = $ mapper ->toGraphQLOutputType ($ type , null , $ reflection , $ docBlock );
5159
5260 $ this ->assertSame (GraphQLType::string (), $ result );
5361 }
5462
55- public function testThrowsWhenUsingCallableWithParameters (): void
63+ public function testThrowsWhenUsingCallable (): void
5664 {
57- $ this ->expectExceptionObject (CannotMapTypeException::createForUnexpectedCallableParameters ());
65+ $ this ->expectExceptionObject (CannotMapTypeException::createForUnexpectedCallable ());
5866
59- $ mapper = new CallableTypeMapper (
67+ $ mapper = new ClosureTypeMapper (
6068 $ this ->createMock (RootTypeMapperInterface::class),
6169 $ this ->createMock (RootTypeMapperInterface::class)
6270 );
6371
64- $ type = new Callable_ (
65- parameters: [
66- new CallableParameter (new String_ ())
67- ]
72+ $ mapper ->toGraphQLOutputType (new Callable_ (), null , new ReflectionMethod (__CLASS__ , 'testSkipsNonCallables ' ), new DocBlock ());
73+ }
74+
75+ public function testThrowsWhenUsingClosureWithParameters (): void
76+ {
77+ $ this ->expectExceptionObject (CannotMapTypeException::createForUnexpectedClosureParameters ());
78+
79+ $ mapper = new ClosureTypeMapper (
80+ $ this ->createMock (RootTypeMapperInterface::class),
81+ $ this ->createMock (RootTypeMapperInterface::class)
6882 );
6983
84+ $ type = new Compound ([
85+ new Callable_ (
86+ parameters: [
87+ new CallableParameter (new String_ ())
88+ ],
89+ returnType: new String_ ()
90+ ),
91+ new Object_ (new Fqsen ('\\' . Closure::class))
92+ ]);
93+
7094 $ mapper ->toGraphQLOutputType ($ type , null , new ReflectionMethod (__CLASS__ , 'testSkipsNonCallables ' ), new DocBlock ());
7195 }
7296
73- public function testThrowsWhenUsingCallableWithoutReturnType (): void
97+ public function testThrowsWhenUsingClosureWithoutReturnType (): void
7498 {
75- $ this ->expectExceptionObject (CannotMapTypeException::createForMissingCallableReturnType ());
99+ $ this ->expectExceptionObject (CannotMapTypeException::createForMissingClosureReturnType ());
76100
77- $ mapper = new CallableTypeMapper (
101+ $ mapper = new ClosureTypeMapper (
78102 $ this ->createMock (RootTypeMapperInterface::class),
79103 $ this ->createMock (RootTypeMapperInterface::class)
80104 );
81105
82- $ mapper ->toGraphQLOutputType (new Callable_ (), null , new ReflectionMethod (__CLASS__ , 'testSkipsNonCallables ' ), new DocBlock ());
106+ $ type = new Compound ([
107+ new Callable_ (),
108+ new Object_ (new Fqsen ('\\' . Closure::class))
109+ ]);
110+
111+ $ mapper ->toGraphQLOutputType ($ type , null , new ReflectionMethod (__CLASS__ , 'testSkipsNonCallables ' ), new DocBlock ());
83112 }
84113
85- public function testThrowsWhenUsingCallableAsInputType (): void
114+ public function testThrowsWhenUsingClosureAsInputType (): void
86115 {
87- $ this ->expectExceptionObject (CannotMapTypeException::createForCallableAsInput ());
116+ $ this ->expectExceptionObject (CannotMapTypeException::createForClosureAsInput ());
88117
89- $ mapper = new CallableTypeMapper (
118+ $ mapper = new ClosureTypeMapper (
90119 $ this ->createMock (RootTypeMapperInterface::class),
91120 $ this ->createMock (RootTypeMapperInterface::class)
92121 );
@@ -115,7 +144,7 @@ public function testSkipsNonCallables(callable $createType): void
115144 ->with ('Name ' )
116145 ->willReturn (GraphQLType::float ());
117146
118- $ mapper = new CallableTypeMapper ($ next , $ this ->createMock (RootTypeMapperInterface::class));
147+ $ mapper = new ClosureTypeMapper ($ next , $ this ->createMock (RootTypeMapperInterface::class));
119148
120149 $ this ->assertSame (GraphQLType::string (), $ mapper ->toGraphQLOutputType ($ type , null , $ reflection , $ docBlock ));
121150 $ this ->assertSame (GraphQLType::int (), $ mapper ->toGraphQLInputType ($ type , null , 'arg1 ' , $ reflection , $ docBlock ));
0 commit comments