48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Media;
|
|
|
|
use App\Media\MediaService;
|
|
use App\Media\MediaRepositoryInterface;
|
|
use App\Media\Exception\FileTooLargeException;
|
|
use App\Media\Exception\StorageException;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Http\Message\UploadedFileInterface;
|
|
use Psr\Http\Message\StreamInterface;
|
|
|
|
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
|
|
|
final class MediaServiceEdgeCasesTest extends TestCase
|
|
{
|
|
public function testRejectsWhenSizeUnknown(): void
|
|
{
|
|
$repo = $this->createMock(MediaRepositoryInterface::class);
|
|
|
|
$file = $this->createMock(UploadedFileInterface::class);
|
|
$file->method('getSize')->willReturn(null);
|
|
|
|
$service = new MediaService($repo, '/tmp', '/media', 1000);
|
|
|
|
$this->expectException(StorageException::class);
|
|
$service->store($file, 1);
|
|
}
|
|
|
|
public function testRejectsWhenFileTooLarge(): void
|
|
{
|
|
$repo = $this->createMock(MediaRepositoryInterface::class);
|
|
|
|
$stream = $this->createMock(StreamInterface::class);
|
|
$stream->method('getMetadata')->willReturn('/tmp/file');
|
|
|
|
$file = $this->createMock(UploadedFileInterface::class);
|
|
$file->method('getSize')->willReturn(999999);
|
|
$file->method('getStream')->willReturn($stream);
|
|
|
|
$service = new MediaService($repo, '/tmp', '/media', 100);
|
|
|
|
$this->expectException(FileTooLargeException::class);
|
|
$service->store($file, 1);
|
|
}
|
|
}
|