Files
slim-blog/tests/Media/MediaServiceInvalidTempPathTest.php
2026-03-16 15:16:56 +01:00

40 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Media;
use App\Media\Exception\StorageException;
use App\Media\MediaRepositoryInterface;
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;
use Psr\Http\Message\UploadedFileInterface;
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
final class MediaServiceInvalidTempPathTest extends TestCase
{
public function testRejectsWhenTemporaryPathIsMissing(): void
{
$repository = $this->createMock(MediaRepositoryInterface::class);
$stream = $this->createMock(StreamInterface::class);
$stream->expects($this->once())->method('getMetadata')->with('uri')->willReturn(null);
$file = $this->createMock(UploadedFileInterface::class);
$file->method('getSize')->willReturn(128);
$file->method('getStream')->willReturn($stream);
$postRepo = $this->createMock(PostRepositoryInterface::class);
$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é');
$service->store($file, 1);
}
}