Refatoring : Working state
This commit is contained in:
@@ -5,7 +5,8 @@ namespace Tests\Media;
|
||||
|
||||
use App\Media\Media;
|
||||
use App\Media\MediaRepositoryInterface;
|
||||
use App\Media\MediaService;
|
||||
use App\Media\Application\MediaApplicationService as MediaService;
|
||||
use App\Media\Infrastructure\LocalMediaStorage;
|
||||
use App\Post\PostRepositoryInterface;
|
||||
use PDOException;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@@ -33,7 +34,7 @@ final class MediaServiceDuplicateAfterInsertRaceTest extends TestCase
|
||||
$this->uploadDir = sys_get_temp_dir() . '/slim_media_race_' . uniqid('', true);
|
||||
@mkdir($this->uploadDir, 0755, true);
|
||||
|
||||
$this->service = new MediaService($this->repository, $this->postRepository, $this->uploadDir, '/media', 5 * 1024 * 1024);
|
||||
$this->service = new MediaService($this->repository, $this->postRepository, new LocalMediaStorage($this->uploadDir), '/media', 5 * 1024 * 1024);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
|
||||
@@ -6,7 +6,8 @@ namespace Tests\Media;
|
||||
use App\Media\Exception\FileTooLargeException;
|
||||
use App\Media\Exception\StorageException;
|
||||
use App\Media\MediaRepositoryInterface;
|
||||
use App\Media\MediaService;
|
||||
use App\Media\Application\MediaApplicationService as MediaService;
|
||||
use App\Media\Infrastructure\LocalMediaStorage;
|
||||
use App\Post\PostRepositoryInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
@@ -23,7 +24,7 @@ final class MediaServiceEdgeCasesTest extends TestCase
|
||||
$file = $this->createMock(UploadedFileInterface::class);
|
||||
$file->method('getSize')->willReturn(null);
|
||||
|
||||
$service = new MediaService($repo, $postRepo, '/tmp', '/media', 1000);
|
||||
$service = new MediaService($repo, $postRepo, new LocalMediaStorage('/tmp'), '/media', 1000);
|
||||
|
||||
$this->expectException(StorageException::class);
|
||||
$service->store($file, 1);
|
||||
@@ -41,7 +42,7 @@ final class MediaServiceEdgeCasesTest extends TestCase
|
||||
$file->method('getSize')->willReturn(999999);
|
||||
$file->method('getStream')->willReturn($stream);
|
||||
|
||||
$service = new MediaService($repo, $postRepo, '/tmp', '/media', 100);
|
||||
$service = new MediaService($repo, $postRepo, new LocalMediaStorage('/tmp'), '/media', 100);
|
||||
|
||||
$this->expectException(FileTooLargeException::class);
|
||||
$service->store($file, 1);
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace Tests\Media;
|
||||
|
||||
use App\Media\Exception\InvalidMimeTypeException;
|
||||
use App\Media\MediaRepositoryInterface;
|
||||
use App\Media\MediaService;
|
||||
use App\Media\Application\MediaApplicationService as MediaService;
|
||||
use App\Media\Infrastructure\LocalMediaStorage;
|
||||
use App\Post\PostRepositoryInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
@@ -31,7 +32,7 @@ final class MediaServiceInvalidMimeTest extends TestCase
|
||||
$file->method('getStream')->willReturn($stream);
|
||||
$file->method('getClientFilename')->willReturn('photo.png');
|
||||
|
||||
$service = new MediaService($repo, $postRepo, sys_get_temp_dir(), '/media', 500000);
|
||||
$service = new MediaService($repo, $postRepo, new LocalMediaStorage(sys_get_temp_dir()), '/media', 500000);
|
||||
|
||||
try {
|
||||
$this->expectException(InvalidMimeTypeException::class);
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace Tests\Media;
|
||||
|
||||
use App\Media\Exception\StorageException;
|
||||
use App\Media\MediaRepositoryInterface;
|
||||
use App\Media\MediaService;
|
||||
use App\Media\Application\MediaApplicationService as MediaService;
|
||||
use App\Media\Infrastructure\LocalMediaStorage;
|
||||
use App\Post\PostRepositoryInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
@@ -28,7 +29,7 @@ final class MediaServiceInvalidTempPathTest extends TestCase
|
||||
|
||||
$postRepo = $this->createMock(PostRepositoryInterface::class);
|
||||
|
||||
$service = new MediaService($repository, $postRepo, sys_get_temp_dir(), '/media', 500000);
|
||||
$service = new MediaService($repository, $postRepo, new LocalMediaStorage(sys_get_temp_dir()), '/media', 500000);
|
||||
|
||||
$this->expectException(StorageException::class);
|
||||
$this->expectExceptionMessage('Impossible de localiser le fichier temporaire uploadé');
|
||||
|
||||
@@ -7,7 +7,8 @@ use App\Media\Exception\FileTooLargeException;
|
||||
use App\Media\Exception\InvalidMimeTypeException;
|
||||
use App\Media\Media;
|
||||
use App\Media\MediaRepositoryInterface;
|
||||
use App\Media\MediaService;
|
||||
use App\Media\Application\MediaApplicationService as MediaService;
|
||||
use App\Media\Infrastructure\LocalMediaStorage;
|
||||
use App\Post\PostRepositoryInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -50,7 +51,7 @@ final class MediaServiceTest extends TestCase
|
||||
$this->service = new MediaService(
|
||||
mediaRepository: $this->repository,
|
||||
postRepository: $this->postRepository,
|
||||
uploadDir: $this->uploadDir,
|
||||
mediaStorage: new LocalMediaStorage($this->uploadDir),
|
||||
uploadUrl: '/media',
|
||||
maxSize: 5 * 1024 * 1024,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user