diff --git a/tests/OfflineTests/ObjectRetrieverMockTest.php b/tests/OfflineTests/ObjectRetrieverMockTest.php index 6e88d70..170fcf5 100644 --- a/tests/OfflineTests/ObjectRetrieverMockTest.php +++ b/tests/OfflineTests/ObjectRetrieverMockTest.php @@ -8,14 +8,18 @@ namespace CloudObjects\SDK; use ML\IRI\IRI; use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler, - GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response; + GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Request, GuzzleHttp\Psr7\Response; +use GuzzleHttp\Exception\ConnectException; use CloudObjects\SDK\Exceptions\CoreAPIException; class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase { private $retriever; - private function setMockResponse(Response $response) { + /** + * @param Response|\Throwable $response A response, or an exception to throw instead. + */ + private function setMockResponse($response) { $mock = new MockHandler([$response]); $handler = HandlerStack::create($mock); $this->retriever->setClient(new Client(['handler' => $handler])); @@ -70,4 +74,20 @@ class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase { $this->retriever->getObjectNode($coid); } + public function testWhenAPITimesOut() { + $this->setMockResponse(new ConnectException( + 'cURL error 28: Operation timed out', + new Request('GET', 'cloudobjects.io') + )); + + $coid = new IRI('coid://cloudobjects.io'); + + try { + $this->retriever->getObjectNode($coid); + $this->fail('Expected CoreAPIException was not thrown.'); + } catch (CoreAPIException $e) { + $this->assertInstanceOf(ConnectException::class, $e->getPrevious()); + } + } + }