createMock(MediaRepositoryInterface::class); $postRepo = $this->createMock(PostRepositoryInterface::class); $tmpFile = tempnam(sys_get_temp_dir(), 'upload_'); self::assertNotFalse($tmpFile); file_put_contents($tmpFile, 'not an image'); $stream = $this->createMock(StreamInterface::class); $stream->expects($this->once())->method('getMetadata')->with('uri')->willReturn($tmpFile); $file = $this->createMock(UploadedFileInterface::class); $file->method('getSize')->willReturn(filesize($tmpFile)); $file->method('getStream')->willReturn($stream); $file->method('getClientFilename')->willReturn('photo.png'); $service = new MediaApplicationService($repo, $postRepo, new LocalMediaStorage(sys_get_temp_dir()), '/media', 500000); try { $this->expectException(InvalidMimeTypeException::class); $service->store($file, 1); } finally { @unlink($tmpFile); } } }