1111use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
1212use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
1313use Symfony \Component \Security \Core \Security as CoreSecurity ;
14+ use Symfony \Bundle \SecurityBundle \Security as BundleSecurity ;
15+ use Symfony \Component \HttpKernel \Kernel ;
1416use Symfony \Component \Security \Core \User \InMemoryUser ;
1517use Symfony \Component \Security \Core \User \User ;
1618use Symfony \Component \Security \Core \User \UserInterface ;
@@ -22,14 +24,32 @@ protected function getFunctions()
2224 return [new GetUser ()];
2325 }
2426
27+ protected function getMockedSecurity ()
28+ {
29+ if (Kernel::VERSION_ID >= 60200 ) {
30+ return $ this ->createMock (BundleSecurity::class);
31+ } else {
32+ return $ this ->createMock (CoreSecurity::class);
33+ }
34+ }
35+
36+ protected function getSecurityWithStorage (TokenStorageInterface $ storage )
37+ {
38+ if (Kernel::VERSION_ID >= 60200 ) {
39+ return new BundleSecurity ($ this ->getDIContainerMock (['security.token_storage ' => $ storage ]));
40+ } else {
41+ return new CoreSecurity ($ this ->getDIContainerMock (['security.token_storage ' => $ storage ]));
42+ }
43+ }
44+
2545 public function testEvaluator (): void
2646 {
2747 if (class_exists (InMemoryUser::class)) {
2848 $ testUser = new InMemoryUser ('testUser ' , 'testPassword ' );
2949 } else {
3050 $ testUser = new User ('testUser ' , 'testPassword ' );
3151 }
32- $ coreSecurity = $ this ->createMock (CoreSecurity::class );
52+ $ coreSecurity = $ this ->getMockedSecurity ( );
3353 $ coreSecurity ->method ('getUser ' )->willReturn ($ testUser );
3454 $ services = $ this ->createGraphQLServices (['security ' => new Security ($ coreSecurity )]);
3555
@@ -40,7 +60,7 @@ public function testEvaluator(): void
4060 public function testGetUserNoTokenStorage (): void
4161 {
4262 $ {TypeGenerator::GRAPHQL_SERVICES } = $ this ->createGraphQLServices (
43- ['security ' => new Security ($ this ->createMock (CoreSecurity::class ))]
63+ ['security ' => new Security ($ this ->getMockedSecurity ( ))]
4464 );
4565 $ {TypeGenerator::GRAPHQL_SERVICES }->get ('security ' );
4666 $ this ->assertNull (eval ($ this ->getCompileCode ()));
@@ -51,11 +71,7 @@ public function testGetUserNoToken(): void
5171 $ tokenStorage = $ this ->getMockBuilder (TokenStorageInterface::class)->getMock ();
5272 $ {TypeGenerator::GRAPHQL_SERVICES } = $ this ->createGraphQLServices (
5373 [
54- 'security ' => new Security (
55- new CoreSecurity (
56- $ this ->getDIContainerMock (['security.token_storage ' => $ tokenStorage ])
57- )
58- ),
74+ 'security ' => new Security ($ this ->getSecurityWithStorage ($ tokenStorage )),
5975 ]
6076 );
6177 $ {TypeGenerator::GRAPHQL_SERVICES }->get ('security ' );
@@ -77,11 +93,7 @@ public function testGetUser($user, $expectedUser): void
7793
7894 $ {TypeGenerator::GRAPHQL_SERVICES } = $ this ->createGraphQLServices (
7995 [
80- 'security ' => new Security (
81- new CoreSecurity (
82- $ this ->getDIContainerMock (['security.token_storage ' => $ tokenStorage ])
83- )
84- ),
96+ 'security ' => new Security ($ this ->getSecurityWithStorage ($ tokenStorage )),
8597 ]
8698 );
8799 $ {TypeGenerator::GRAPHQL_SERVICES }->get ('security ' );
0 commit comments