first commit
This commit is contained in:
51
tests/Media/MediaServiceEdgeCasesTest.php
Normal file
51
tests/Media/MediaServiceEdgeCasesTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Media;
|
||||
|
||||
use Netig\Netslim\Media\Application\MediaApplicationService;
|
||||
use Netig\Netslim\Media\Application\UseCase\DeleteMedia;
|
||||
use Netig\Netslim\Media\Application\UseCase\StoreMedia;
|
||||
use Netig\Netslim\Media\Contracts\MediaUsageReaderInterface;
|
||||
use Netig\Netslim\Media\Domain\Exception\FileTooLargeException;
|
||||
use Netig\Netslim\Media\Domain\Exception\StorageException;
|
||||
use Netig\Netslim\Media\Domain\Repository\MediaRepositoryInterface;
|
||||
use Netig\Netslim\Media\Domain\Service\UploadedMediaInterface;
|
||||
use Netig\Netslim\Media\Infrastructure\LocalMediaStorage;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class MediaServiceEdgeCasesTest extends TestCase
|
||||
{
|
||||
public function testRejectsWhenSizeUnknown(): void
|
||||
{
|
||||
$repo = $this->createMock(MediaRepositoryInterface::class);
|
||||
$mediaUsageReader = $this->createMock(MediaUsageReaderInterface::class);
|
||||
|
||||
$file = $this->createMock(UploadedMediaInterface::class);
|
||||
$file->method('getSize')->willReturn(null);
|
||||
|
||||
$storage = new LocalMediaStorage('/tmp');
|
||||
$service = new MediaApplicationService($repo, $mediaUsageReader, new StoreMedia($repo, $storage, '/media', 1000), new DeleteMedia($repo, $storage));
|
||||
|
||||
$this->expectException(StorageException::class);
|
||||
$service->store($file, 1);
|
||||
}
|
||||
|
||||
public function testRejectsWhenFileTooLarge(): void
|
||||
{
|
||||
$repo = $this->createMock(MediaRepositoryInterface::class);
|
||||
$mediaUsageReader = $this->createMock(MediaUsageReaderInterface::class);
|
||||
|
||||
$file = $this->createMock(UploadedMediaInterface::class);
|
||||
$file->method('getSize')->willReturn(999999);
|
||||
$file->method('getTemporaryPath')->willReturn('/tmp/file');
|
||||
|
||||
$storage = new LocalMediaStorage('/tmp');
|
||||
$service = new MediaApplicationService($repo, $mediaUsageReader, new StoreMedia($repo, $storage, '/media', 100), new DeleteMedia($repo, $storage));
|
||||
|
||||
$this->expectException(FileTooLargeException::class);
|
||||
$service->store($file, 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user