Refatoring : Working state
This commit is contained in:
@@ -267,7 +267,6 @@ src/
|
|||||||
│ ├── MediaController.php
|
│ ├── MediaController.php
|
||||||
│ ├── MediaRepository.php
|
│ ├── MediaRepository.php
|
||||||
│ ├── MediaRepositoryInterface.php
|
│ ├── MediaRepositoryInterface.php
|
||||||
│ ├── MediaService.php
|
|
||||||
│ └── MediaServiceInterface.php
|
│ └── MediaServiceInterface.php
|
||||||
├── Post/
|
├── Post/
|
||||||
│ ├── Post.php
|
│ ├── Post.php
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Media;
|
|
||||||
|
|
||||||
use App\Media\Application\MediaApplicationService;
|
|
||||||
use App\Media\Infrastructure\LocalMediaStorage;
|
|
||||||
use App\Post\PostRepositoryInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pont de compatibilité : l'implémentation métier principale vit désormais dans
|
|
||||||
* App\Media\Application\MediaApplicationService.
|
|
||||||
*/
|
|
||||||
final class MediaService extends MediaApplicationService implements MediaServiceInterface
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
MediaRepositoryInterface $mediaRepository,
|
|
||||||
PostRepositoryInterface $postRepository,
|
|
||||||
string $uploadDir,
|
|
||||||
string $uploadUrl,
|
|
||||||
int $maxSize,
|
|
||||||
) {
|
|
||||||
parent::__construct(
|
|
||||||
mediaRepository: $mediaRepository,
|
|
||||||
postRepository: $postRepository,
|
|
||||||
mediaStorage: new LocalMediaStorage($uploadDir),
|
|
||||||
uploadUrl: $uploadUrl,
|
|
||||||
maxSize: $maxSize,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,8 @@ namespace Tests\Media;
|
|||||||
|
|
||||||
use App\Media\Media;
|
use App\Media\Media;
|
||||||
use App\Media\MediaRepositoryInterface;
|
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 App\Post\PostRepositoryInterface;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
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);
|
$this->uploadDir = sys_get_temp_dir() . '/slim_media_race_' . uniqid('', true);
|
||||||
@mkdir($this->uploadDir, 0755, 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
|
protected function tearDown(): void
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ namespace Tests\Media;
|
|||||||
use App\Media\Exception\FileTooLargeException;
|
use App\Media\Exception\FileTooLargeException;
|
||||||
use App\Media\Exception\StorageException;
|
use App\Media\Exception\StorageException;
|
||||||
use App\Media\MediaRepositoryInterface;
|
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 App\Post\PostRepositoryInterface;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
@@ -23,7 +24,7 @@ final class MediaServiceEdgeCasesTest extends TestCase
|
|||||||
$file = $this->createMock(UploadedFileInterface::class);
|
$file = $this->createMock(UploadedFileInterface::class);
|
||||||
$file->method('getSize')->willReturn(null);
|
$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);
|
$this->expectException(StorageException::class);
|
||||||
$service->store($file, 1);
|
$service->store($file, 1);
|
||||||
@@ -41,7 +42,7 @@ final class MediaServiceEdgeCasesTest extends TestCase
|
|||||||
$file->method('getSize')->willReturn(999999);
|
$file->method('getSize')->willReturn(999999);
|
||||||
$file->method('getStream')->willReturn($stream);
|
$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);
|
$this->expectException(FileTooLargeException::class);
|
||||||
$service->store($file, 1);
|
$service->store($file, 1);
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ namespace Tests\Media;
|
|||||||
|
|
||||||
use App\Media\Exception\InvalidMimeTypeException;
|
use App\Media\Exception\InvalidMimeTypeException;
|
||||||
use App\Media\MediaRepositoryInterface;
|
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 App\Post\PostRepositoryInterface;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
@@ -31,7 +32,7 @@ final class MediaServiceInvalidMimeTest extends TestCase
|
|||||||
$file->method('getStream')->willReturn($stream);
|
$file->method('getStream')->willReturn($stream);
|
||||||
$file->method('getClientFilename')->willReturn('photo.png');
|
$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 {
|
try {
|
||||||
$this->expectException(InvalidMimeTypeException::class);
|
$this->expectException(InvalidMimeTypeException::class);
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ namespace Tests\Media;
|
|||||||
|
|
||||||
use App\Media\Exception\StorageException;
|
use App\Media\Exception\StorageException;
|
||||||
use App\Media\MediaRepositoryInterface;
|
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 App\Post\PostRepositoryInterface;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
@@ -28,7 +29,7 @@ final class MediaServiceInvalidTempPathTest extends TestCase
|
|||||||
|
|
||||||
$postRepo = $this->createMock(PostRepositoryInterface::class);
|
$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->expectException(StorageException::class);
|
||||||
$this->expectExceptionMessage('Impossible de localiser le fichier temporaire uploadé');
|
$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\Exception\InvalidMimeTypeException;
|
||||||
use App\Media\Media;
|
use App\Media\Media;
|
||||||
use App\Media\MediaRepositoryInterface;
|
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 App\Post\PostRepositoryInterface;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@@ -50,7 +51,7 @@ final class MediaServiceTest extends TestCase
|
|||||||
$this->service = new MediaService(
|
$this->service = new MediaService(
|
||||||
mediaRepository: $this->repository,
|
mediaRepository: $this->repository,
|
||||||
postRepository: $this->postRepository,
|
postRepository: $this->postRepository,
|
||||||
uploadDir: $this->uploadDir,
|
mediaStorage: new LocalMediaStorage($this->uploadDir),
|
||||||
uploadUrl: '/media',
|
uploadUrl: '/media',
|
||||||
maxSize: 5 * 1024 * 1024,
|
maxSize: 5 * 1024 * 1024,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user