function it_does_not_get_the_file_because_the_name_does_not_exist(FileRepository $repository, FileOfNameQuery $query) { $query->name()->shouldBeCalled()->willReturn('file.pdf'); $name = new FileName('file.pdf'); $repository->fileOfName($name)->shouldBeCalled()->willReturn(null); $this->shouldThrow(FileDoesNotExistException::class)->during__invoke($query); }
/** * Handles the given query. * * @param FileOfNameQuery $aQuery The query * * @throws FileDoesNotExistException when the file name does not exist * * @return mixed */ public function __invoke(FileOfNameQuery $aQuery) { $fileName = new FileName($aQuery->name()); $file = $this->repository->fileOfName($fileName); if (null === $file) { throw new FileDoesNotExistException(); } $this->dataTransformer->write($file); return $this->dataTransformer->read(); }