first commit
This commit is contained in:
45
tests/Media/MediaServiceEdgeCasesTest.php
Normal file
45
tests/Media/MediaServiceEdgeCasesTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user