1+ <?php
2+
3+ namespace TheCodingMachine \GraphQLite \Mappers \Parameters ;
4+
5+ use Generator ;
6+ use phpDocumentor \Reflection \DocBlock ;
7+ use ReflectionMethod ;
8+ use stdClass ;
9+ use TheCodingMachine \GraphQLite \AbstractQueryProviderTest ;
10+ use TheCodingMachine \GraphQLite \Annotations \InjectUser ;
11+ use TheCodingMachine \GraphQLite \Parameters \InjectUserParameter ;
12+ use TheCodingMachine \GraphQLite \Security \AuthenticationServiceInterface ;
13+
14+ class InjectUserParameterHandlerTest extends AbstractQueryProviderTest
15+ {
16+ /**
17+ * @dataProvider mapParameterProvider
18+ */
19+ public function testMapParameter (bool $ optional , string $ method ): void
20+ {
21+ $ authenticationService = $ this ->createMock (AuthenticationServiceInterface::class);
22+
23+ $ refMethod = new ReflectionMethod (__CLASS__ , $ method );
24+ $ parameter = $ refMethod ->getParameters ()[0 ];
25+
26+ $ mapped = (new InjectUserParameterHandler ($ authenticationService ))->mapParameter (
27+ $ parameter ,
28+ new DocBlock (),
29+ null ,
30+ $ this ->getAnnotationReader ()->getParameterAnnotationsPerParameter ([$ parameter ])['user ' ],
31+ $ this ->createMock (ParameterHandlerInterface::class),
32+ );
33+
34+ self ::assertEquals (
35+ new InjectUserParameter ($ authenticationService , $ optional ),
36+ $ mapped
37+ );
38+ }
39+
40+ public function mapParameterProvider (): Generator
41+ {
42+ yield 'required user ' => [false , 'requiredUser ' ];
43+ yield 'optional user ' => [true , 'optionalUser ' ];
44+ yield 'missing type ' => [true , 'missingType ' ];
45+ }
46+
47+ private function requiredUser (
48+ #[InjectUser] stdClass $ user ,
49+ ) {
50+ }
51+
52+ private function optionalUser (
53+ #[InjectUser] stdClass |null $ user ,
54+ ) {
55+ }
56+
57+ private function missingType (
58+ #[InjectUser] $ user ,
59+ ) {
60+ }
61+ }
0 commit comments