Improved exception handling
This commit is contained in:
1 parent
70c52b8ad2
commit
12ed032a31
3 files changed
+50
-9
No files matched your search
@@ -9,6 +9,7 @@ namespace CloudObjects\SDK;
|
||||
use ML\IRI\IRI;
|
||||
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
||||
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
||||
use CloudObjects\SDK\Exceptions\CoreAPIException;
|
||||
|
||||
class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
@@ -50,4 +51,23 @@ class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
|
||||
$this->assertNull($object->getString('urn:example:nonexistingvalue'));
|
||||
}
|
||||
|
||||
public function testGetNonExistingResource() {
|
||||
$this->setMockResponse(new Response(404));
|
||||
|
||||
// should return "null"
|
||||
$coid = new IRI('coid://nonexistingresource.example.com');
|
||||
|
||||
$object = $this->retriever->getObjectNode($coid);
|
||||
$this->assertNull($object);
|
||||
}
|
||||
|
||||
public function testWhenAPIThrowsError() {
|
||||
$this->setMockResponse(new Response(500));
|
||||
|
||||
$coid = new IRI('coid://nonexistingresource.example.com');
|
||||
|
||||
$this->expectException(CoreAPIException::class);
|
||||
$this->retriever->getObjectNode($coid);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user