|
4 | 4 |
|
5 | 5 | namespace MezzioTest\Authentication\OAuth2;
|
6 | 6 |
|
| 7 | +use Laminas\Diactoros\ServerRequest; |
7 | 8 | use League\Event\ListenerInterface;
|
8 | 9 | use League\Event\ListenerProviderInterface;
|
9 | 10 | use League\OAuth2\Server\AuthorizationServer;
|
@@ -133,6 +134,43 @@ static function (RequestEvent $event): void {
|
133 | 134 | $result = $factory($mockContainer);
|
134 | 135 |
|
135 | 136 | self::assertInstanceOf(AuthorizationServer::class, $result);
|
| 137 | + |
| 138 | + // Ensure listeners have been registered correctly. If they have not, then emitting an event will fail |
| 139 | + $request = $this->createMock(ServerRequest::class); |
| 140 | + $result->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); |
| 141 | + } |
| 142 | + |
| 143 | + public function testInvokeWithListenerConfigFailsIfPriorityIsNotAnInteger(): void |
| 144 | + { |
| 145 | + $mockContainer = $this->getContainerMock(); |
| 146 | + $mockListener = $this->createMock(ListenerInterface::class); |
| 147 | + $mockContainer->set(ListenerInterface::class, $mockListener); |
| 148 | + |
| 149 | + $config = [ |
| 150 | + 'authentication' => [ |
| 151 | + 'private_key' => __DIR__ . '/TestAsset/private.key', |
| 152 | + 'encryption_key' => 'iALlwJ1sH77dmFCJFo+pMdM6Af4bF/hCca1EDDx7MwE=', |
| 153 | + 'access_token_expire' => 'P1D', |
| 154 | + 'grants' => [ |
| 155 | + ClientCredentialsGrant::class => ClientCredentialsGrant::class, |
| 156 | + ], |
| 157 | + 'event_listeners' => [ |
| 158 | + [ |
| 159 | + RequestEvent::CLIENT_AUTHENTICATION_FAILED, |
| 160 | + ListenerInterface::class, |
| 161 | + 'one', |
| 162 | + ], |
| 163 | + ], |
| 164 | + ], |
| 165 | + ]; |
| 166 | + |
| 167 | + $mockContainer->set('config', $config); |
| 168 | + |
| 169 | + $factory = new AuthorizationServerFactory(); |
| 170 | + |
| 171 | + $this->expectException(InvalidConfigException::class); |
| 172 | + |
| 173 | + $factory($mockContainer); |
136 | 174 | }
|
137 | 175 |
|
138 | 176 | public function testInvokeWithListenerConfigMissingServiceThrowsException(): void
|
|
0 commit comments