|
12 | 12 | use ScriptFUSION\Porter\Connector\ConnectionContext; |
13 | 13 | use ScriptFUSION\Porter\Connector\Connector; |
14 | 14 | use ScriptFUSION\Porter\Connector\ConnectorOptions; |
| 15 | +use ScriptFUSION\Porter\Connector\ImportConnector; |
15 | 16 | use ScriptFUSION\Porter\Connector\RecoverableConnectorException; |
16 | 17 | use ScriptFUSION\Porter\ImportException; |
17 | 18 | use ScriptFUSION\Porter\Porter; |
@@ -303,6 +304,36 @@ public function testCustomFetchExceptionHandler() |
303 | 304 | $this->porter->import($this->specification); |
304 | 305 | } |
305 | 306 |
|
| 307 | + /** |
| 308 | + * Tests that when a provider fetch exception handler is specified and the connector throws a recoverable |
| 309 | + * exception, the handler is called before the user handler. |
| 310 | + */ |
| 311 | + public function testCustomProviderFetchExceptionHandler() |
| 312 | + { |
| 313 | + $this->specification->setFetchExceptionHandler(function () { |
| 314 | + throw new \LogicException('This exception must not be thrown!'); |
| 315 | + }); |
| 316 | + |
| 317 | + $this->arrangeConnectorException($connectorException = |
| 318 | + new RecoverableConnectorException('This exception is caught by the provider handler.')); |
| 319 | + |
| 320 | + $this->resource |
| 321 | + ->shouldReceive('fetch') |
| 322 | + ->andReturnUsing(function (ImportConnector $connector) use ($connectorException) { |
| 323 | + $connector->setExceptionHandler(function (\Exception $exception) use ($connectorException) { |
| 324 | + self::assertSame($connectorException, $exception); |
| 325 | + |
| 326 | + throw new \RuntimeException('This exception is thrown by the provider handler.'); |
| 327 | + }); |
| 328 | + |
| 329 | + yield $connector->fetch('foo'); |
| 330 | + }) |
| 331 | + ; |
| 332 | + |
| 333 | + $this->setExpectedException(\RuntimeException::class); |
| 334 | + $this->porter->importOne($this->specification); |
| 335 | + } |
| 336 | + |
306 | 337 | #endregion |
307 | 338 |
|
308 | 339 | public function testFilter() |
|
0 commit comments