Test case for timeouts
This commit is contained in:
1 parent
bb4a95e8de
commit
0295627da1
1 file changed
+22
-2
@@ -8,14 +8,18 @@ namespace CloudObjects\SDK;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
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;
|
use CloudObjects\SDK\Exceptions\CoreAPIException;
|
||||||
|
|
||||||
class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
|
class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
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]);
|
$mock = new MockHandler([$response]);
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$this->retriever->setClient(new Client(['handler' => $handler]));
|
$this->retriever->setClient(new Client(['handler' => $handler]));
|
||||||
@@ -70,4 +74,20 @@ class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
|
|||||||
$this->retriever->getObjectNode($coid);
|
$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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user