44
55namespace OAuth \Tests \Server ;
66
7+ use OAuth \Event \AfterCreateAccessTokenEvent ;
78use OAuth \Event \AfterGrantAccessEvent ;
9+ use OAuth \Event \VerifyTokenEvent ;
810use OAuth \Exception \OAuthAuthenticateException ;
911use OAuth \Exception \OAuthServerException ;
1012use OAuth \Model \AccessTokenInterface ;
@@ -81,7 +83,7 @@ protected function setUp(): void
8183 $ this ->authCodeStorage ,
8284 new AuthCodeGrantExtension ($ this ->authCodeStorage ),
8385 new ClientCredentialsGrantExtension (),
84- new RefreshTokenGrantExtension ($ this ->refreshTokenStorage ),
86+ new RefreshTokenGrantExtension ($ this ->eventDispatcher , $ this -> refreshTokenStorage ),
8587 new UserCredentialsGrantExtension ($ this ->userProviderInterface , $ this ->passwordHasherFactory ),
8688 $ this ->customGrantExtension ,
8789 );
@@ -105,6 +107,8 @@ public function testVerifyAccessToken(): void
105107 $ token = $ this ->manager ->verifyAccessToken ('my_token ' );
106108 $ this ->assertNotNull ($ token );
107109 $ this ->assertEquals ('my_token ' , $ token ->getToken ());
110+
111+ $ this ->assertEquals ([VerifyTokenEvent::class], $ this ->eventDispatcher ->getOrphanedEvents ());
108112 }
109113
110114 public static function provideVerifyAccessTokenException (): iterable
@@ -173,6 +177,8 @@ public function testVerifyAccessTokenException(
173177 $ this ->expectException (OAuthAuthenticateException::class);
174178
175179 $ this ->manager ->verifyAccessToken ($ tokenParam , $ scope );
180+
181+ $ this ->assertEquals ([], $ this ->eventDispatcher ->getOrphanedEvents ());
176182 }
177183
178184 public static function provideGetBearerToken (): iterable
@@ -380,7 +386,7 @@ public function testGrantAccessTokenAuthCode(Request $request, array $expectedRe
380386 $ response = $ this ->manager ->grantAccessToken ($ request );
381387
382388 $ this ->assertEquals ($ expectedResponse , json_decode ($ response ->getContent (), true , 512 , JSON_THROW_ON_ERROR ));
383- $ this ->assertEquals ([AfterGrantAccessEvent::class], $ this ->eventDispatcher ->getOrphanedEvents ());
389+ $ this ->assertEquals ([AfterGrantAccessEvent::class, AfterCreateAccessTokenEvent::class ], $ this ->eventDispatcher ->getOrphanedEvents ());
384390 }
385391
386392 public static function provideGrantAccessTokenUserCredentials (): iterable
@@ -433,7 +439,7 @@ public function testGrantAccessTokenUserCredentials(Request $request): void
433439 'scope ' => null ,
434440 'refresh_token ' => 'refresh_token ' ,
435441 ], json_decode ($ response ->getContent (), true , 512 , JSON_THROW_ON_ERROR ));
436- $ this ->assertEquals ([AfterGrantAccessEvent::class], $ this ->eventDispatcher ->getOrphanedEvents ());
442+ $ this ->assertEquals ([AfterGrantAccessEvent::class, AfterCreateAccessTokenEvent::class ], $ this ->eventDispatcher ->getOrphanedEvents ());
437443 }
438444
439445 public static function provideGrantAccessTokenClientCredentials (): iterable
@@ -478,7 +484,7 @@ public function testGrantAccessTokenClientCredentials(Request $request): void
478484 'token_type ' => 'bearer ' ,
479485 'scope ' => null ,
480486 ], json_decode ($ response ->getContent (), true , 512 , JSON_THROW_ON_ERROR ));
481- $ this ->assertEquals ([AfterGrantAccessEvent::class], $ this ->eventDispatcher ->getOrphanedEvents ());
487+ $ this ->assertEquals ([AfterGrantAccessEvent::class, AfterCreateAccessTokenEvent::class ], $ this ->eventDispatcher ->getOrphanedEvents ());
482488 }
483489
484490 public static function provideGrantAccessTokenRefreshToken (): iterable
@@ -537,7 +543,7 @@ public function testGrantAccessTokenRefreshToken(Request $request): void
537543 'scope ' => 'read ' ,
538544 'refresh_token ' => 'refresh_token ' ,
539545 ], json_decode ($ response ->getContent (), true , 512 , JSON_THROW_ON_ERROR ));
540- $ this ->assertEquals ([AfterGrantAccessEvent::class], $ this ->eventDispatcher ->getOrphanedEvents ());
546+ $ this ->assertEquals ([VerifyTokenEvent::class, AfterGrantAccessEvent::class, AfterCreateAccessTokenEvent ::class], $ this ->eventDispatcher ->getOrphanedEvents ());
541547 }
542548
543549 public static function provideGrantAccessTokenCustom (): iterable
@@ -595,7 +601,7 @@ public function checkGrantExtension(ClientInterface $client, Config $config, str
595601 'scope ' => null ,
596602 'refresh_token ' => 'refresh_token ' ,
597603 ], json_decode ($ response ->getContent (), true , 512 , JSON_THROW_ON_ERROR ));
598- $ this ->assertEquals ([AfterGrantAccessEvent::class], $ this ->eventDispatcher ->getOrphanedEvents ());
604+ $ this ->assertEquals ([AfterGrantAccessEvent::class, AfterCreateAccessTokenEvent::class ], $ this ->eventDispatcher ->getOrphanedEvents ());
599605 }
600606
601607 public static function provideGrantAccessTokenException (): iterable
0 commit comments