function it_does_not_get_the_file_because_the_id_does_not_exist(FileRepository $repository, FileOfIdQuery $query) { $query->id()->shouldBeCalled()->willReturn('file-id'); $id = new FileId('file-id'); $repository->fileOfId($id)->shouldBeCalled()->willReturn(null); $this->shouldThrow(FileDoesNotExistException::class)->during__invoke($query); }
/** * Handles the given query. * * @param FileOfIdQuery $aQuery The query * * @throws FileDoesNotExistException when the file id does not exist * * @return mixed */ public function __invoke(FileOfIdQuery $aQuery) { $fileId = new FileId($aQuery->id()); $file = $this->repository->fileOfId($fileId); if (null === $file) { throw new FileDoesNotExistException(); } $this->dataTransformer->write($file); return $this->dataTransformer->read(); }