/** * @param string $fileName * @return string */ public function generate(string $fileName) : string { if (trim($fileName) === '') { throw PathGenerationException::emptyFileName(); } return $this->documentUploadDir . $this->pathGenerator->generatePathFromName($fileName); }
/** * @param \Dvs\PathGenerator\Interfaces\PathGenerator $pathGenerator */ public function it_should_return_generated_path($pathGenerator) { //given $uploadDir = 'upload/'; $fileName = 'test'; $pathGenerator->generatePathFromName($fileName)->willReturn($filePath = 't/e/s/t'); //when $this->generate($fileName)->shouldReturn($uploadDir . $filePath); }
/** * @param \Dvs\FileBundle\Adapter\FlySystem\Local $filesystem * @param \Dvs\PathGenerator\Interfaces\PathGenerator $pathGenerator */ public function it_should_create_file_from_resource($filesystem, $pathGenerator) { $subDirectories = $this->getSubDirectories(); $directory = 'directory'; $file = File::create($filename = 'filename', $directory . DIRECTORY_SEPARATOR . $subDirectories, $resource = 'resource'); $pathGenerator->generatePathFromName($filename)->willReturn($subDirectories); $filesystem->getPathPrefix()->willReturn('/root'); $filesystem->writeFile($file)->shouldBeCalled(); $this->create($filename, $resource, $directory)->shouldBeLike($file); }
/** * @param string $name * * @return string */ public function getDirectoryFromName($name) { return $this->pathGenerator->generatePathFromName($name); }