Improved attachment retrieval and added test cases

This commit is contained in:
lukas committed 2026-10-22 09:33:19 +00:00
1 parent 6f2fd40464
commit fde9661c2c
4 files changed
+91 -2

No files matched your search

@@ -115,6 +115,35 @@ class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
$this->assertNull($content);
}
public function testWhenAPIThrowsErrorForAttachment() {
$this->setMockResponse(
new Response(200, ['Content-Type' => 'application/ld+json'],
'{"@id":"coid://cloudobjects.io/Test","coid://cloudobjects.io/isAtRevision":"1-abc"}'),
new Response(500)
);
$this->expectException(CoreAPIException::class);
$this->retriever->getAttachment(new IRI('coid://cloudobjects.io/Test'), 'file.txt');
}
public function testWhenAPITimesOutForAttachment() {
$this->setMockResponse(
new Response(200, ['Content-Type' => 'application/ld+json'],
'{"@id":"coid://cloudobjects.io/Test","coid://cloudobjects.io/isAtRevision":"1-abc"}'),
new ConnectException(
'cURL error 28: Operation timed out',
new Request('GET', 'cloudobjects.io')
)
);
try {
$this->retriever->getAttachment(new IRI('coid://cloudobjects.io/Test'), 'file.txt');
$this->fail('Expected CoreAPIException was not thrown.');
} catch (CoreAPIException $e) {
$this->assertInstanceOf(ConnectException::class, $e->getPrevious());
}
}
private function createFallbackStoreDirectory() : string {
$directory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'clobj-fallback-'.uniqid();
mkdir($directory);