public function testDirectoryCreateOpenAndDelete() { if (!$this->testWritable()) { return; } try { $file = Directory::create($this->getTestDir()); } catch (Exception $e) { $this->assert(false, "The directory could not be created with message: {$e->getMessage()}."); } try { $file = Directory::open($file->getPathname()); } catch (Exception $e) { $this->assert(false, "The directory could not be opened with message: {$e->getMessage()}."); } try { $file->delete(); } catch (Exception $e) { $this->assert(false, "The directory {$file->getPathname()} could not be deleted with message: {$e->getMessage()}."); } }
public static function create($file, $mask = self::MASK) { // the file must not exist if (is_file($file)) { throw new LogicException("The file {$file} already exists."); } // the directory it is supposed to be in $dir = dirname($file); // create the directory if it doesn't exist if (!is_dir($dir)) { Directory::create($dir); } // create the file in the directory file_put_contents($file, ''); // set permissions chmod($file, $mask); // open and return return static::open($file); }