Test case for timeouts

This commit is contained in:
lukas committed 2026-10-16 10:49:51 +00:00
1 parent bb4a95e8de
commit 0295627da1
1 file changed
+22 -2
+22 -2
View File
@@ -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());
}
}
}