Working state
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Media\Exception\InvalidMimeTypeException;
|
||||
use App\Media\Media;
|
||||
use App\Media\MediaRepositoryInterface;
|
||||
use App\Media\MediaService;
|
||||
use App\Post\PostRepositoryInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
@@ -33,6 +34,8 @@ final class MediaServiceTest extends TestCase
|
||||
/** @var MediaRepositoryInterface&MockObject */
|
||||
private MediaRepositoryInterface $repository;
|
||||
|
||||
private PostRepositoryInterface $postRepository;
|
||||
|
||||
private string $uploadDir;
|
||||
|
||||
private MediaService $service;
|
||||
@@ -40,11 +43,13 @@ final class MediaServiceTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = $this->createMock(MediaRepositoryInterface::class);
|
||||
$this->postRepository = $this->createMock(PostRepositoryInterface::class);
|
||||
$this->uploadDir = sys_get_temp_dir() . '/slim_media_test_' . uniqid();
|
||||
@mkdir($this->uploadDir, 0755, true);
|
||||
|
||||
$this->service = new MediaService(
|
||||
mediaRepository: $this->repository,
|
||||
postRepository: $this->postRepository,
|
||||
uploadDir: $this->uploadDir,
|
||||
uploadUrl: '/media',
|
||||
maxSize: 5 * 1024 * 1024,
|
||||
@@ -104,10 +109,13 @@ final class MediaServiceTest extends TestCase
|
||||
public function testStoreReturnsDuplicateUrl(): void
|
||||
{
|
||||
$tmpFile = $this->createMinimalJpeg();
|
||||
$hash = hash_file('sha256', $tmpFile);
|
||||
|
||||
$existing = new Media(7, 'existing.jpg', '/media/existing.jpg', $hash, 1);
|
||||
$this->repository->method('findByHash')->willReturn($existing);
|
||||
$existing = new Media(7, 'existing.jpg', '/media/existing.jpg', 'existing-hash', 1);
|
||||
$this->repository
|
||||
->expects($this->once())
|
||||
->method('findByHashForUser')
|
||||
->with($this->callback(static fn (mixed $value): bool => is_string($value) && $value !== ''), 1)
|
||||
->willReturn($existing);
|
||||
$this->repository->expects($this->never())->method('create');
|
||||
|
||||
$file = $this->makeUploadedFileFromPath($tmpFile, filesize($tmpFile));
|
||||
@@ -128,7 +136,7 @@ final class MediaServiceTest extends TestCase
|
||||
{
|
||||
$tmpFile = $this->createMinimalJpeg();
|
||||
|
||||
$this->repository->method('findByHash')->willReturn(null);
|
||||
$this->repository->method('findByHashForUser')->willReturn(null);
|
||||
$this->repository->expects($this->once())->method('create');
|
||||
|
||||
$file = $this->makeUploadedFileFromPath($tmpFile, filesize($tmpFile));
|
||||
|
||||
Reference in New Issue
Block a user