test filesystem abstraction

This commit is contained in:
Yisroel Baum 2026-06-26 08:23:17 +03:00
parent bc7937d2b3
commit be2c51bfb7
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
10 changed files with 66 additions and 78 deletions

View file

@ -3,9 +3,9 @@
namespace Tests\Fakes;
use App\Shared\Files\FileToUpload;
use App\Shared\Files\FileUploader;
use App\Shared\Files\Filesystem;
class FakeFileUploader implements FileUploader
class FakeFilesystem implements Filesystem
{
/**
* @var array<int, array{file: FileToUpload, folder: string}>
@ -17,6 +17,16 @@ class FakeFileUploader implements FileUploader
*/
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];
@ -33,4 +43,16 @@ class FakeFileUploader implements FileUploader
{
$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;
}
}

View file

@ -1,30 +0,0 @@
<?php
namespace Tests\Fakes;
use App\Shared\Files\StoredFileReader;
class FakeStoredFileReader implements StoredFileReader
{
/**
* @var array<string, string>
*/
private array $filesByPath = [];
/**
* @var string[]
*/
public array $readPaths = [];
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;
}
}