/** * Create the directory specified by the $file if it does not exist * * @param FileNode $file * @param string|null $visibility public or private visibility * * @return LocalFile The original file inputted * @throws MakeDirectoryFailedException */ public function makeDirectory(FileNode $file, $visibility = null) { $madeDirectory = $file->getFilesystem()->createDir($file->getDirectory(), ['visibility' => $visibility ?: static::VISIBILITY_PUBLIC]); if (!$madeDirectory) { throw new MakeDirectoryFailedException($file, error_get_last()['message']); } return $file; }
public function testWhenCreateDirReturnsFalseAnExceptionIsthrown() { $fileSystem = m::mock(FilesystemInterface::class); $directory = new FileNode($fileSystem, 'random/path'); $fileSystem->shouldReceive('createDir')->with($directory->getDirectory(), ['visibility' => 'public'])->andReturn(false); $this->expectException(MakedirectoryFailedException::class); $maker = new MakeDirectory(); $maker->makeDirectory($directory); }