createMock(MediaRepositoryInterface::class); $mediaUsageReader = $this->createMock(MediaUsageReaderInterface::class); $tmpFile = tempnam(sys_get_temp_dir(), 'upload_'); self::assertNotFalse($tmpFile); file_put_contents($tmpFile, 'not an image'); $file = $this->createMock(UploadedMediaInterface::class); $file->method('getSize')->willReturn(filesize($tmpFile)); $file->method('getTemporaryPath')->willReturn($tmpFile); $storage = new LocalMediaStorage(sys_get_temp_dir()); $service = new MediaApplicationService($repo, $mediaUsageReader, new StoreMedia($repo, $storage, '/media', 500000), new DeleteMedia($repo, $storage)); try { $this->expectException(InvalidMimeTypeException::class); $service->store($file, 1); } finally { @unlink($tmpFile); } } }