|
19 | 19 | use Magento\AdobeStockClient\Model\ConnectionFactory;
|
20 | 20 | use Magento\AdobeStockClient\Model\ConnectionWrapper;
|
21 | 21 | use Magento\AdobeStockClientApi\Api\ConfigInterface;
|
| 22 | +use Magento\Framework\Exception\AuthenticationException; |
| 23 | +use Magento\Framework\Exception\AuthorizationException; |
22 | 24 | use PHPUnit\Framework\MockObject\MockObject;
|
23 | 25 | use PHPUnit\Framework\TestCase;
|
24 | 26 |
|
@@ -163,6 +165,30 @@ public function testGetNextResponseWithException(): void
|
163 | 165 | $this->connectionWrapper->getNextResponse();
|
164 | 166 | }
|
165 | 167 |
|
| 168 | + /** |
| 169 | + * Next response with exception that should be explained in more detail |
| 170 | + * |
| 171 | + * @param string $connectionException Exception message thrown by the connection |
| 172 | + * @param string $thrownException Exception message that will throws by the getNextResponse method |
| 173 | + * @param string $exception Exception class that will throws by the getNextResponse method |
| 174 | + * |
| 175 | + * @return void |
| 176 | + * @dataProvider detailedExceptionsForGetNextResponseProvider |
| 177 | + */ |
| 178 | + public function testGetNextResponseWithExceptionThatNeedMoreAttention( |
| 179 | + string $connectionException, |
| 180 | + string $thrownException, |
| 181 | + string $exception |
| 182 | + ): void { |
| 183 | + $this->expectException($exception); |
| 184 | + $this->expectExceptionMessage($thrownException); |
| 185 | + $this->imsConfig->method('getApiKey') |
| 186 | + ->willReturn('key'); |
| 187 | + $this->adobeStockMock->method('getNextResponse') |
| 188 | + ->willThrowException(new \Exception('Beginning of the exception message ' . $connectionException)); |
| 189 | + $this->connectionWrapper->getNextResponse(); |
| 190 | + } |
| 191 | + |
166 | 192 | /**
|
167 | 193 | * Get member profile test
|
168 | 194 | */
|
@@ -258,6 +284,37 @@ public function testFlushTokens(): void
|
258 | 284 | $this->connectionWrapper->downloadAssetUrl(new LicenseRequest());
|
259 | 285 | }
|
260 | 286 |
|
| 287 | + /** |
| 288 | + * Provider of exceptions that need more attention in getNextResponse method |
| 289 | + * |
| 290 | + * @return array |
| 291 | + */ |
| 292 | + public function detailedExceptionsForGetNextResponseProvider(): array |
| 293 | + { |
| 294 | + return [ |
| 295 | + [ |
| 296 | + 'connection_exception_message' => 'Api Key is invalid', |
| 297 | + 'thrown_exception_message' => 'Adobe API Key is invalid!', |
| 298 | + 'thrown_exception' => AuthenticationException::class, |
| 299 | + ], |
| 300 | + [ |
| 301 | + 'connection_exception_message' => 'Api Key is required', |
| 302 | + 'thrown_exception_message' => 'Adobe Api Key is required!', |
| 303 | + 'thrown_exception' => AuthenticationException::class, |
| 304 | + ], |
| 305 | + [ |
| 306 | + 'connection_exception_message' => 'Oauth token is not valid', |
| 307 | + 'thrown_exception_message' => 'Adobe API login has expired!', |
| 308 | + 'thrown_exception' => AuthorizationException::class, |
| 309 | + ], |
| 310 | + [ |
| 311 | + 'connection_exception_message' => 'Could not validate the oauth token', |
| 312 | + 'thrown_exception_message' => 'Adobe API login has expired!', |
| 313 | + 'thrown_exception' => AuthorizationException::class, |
| 314 | + ], |
| 315 | + ]; |
| 316 | + } |
| 317 | + |
261 | 318 | /**
|
262 | 319 | * Ste's tokens
|
263 | 320 | */
|
|
0 commit comments