Renamed, document and tested static_config_path / static_object_directory

This commit is contained in:
lukas committed 2026-10-18 17:17:41 +00:00
1 parent 55419acb09
commit c4f5504fdf
4 files changed
+94 -6

No files matched your search

@@ -366,4 +366,61 @@ class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
}
}
private function createStaticObjectDirectory() : string {
$directory = $this->createFallbackStoreDirectory();
mkdir($directory.'/cloudobjects.io/Test', 0777, true);
file_put_contents($directory.'/cloudobjects.io/Test/object.jsonld',
'{"@id":"coid://cloudobjects.io/Test","http://www.w3.org/2000/01/rdf-schema#label":"Static"}');
return $directory;
}
public function testStaticObjectDirectoryUsedWithoutContactingAPI() {
$directory = $this->createStaticObjectDirectory();
$this->retriever = new ObjectRetriever([
'static_object_directory' => $directory,
]);
$mock = new MockHandler([ new Response(500) ]);
$this->retriever->setClient(new Client(['handler' => HandlerStack::create($mock)]));
try {
$object = $this->retriever->getObjectNode(new IRI('coid://cloudobjects.io/Test'));
$this->assertEquals('Static', $object->getProperty('http://www.w3.org/2000/01/rdf-schema#label')->getValue());
// The mocked response has not been consumed
$this->assertCount(1, $mock);
} finally {
$this->removeDirectory($directory);
}
}
public function testStaticObjectDirectoryWithDeprecatedOptionName() {
$directory = $this->createStaticObjectDirectory();
$this->retriever = new ObjectRetriever([
'static_config_path' => $directory,
]);
$this->setMockResponse(new Response(500));
try {
$object = $this->retriever->getObjectNode(new IRI('coid://cloudobjects.io/Test'));
$this->assertEquals('Static', $object->getProperty('http://www.w3.org/2000/01/rdf-schema#label')->getValue());
} finally {
$this->removeDirectory($directory);
}
}
public function testStaticObjectDirectoryFallsThroughToAPI() {
$directory = $this->createStaticObjectDirectory();
$this->retriever = new ObjectRetriever([
'static_object_directory' => $directory,
]);
$this->setMockResponse(new Response(200, ['Content-Type' => 'application/ld+json'],
'{"@id":"coid://cloudobjects.io/Other","http://www.w3.org/2000/01/rdf-schema#label":"API"}'));
try {
$object = $this->retriever->getObjectNode(new IRI('coid://cloudobjects.io/Other'));
$this->assertEquals('API', $object->getProperty('http://www.w3.org/2000/01/rdf-schema#label')->getValue());
} finally {
$this->removeDirectory($directory);
}
}
}