test filesystem abstraction
This commit is contained in:
parent
bc7937d2b3
commit
be2c51bfb7
10 changed files with 66 additions and 78 deletions
58
backend/tests/Fakes/FakeFilesystem.php
Normal file
58
backend/tests/Fakes/FakeFilesystem.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Shared\Files\FileToUpload;
|
||||
use App\Shared\Files\Filesystem;
|
||||
|
||||
class FakeFilesystem implements Filesystem
|
||||
{
|
||||
/**
|
||||
* @var array<int, array{file: FileToUpload, folder: string}>
|
||||
*/
|
||||
public array $uploads = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public array $deletedPaths = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public array $readPaths = [];
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private array $filesByPath = [];
|
||||
|
||||
public function upload(FileToUpload $file, string $folder): string
|
||||
{
|
||||
$this->uploads[] = ['file' => $file, 'folder' => $folder];
|
||||
|
||||
return $folder . '/fake-' . $file->getOriginalName();
|
||||
}
|
||||
|
||||
public function url(string $path): string
|
||||
{
|
||||
return 'https://test.local/storage/' . $path;
|
||||
}
|
||||
|
||||
public function delete(string $path): void
|
||||
{
|
||||
$this->deletedPaths[] = $path;
|
||||
}
|
||||
|
||||
public function put(string $path, string $contents): void
|
||||
{
|
||||
$this->filesByPath[$path] = $contents;
|
||||
}
|
||||
|
||||
public function read(string $path): ?string
|
||||
{
|
||||
$this->readPaths[] = $path;
|
||||
|
||||
return $this->filesByPath[$path] ?? null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue