Closed as not planned
Description
In the FileGetContents-Class is this code:
$response = file_get_contents($uri);
That do some problems in unit tests, cause you cant mock or fake the schema files. My example idea is this in Laravel, if someone want to test the code later (or extend the file in a seperate file):
$fileGetContents = new class extends FileGetContents
{
protected function getContents(string $uri): false|string
{
if (!File::exists($uri)) {
throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
}
return File::get($uri);
}
};
$factory = new Factory();
$uriRetriever = $factory->getUriRetriever();
$uriRetriever->setUriRetriever($fileGetContents);
In the unit test, you can mock it:
File::shouldReceive('exists')
->with('test.json')
->andReturn(true);
File::shouldReceive('get')
->with('file://test.json')
->andReturn('{...}');
Metadata
Metadata
Assignees
Labels
No labels