55use GraphQL \Error \Debug ;
66use GraphQL \GraphQL ;
77use GraphQL \Type \SchemaConfig ;
8+ use Mouf \Composer \ClassNameMapper ;
89use PHPUnit \Framework \TestCase ;
10+ use Symfony \Component \Cache \Simple \ArrayCache ;
911use Symfony \Component \Cache \Simple \PhpFilesCache ;
1012use TheCodingMachine \GraphQLite \Containers \BasicAutoWiringContainer ;
1113use TheCodingMachine \GraphQLite \Containers \EmptyContainer ;
1214use TheCodingMachine \GraphQLite \Hydrators \FactoryHydrator ;
15+ use TheCodingMachine \GraphQLite \Mappers \CannotMapTypeException ;
1316use TheCodingMachine \GraphQLite \Mappers \CompositeTypeMapper ;
1417use TheCodingMachine \GraphQLite \Security \VoidAuthenticationService ;
1518use TheCodingMachine \GraphQLite \Security \VoidAuthorizationService ;
@@ -57,10 +60,47 @@ public function testSetters(): void
5760 $ this ->doTestSchema ($ schema );
5861 }
5962
63+ public function testClassNameMapperInjectionWithValidMapper (): void
64+ {
65+ $ factory = new SchemaFactory (
66+ new ArrayCache (),
67+ new BasicAutoWiringContainer (
68+ new EmptyContainer ()
69+ )
70+ );
71+ $ factory ->setAuthenticationService (new VoidAuthenticationService ())
72+ ->setAuthorizationService (new VoidAuthorizationService ())
73+ ->setClassNameMapper (ClassNameMapper::createFromComposerFile (null , null , true ))
74+ ->addControllerNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration \\Controllers ' )
75+ ->addTypeNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration ' );
76+
77+ $ schema = $ factory ->createSchema ();
78+
79+ $ this ->doTestSchema ($ schema );
80+ }
81+
82+ public function testClassNameMapperInjectionWithInvalidMapper (): void
83+ {
84+ $ factory = new SchemaFactory (
85+ new ArrayCache (),
86+ new BasicAutoWiringContainer (
87+ new EmptyContainer ()
88+ )
89+ );
90+ $ factory ->setAuthenticationService (new VoidAuthenticationService ())
91+ ->setAuthorizationService (new VoidAuthorizationService ())
92+ ->setClassNameMapper (new ClassNameMapper ())
93+ ->addControllerNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration \\Controllers ' )
94+ ->addTypeNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration ' );
95+
96+ $ this ->expectException (\TypeError::class);
97+ $ this ->doTestSchema ($ factory ->createSchema ());
98+ }
99+
60100 public function testException (): void
61101 {
62102 $ container = new BasicAutoWiringContainer (new EmptyContainer ());
63- $ cache = new PhpFilesCache ();
103+ $ cache = new ArrayCache ();
64104
65105 $ factory = new SchemaFactory ($ cache , $ container );
66106
@@ -71,7 +111,7 @@ public function testException(): void
71111 public function testException2 (): void
72112 {
73113 $ container = new BasicAutoWiringContainer (new EmptyContainer ());
74- $ cache = new PhpFilesCache ();
114+ $ cache = new ArrayCache ();
75115
76116 $ factory = new SchemaFactory ($ cache , $ container );
77117 $ factory ->addTypeNamespace ('TheCodingMachine \\GraphQLite \\Fixtures \\Integration ' );
0 commit comments