How to use path method of vfsStream class

Best VfsStream code snippet using vfsStream.path

vfsStreamWrapper.php

Source:vfsStreamWrapper.php Github

copy

Full Screen

...141 {142 self::$quota = $quota;143 }144 /**145 * returns content for given path146 *147 * @param string $path148 * @return vfsStreamContent149 */150 protected function getContent($path)151 {152 if (null === self::$root) {153 return null;154 }155 if (self::$root->getName() === $path) {156 return self::$root;157 }158 if (self::$root->hasChild($path) === true) {159 return self::$root->getChild($path);160 }161 return null;162 }163 /**164 * returns content for given path but only when it is of given type165 *166 * @param string $path167 * @param int $type168 * @return vfsStreamContent169 */170 protected function getContentOfType($path, $type)171 {172 $content = $this->getContent($path);173 if (null !== $content && $content->getType() === $type) {174 return $content;175 }176 return null;177 }178 /**179 * splits path into its dirname and the basename180 *181 * @param string $path182 * @return string[]183 */184 protected function splitPath($path)185 {186 $lastSlashPos = strrpos($path, '/');187 if (false === $lastSlashPos) {188 return array('dirname' => '', 'basename' => $path);189 }190 return array('dirname' => substr($path, 0, $lastSlashPos),191 'basename' => substr($path, $lastSlashPos + 1)192 );193 }194 /**195 * helper method to resolve a path from /foo/bar/. to /foo/bar196 *197 * @param string $path198 * @return string199 */200 protected function resolvePath($path)201 {202 $newPath = array();203 foreach (explode('/', $path) as $pathPart) {204 if ('.' !== $pathPart) {205 if ('..' !== $pathPart) {206 $newPath[] = $pathPart;207 } else {208 array_pop($newPath);209 }210 }211 }212 return implode('/', $newPath);213 }214 /**215 * open the stream216 *217 * @param string $path the path to open218 * @param string $mode mode for opening219 * @param string $options options for opening220 * @param string $opened_path full path that was actually opened221 * @return bool222 */223 public function stream_open($path, $mode, $options, $opened_path)224 {225 $extended = ((strstr($mode, '+') !== false) ? (true) : (false));226 $mode = str_replace(array('b', '+'), '', $mode);227 if (in_array($mode, array('r', 'w', 'a', 'x', 'c')) === false) {228 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {229 trigger_error('Illegal mode ' . $mode . ', use r, w, a, x or c, flavoured with b and/or +', E_USER_WARNING);230 }231 return false;232 }233 $this->mode = $this->calculateMode($mode, $extended);234 $path = $this->resolvePath(vfsStream::path($path));235 $this->content = $this->getContentOfType($path, vfsStreamContent::TYPE_FILE);236 if (null !== $this->content) {237 if (self::WRITE === $mode) {238 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {239 trigger_error('File ' . $path . ' already exists, can not open with mode x', E_USER_WARNING);240 }241 return false;242 }243 if (244 (self::TRUNCATE === $mode || self::APPEND === $mode) &&245 $this->content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false246 ) {247 return false;248 }249 if (self::TRUNCATE === $mode) {250 $this->content->openWithTruncate();251 } elseif (self::APPEND === $mode) {252 $this->content->openForAppend();253 } else {254 if (!$this->content->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {255 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {256 trigger_error('Permission denied', E_USER_WARNING);257 }258 return false;259 }260 $this->content->open();261 }262 return true;263 }264 $content = $this->createFile($path, $mode, $options);265 if (false === $content) {266 return false;267 }268 $this->content = $content;269 return true;270 }271 /**272 * creates a file at given path273 *274 * @param string $path the path to open275 * @param string $mode mode for opening276 * @param string $options options for opening277 * @return bool278 */279 private function createFile($path, $mode = null, $options = null)280 {281 $names = $this->splitPath($path);282 if (empty($names['dirname']) === true) {283 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {284 trigger_error('File ' . $names['basename'] . ' does not exist', E_USER_WARNING);285 }286 return false;287 }288 $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR);289 if (null === $dir) {290 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {291 trigger_error('Directory ' . $names['dirname'] . ' does not exist', E_USER_WARNING);292 }293 return false;294 } elseif ($dir->hasChild($names['basename']) === true) {295 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {296 trigger_error('Directory ' . $names['dirname'] . ' already contains a director named ' . $names['basename'], E_USER_WARNING);297 }298 return false;299 }300 if (self::READ === $mode) {301 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {302 trigger_error('Can not open non-existing file ' . $path . ' for reading', E_USER_WARNING);303 }304 return false;305 }306 if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {307 if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {308 trigger_error('Can not create new file in non-writable path ' . $names['dirname'], E_USER_WARNING);309 }310 return false;311 }312 return vfsStream::newFile($names['basename'])->at($dir);313 }314 /**315 * calculates the file mode316 *317 * @param string $mode opening mode: r, w, a or x318 * @param bool $extended true if + was set with opening mode319 * @return int320 */321 protected function calculateMode($mode, $extended)322 {323 if (true === $extended) {324 return self::ALL;325 }326 if (self::READ === $mode) {327 return self::READONLY;328 }329 return self::WRITEONLY;330 }331 /**332 * closes the stream333 */334 public function stream_close()335 {336 $this->content->lock(LOCK_UN);337 }338 /**339 * read the stream up to $count bytes340 *341 * @param int $count amount of bytes to read342 * @return string343 */344 public function stream_read($count)345 {346 if (self::WRITEONLY === $this->mode) {347 return '';348 }349 if ($this->content->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {350 return '';351 }352 return $this->content->read($count);353 }354 /**355 * writes data into the stream356 *357 * @param string $data358 * @return int amount of bytes written359 */360 public function stream_write($data)361 {362 if (self::READONLY === $this->mode) {363 return 0;364 }365 if ($this->content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {366 return 0;367 }368 if (self::$quota->isLimited()) {369 $data = substr($data, 0, self::$quota->spaceLeft(self::$root->sizeSummarized()));370 }371 return $this->content->write($data);372 }373 /**374 * truncates a file to a given length375 *376 * @param int $size length to truncate file to377 * @return bool378 * @since 1.1.0379 */380 public function stream_truncate($size)381 {382 if (self::READONLY === $this->mode) {383 return false;384 }385 if ($this->content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {386 return false;387 }388 if ($this->content->getType() !== vfsStreamContent::TYPE_FILE) {389 return false;390 }391 if (self::$quota->isLimited() && $this->content->size() < $size) {392 $maxSize = self::$quota->spaceLeft(self::$root->sizeSummarized());393 if (0 === $maxSize) {394 return false;395 }396 if ($size > $maxSize) {397 $size = $maxSize;398 }399 }400 return $this->content->truncate($size);401 }402 /**403 * sets metadata like owner, user or permissions404 *405 * @param string $path406 * @param int $option407 * @param mixed $var408 * @return bool409 * @since 1.1.0410 */411 public function stream_metadata($path, $option, $var)412 {413 $path = $this->resolvePath(vfsStream::path($path));414 $content = $this->getContent($path);415 switch ($option) {416 case STREAM_META_TOUCH:417 if (null === $content) {418 $content = $this->createFile($path);419 }420 if (isset($var[0])) {421 $content->lastModified($var[0]);422 }423 if (isset($var[1])) {424 $content->lastAccessed($var[1]);425 }426 return true;427 case STREAM_META_OWNER_NAME:428 return false;429 case STREAM_META_OWNER:430 if (null === $content) {431 return false;432 }433 $content->chown($var);434 return true;435 case STREAM_META_GROUP_NAME:436 return false;437 case STREAM_META_GROUP:438 if (null === $content) {439 return false;440 }441 $content->chgrp($var);442 return true;443 case STREAM_META_ACCESS:444 if (null === $content) {445 return false;446 }447 $content->chmod($var);448 return true;449 default:450 return false;451 }452 }453 /**454 * checks whether stream is at end of file455 *456 * @return bool457 */458 public function stream_eof()459 {460 return $this->content->eof();461 }462 /**463 * returns the current position of the stream464 *465 * @return int466 */467 public function stream_tell()468 {469 return $this->content->getBytesRead();470 }471 /**472 * seeks to the given offset473 *474 * @param int $offset475 * @param int $whence476 * @return bool477 */478 public function stream_seek($offset, $whence)479 {480 return $this->content->seek($offset, $whence);481 }482 /**483 * flushes unstored data into storage484 *485 * @return bool486 */487 public function stream_flush()488 {489 return true;490 }491 /**492 * returns status of stream493 *494 * @return array495 */496 public function stream_stat()497 {498 $fileStat = array('dev' => 0,499 'ino' => 0,500 'mode' => $this->content->getType() | $this->content->getPermissions(),501 'nlink' => 0,502 'uid' => $this->content->getUser(),503 'gid' => $this->content->getGroup(),504 'rdev' => 0,505 'size' => $this->content->size(),506 'atime' => $this->content->fileatime(),507 'mtime' => $this->content->filemtime(),508 'ctime' => $this->content->filectime(),509 'blksize' => -1,510 'blocks' => -1511 );512 return array_merge(array_values($fileStat), $fileStat);513 }514 /**515 * retrieve the underlaying resource516 *517 * Please note that this method always returns false as there is no518 * underlaying resource to return.519 *520 * @param int $cast_as521 * @since 0.9.0522 * @see https://github.com/mikey179/vfsStream/issues/3523 * @return bool524 */525 public function stream_cast($cast_as)526 {527 return false;528 }529 /**530 * set lock status for stream531 *532 * @param int $operation533 * @return bool534 * @since 0.10.0535 * @see https://github.com/mikey179/vfsStream/issues/6536 * @see https://github.com/mikey179/vfsStream/issues/31537 */538 public function stream_lock($operation)539 {540 if ((LOCK_NB & $operation) == LOCK_NB) {541 $operation = $operation - LOCK_NB;542 }543 if (LOCK_EX === $operation && $this->content->isLocked()) {544 return false;545 } elseif (LOCK_SH === $operation && $this->content->hasExclusiveLock()) {546 return false;547 }548 $this->content->lock($operation);549 return true;550 }551 /**552 * sets options on the stream553 *554 * @param int $option key of option to set555 * @param int $arg1556 * @param int $arg2557 * @return bool558 * @since 0.10.0559 * @see https://github.com/mikey179/vfsStream/issues/15560 * @see http://www.php.net/manual/streamwrapper.stream-set-option.php561 */562 public function stream_set_option($option, $arg1, $arg2)563 {564 switch ($option) {565 case STREAM_OPTION_BLOCKING:566 // break omitted567 case STREAM_OPTION_READ_TIMEOUT:568 // break omitted569 case STREAM_OPTION_WRITE_BUFFER:570 // break omitted571 default:572 // nothing to do here573 }574 return false;575 }576 /**577 * remove the data under the given path578 *579 * @param string $path580 * @return bool581 */582 public function unlink($path)583 {584 $realPath = $this->resolvePath(vfsStream::path($path));585 $content = $this->getContent($realPath);586 if (null === $content || $content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {587 return false;588 }589 if ($content->getType() !== vfsStreamContent::TYPE_FILE) {590 trigger_error('unlink(' . $path . '): Operation not permitted', E_USER_WARNING);591 return false;592 }593 return $this->doUnlink($realPath);594 }595 /**596 * removes a path597 *598 * @param string $path599 * @return bool600 */601 protected function doUnlink($path)602 {603 if (self::$root->getName() === $path) {604 // delete root? very brave. :)605 self::$root = null;606 clearstatcache();607 return true;608 }609 $names = $this->splitPath($path);610 $content = $this->getContent($names['dirname']);611 if ($content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {612 return false;613 }614 clearstatcache();615 return $content->removeChild($names['basename']);616 }617 /**618 * rename from one path to another619 *620 * @param string $path_from621 * @param string $path_to622 * @return bool623 * @author Benoit Aubuchon624 */625 public function rename($path_from, $path_to)626 {627 $srcRealPath = $this->resolvePath(vfsStream::path($path_from));628 $dstRealPath = $this->resolvePath(vfsStream::path($path_to));629 $srcContent = $this->getContent($srcRealPath);630 if (null == $srcContent) {631 trigger_error(' No such file or directory', E_USER_WARNING);632 return false;633 }634 $dstNames = $this->splitPath($dstRealPath);635 $dstParentContent = $this->getContent($dstNames['dirname']);636 if (null == $dstParentContent) {637 trigger_error('No such file or directory', E_USER_WARNING);638 return false;639 }640 if (!$dstParentContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {641 trigger_error('Permission denied', E_USER_WARNING);642 return false;643 }644 if ($dstParentContent->getType() !== vfsStreamContent::TYPE_DIR) {645 trigger_error('Target is not a directory', E_USER_WARNING);646 return false;647 }648 $dstContent = clone $srcContent;649 // Renaming the filename650 $dstContent->rename($dstNames['basename']);651 // Copying to the destination652 $dstParentContent->addChild($dstContent);653 // Removing the source654 return $this->doUnlink($srcRealPath);655 }656 /**657 * creates a new directory658 *659 * @param string $path660 * @param int $mode661 * @param int $options662 * @return bool663 */664 public function mkdir($path, $mode, $options)665 {666 $umask = vfsStream::umask();667 if (0 < $umask) {668 $permissions = $mode & ~$umask;669 } else {670 $permissions = $mode;671 }672 $path = $this->resolvePath(vfsStream::path($path));673 if (null !== $this->getContent($path)) {674 trigger_error('mkdir(): Path vfs://' . $path . ' exists', E_USER_WARNING);675 return false;676 }677 if (null === self::$root) {678 self::$root = vfsStream::newDirectory($path, $permissions);679 return true;680 }681 $maxDepth = count(explode('/', $path));682 $names = $this->splitPath($path);683 $newDirs = $names['basename'];684 $dir = null;685 $i = 0;686 while ($dir === null && $i < $maxDepth) {687 $dir = $this->getContent($names['dirname']);688 $names = $this->splitPath($names['dirname']);689 if (null == $dir) {690 $newDirs = $names['basename'] . '/' . $newDirs;691 }692 $i++;693 }694 if (null === $dir695 || $dir->getType() !== vfsStreamContent::TYPE_DIR696 || $dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {697 return false;698 }699 $recursive = ((STREAM_MKDIR_RECURSIVE & $options) !== 0) ? (true) : (false);700 if (strpos($newDirs, '/') !== false && false === $recursive) {701 return false;702 }703 vfsStream::newDirectory($newDirs, $permissions)->at($dir);704 return true;705 }706 /**707 * removes a directory708 *709 * @param string $path710 * @param int $options711 * @return bool712 * @todo consider $options with STREAM_MKDIR_RECURSIVE713 */714 public function rmdir($path, $options)715 {716 $path = $this->resolvePath(vfsStream::path($path));717 $child = $this->getContentOfType($path, vfsStreamContent::TYPE_DIR);718 if (null === $child) {719 return false;720 }721 // can only remove empty directories722 if (count($child->getChildren()) > 0) {723 return false;724 }725 if (self::$root->getName() === $path) {726 // delete root? very brave. :)727 self::$root = null;728 clearstatcache();729 return true;730 }731 $names = $this->splitPath($path);732 $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR);733 if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {734 return false;735 }736 clearstatcache();737 return $dir->removeChild($child->getName());738 }739 /**740 * opens a directory741 *742 * @param string $path743 * @param int $options744 * @return bool745 */746 public function dir_opendir($path, $options)747 {748 $path = $this->resolvePath(vfsStream::path($path));749 $this->dir = $this->getContentOfType($path, vfsStreamContent::TYPE_DIR);750 if (null === $this->dir || $this->dir->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {751 return false;752 }753 $this->dirIterator = $this->dir->getIterator();754 return true;755 }756 /**757 * reads directory contents758 *759 * @return string760 */761 public function dir_readdir()762 {763 $dir = $this->dirIterator->current();764 if (null === $dir) {765 return false;766 }767 $this->dirIterator->next();768 return $dir->getName();769 }770 /**771 * reset directory iteration772 *773 * @return bool774 */775 public function dir_rewinddir()776 {777 return $this->dirIterator->rewind();778 }779 /**780 * closes directory781 *782 * @return bool783 */784 public function dir_closedir()785 {786 $this->dirIterator = null;787 return true;788 }789 /**790 * returns status of url791 *792 * @param string $path path of url to return status for793 * @param int $flags flags set by the stream API794 * @return array795 */796 public function url_stat($path, $flags)797 {798 $content = $this->getContent($this->resolvePath(vfsStream::path($path)));799 if (null === $content) {800 if (($flags & STREAM_URL_STAT_QUIET) != STREAM_URL_STAT_QUIET) {801 trigger_error(' No such file or directory: ' . $path, E_USER_WARNING);802 }803 return false;804 }805 $fileStat = array('dev' => 0,806 'ino' => 0,807 'mode' => $content->getType() | $content->getPermissions(),808 'nlink' => 0,809 'uid' => $content->getUser(),810 'gid' => $content->getGroup(),811 'rdev' => 0,812 'size' => $content->size(),813 'atime' => $content->fileatime(),814 'mtime' => $content->filemtime(),815 'ctime' => $content->filectime(),...

Full Screen

Full Screen

FileSystemStorageTest.php

Source:FileSystemStorageTest.php Github

copy

Full Screen

...23 {24 $storage = new FileSystemStorage('/var/www/', 'http://localhost/');25 $this->assertInstanceOf('NaturalWeb\FileStorage\Storage\StorageInterface', $storage);26 $this->assertAttributeEquals('http://localhost/', 'host', $storage);27 $this->assertAttributeEquals('/var/www/', 'pathRoot', $storage);28 $this->assertEquals('/var/www/', $storage->getPathRoot());29 }30 public function testMethodUploadWithoutOverride()31 {32 $pathRoot = vfsStream::url('uploads');33 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');34 $source = __DIR__ . '/_file/file_upload.txt';35 $this->assertTrue($storage->upload($source, '/file_upload.txt'));36 $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('file_upload.txt'));37 }38 public function testMethodDelete()39 {40 $pathRoot = vfsStream::url('uploads');41 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');42 vfsStream::newFile('foo.txt')->at(vfsStreamWrapper::getRoot());43 $path = vfsStream::url("uploads/foo.txt");44 $this->assertTrue($storage->delete('/foo.txt'));45 $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('foo.txt'));46 $this->assertFalse(file_exists($path));47 }48 public function testMethodCreateFolder()49 {50 $pathRoot = vfsStream::url('uploads');51 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');52 $path = vfsStream::url("uploads/baz");53 $this->assertTrue($storage->createFolder('/baz'));54 $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('baz'));55 $this->assertTrue(is_dir($path));56 }57 public function testMethodDeleteFolderWithItens()58 {59 $pathRoot = vfsStream::url('uploads');60 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');61 $folder = vfsStream::newDirectory('/foo')->at(vfsStreamWrapper::getRoot());62 $folder->addChild(vfsStream::newDirectory('files'));63 $folder->addChild(vfsStream::newFile('text.txt'));64 $path = vfsStream::url("uploads/foo");65 $this->assertTrue($storage->deleteFolder('/foo'));66 $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('foo'));67 $this->assertFalse(file_exists($path));68 }69 public function testMethodDeleteFolderNotExists()70 {71 $this->setExpectedException('NaturalWeb\FileStorage\Storage\ExceptionStorage', 'Directory foo Not found or Not Is Diretory');72 $pathRoot = vfsStream::url('uploads');73 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');74 $path = vfsStream::url("uploads/foo");75 $this->assertTrue($storage->deleteFolder('/foo'));76 }77 public function testMethodGetUrlFileExists()78 {79 $pathRoot = vfsStream::url('uploads');80 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');81 vfsStream::newFile('foo.txt')->at(vfsStreamWrapper::getRoot());82 $path = vfsStream::url("uploads/foo.txt");83 $this->assertEquals('http://localhost/foo.txt', $storage->getUrl('/foo.txt'));84 }85 public function testMethodGetUrlFileNotExists()86 {87 $pathRoot = vfsStream::url('uploads');88 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');89 $path = vfsStream::url("uploads/foo.txt");90 $this->assertEquals('', $storage->getUrl('/foo.txt'));91 }92 public function testMethodExistsTrue()93 {94 $pathRoot = vfsStream::url('uploads');95 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');96 vfsStream::newFile('foo.txt')->at(vfsStreamWrapper::getRoot());97 $this->assertTrue($storage->exists('/foo.txt'));98 }99 public function testMethodExistsFalse()100 {101 $pathRoot = vfsStream::url('uploads');102 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');103 $this->assertFalse($storage->exists('/foobar'));104 }105 public function testMethodIsFileTrue()106 {107 $pathRoot = vfsStream::url('uploads');108 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');109 vfsStream::newFile('foobar')->at(vfsStreamWrapper::getRoot());110 $this->assertTrue($storage->isFile('/foobar'));111 }112 public function testMethodIsFileFalse()113 {114 $pathRoot = vfsStream::url('uploads');115 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');116 vfsStream::newDirectory('foobar')->at(vfsStreamWrapper::getRoot());117 $this->assertFalse($storage->isFile('/foobar'));118 }119 public function testMethodIsDirTrue()120 {121 $pathRoot = vfsStream::url('uploads');122 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');123 vfsStream::newDirectory('foobar')->at(vfsStreamWrapper::getRoot());124 $this->assertTrue($storage->isDir('/foobar'));125 }126 public function testMethodIsDirFalse()127 {128 $pathRoot = vfsStream::url('uploads');129 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');130 vfsStream::newFile('foobar')->at(vfsStreamWrapper::getRoot());131 $this->assertFalse($storage->isDir('/foobar'));132 }133 public function testMethodFiles()134 {135 $pathRoot = vfsStream::url('uploads');136 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');137 $foobar = vfsStream::newDirectory('foobar')->at(vfsStreamWrapper::getRoot());138 vfsStream::newFile('logo.jpg')->at($foobar);139 vfsStream::newFile('image.jpg')->at($foobar);140 $newsfolder = vfsStream::newDirectory('newfolder')->at($foobar);141 vfsStream::newFile('other.png')->at($newsfolder);142 $newsfolder = vfsStream::newDirectory('emptyfolder')->at($foobar);143 $expecteds = array(144 $pathRoot.'/foobar/logo.jpg',145 $pathRoot.'/foobar/image.jpg',146 $pathRoot.'/foobar/newfolder/other.png',147 );148 $this->assertEquals($expecteds, $storage->files('/foobar'));149 }150 public function testMethodItemsDirectory()151 {152 $pathRoot = vfsStream::url('uploads');153 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');154 $foobar = vfsStream::newDirectory('foobar')->at(vfsStreamWrapper::getRoot());155 vfsStream::newFile('logo.jpg')->at($foobar);156 vfsStream::newFile('image.jpg')->at($foobar);157 $newsfolder = vfsStream::newDirectory('newfolder')->at($foobar);158 vfsStream::newFile('other.png')->at($newsfolder);159 $newsfolder = vfsStream::newDirectory('emptyfolder')->at($foobar);160 $expecteds = array(161 $pathRoot.'/foobar/logo.jpg',162 $pathRoot.'/foobar/image.jpg',163 $pathRoot.'/foobar/newfolder',164 $pathRoot.'/foobar/emptyfolder',165 );166 $this->assertEquals($expecteds, $storage->items('/foobar'));167 }168 public function testMethodRename()169 {170 $pathRoot = vfsStream::url('uploads');171 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');172 $foobar = vfsStream::newDirectory('foobar')->at(vfsStreamWrapper::getRoot());173 vfsStream::newFile('logo.jpg')->at($foobar);174 $pathOld = vfsStream::url("uploads/foobar");175 $pathNew = vfsStream::url("uploads/newfolder");176 $this->assertTrue(file_exists($pathOld));177 178 $this->assertTrue($storage->rename("foobar", "newfolder"));179 180 $this->assertFalse(file_exists($pathOld));181 $this->assertTrue(file_exists($pathNew));182 }183 public function testMethodCopyWithFile()184 {185 $pathRoot = vfsStream::url('uploads');186 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');187 vfsStream::newFile('logo.jpg')->at(vfsStreamWrapper::getRoot());188 $pathOld = vfsStream::url("uploads/logo.jpg");189 $pathNew = vfsStream::url("uploads/copyed.jpg");190 $this->assertTrue(file_exists($pathOld));191 192 $this->assertTrue($storage->copy("logo.jpg", "copyed.jpg"));193 194 $this->assertTrue(file_exists($pathOld));195 $this->assertTrue(file_exists($pathNew));196 }197 public function testMethodCopyWithDirectory()198 {199 $pathRoot = vfsStream::url('uploads');200 $storage = new FileSystemStorage($pathRoot, 'http://localhost/');201 $foobar = vfsStream::newDirectory('foobar')->at(vfsStreamWrapper::getRoot());202 vfsStream::newFile('logo.jpg')->at($foobar);203 $empty = vfsStream::newDirectory('empty-folder')->at($foobar);204 vfsStream::newFile('image.jpg')->at($empty);205 vfsStream::newDirectory('other-folder')->at($foobar);206 $pathOld = vfsStream::url("uploads/foobar");207 $pathNew = vfsStream::url("uploads/newfolder");208 $this->assertTrue(file_exists($pathOld));209 210 $this->assertTrue($storage->copy("foobar", "newfolder"));211 212 $this->assertTrue(file_exists($pathOld));213 $this->assertTrue(file_exists($pathNew));214 }215}...

Full Screen

Full Screen

path

Using AI Code Generation

copy

Full Screen

1$vfs = vfsStream::setup('root');2$vfs->addChild(vfsStream::newDirectory('dir1'));3$vfs->addChild(vfsStream::newDirectory('dir2'));4$vfs->addChild(vfsStream::newDirectory('dir3'));5$vfs->addChild(vfsStream::newDirectory('dir4'));6$vfs->getChild('dir1')->addChild(vfsStream::newDirectory('dir11'));7$vfs->getChild('dir1')->addChild(vfsStream::newDirectory('dir12'));8$vfs->getChild('dir1')->getChild('dir11')->addChild(vfsStream::newDirectory('dir111'));9$vfs->getChild('dir1')->getChild('dir11')->addChild(vfsStream::newDirectory('dir112'));10$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->addChild(vfsStream::newDirectory('dir1111'));11$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->addChild(vfsStream::newDirectory('dir1112'));12$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->getChild('dir1111')->addChild(vfsStream::newDirectory('dir11111'));13$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->getChild('dir1111')->addChild(vfsStream::newDirectory('dir11112'));14$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->getChild('dir1111')->getChild('dir11111')->addChild(vfsStream::newDirectory('dir111111'));15$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->getChild('dir1111')->getChild('dir11111')->addChild(vfsStream::newDirectory('dir111112'));16$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->getChild('dir1111')->getChild('dir11111')->getChild('dir111111')->addChild(vfsStream::newDirectory('dir1111111'));17$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->getChild('dir1111')->getChild('dir11111')->getChild('dir111111')->addChild(vfsStream::newDirectory('dir1111112'));18$vfs->getChild('dir1')->getChild('dir11')->getChild('dir111')->getChild('dir1111')->getChild('dir11111')->getChild('

Full Screen

Full Screen

path

Using AI Code Generation

copy

Full Screen

1$root = vfsStream::setup('root');2$dir = vfsStream::newDirectory('dir');3$root->addChild($dir);4$dir->addChild(vfsStream::newFile('file.txt')->withContent('content'));5$dir->getChild('file.txt')->url();6$root = vfsStream::setup('root');7$dir = vfsStream::newDirectory('dir');8$root->addChild($dir);9$dir->addChild(vfsStream::newFile('file.txt')->withContent('content'));10$dir->getChild('file.txt')->url();11$root = vfsStream::setup('root');12$dir = vfsStream::newDirectory('dir');13$root->addChild($dir);14$dir->addChild(vfsStream::newFile('file.txt')->withContent('content'));15$dir->getChildren();16$root = vfsStream::setup('root');17$dir = vfsStream::newDirectory('dir');18$root->addChild($dir);19$dir->addChild(vfsStream::newFile('file.txt')->withContent('content'));20$dir->hasChild('file.txt');21$root = vfsStream::setup('root');22$dir = vfsStream::newDirectory('dir');23$root->addChild($dir);24$dir->addChild(vfsStream::newFile('file.txt')->withContent('content'));25$dir->getChild('file.txt');

Full Screen

Full Screen

path

Using AI Code Generation

copy

Full Screen

1$root = vfsStream::setup('root');2$root->addChild(vfsStream::newFile('file.txt')->withContent('content of file'));3$root->addChild(vfsStream::newDirectory('subdir'));4$root->getChild('subdir')->addChild(vfsStream::newFile('subfile.txt')->withContent('content of subfile'));5$root = vfsStream::setup('root');6$root->addChild(vfsStream::newFile('file.txt')->withContent('content of file'));7$root->addChild(vfsStream::newDirectory('subdir'));8$root->getChild('subdir')->addChild(vfsStream::newFile('subfile.txt')->withContent('content of subfile'));9$root = vfsStream::setup('root');10$root->addChild(vfsStream::newFile('file.txt')->withContent('content of file'));11$root->addChild(vfsStream::newDirectory('subdir'));12$root->getChild('subdir')->addChild(vfsStream::newFile('subfile.txt')->withContent('content of subfile'));13$root = vfsStream::setup('root');14$root->addChild(vfsStream::newFile('file.txt')->withContent('content of file'));15$root->addChild(vfsStream::newDirectory('subdir'));16$root->getChild('subdir')->addChild(vfsStream::newFile('subfile.txt')->withContent('content of subfile'));17$root = vfsStream::setup('root');18$root->addChild(vfsStream::newFile('file.txt')->withContent('content of file'));19$root->addChild(vfsStream::newDirectory('subdir'));20$root->getChild('subdir')->addChild(vfsStream::newFile('subfile.txt')->withContent('content of subfile'));21$root = vfsStream::setup('root');22$root->addChild(vfsStream::newFile('file.txt')->withContent('content of file'));23$root->addChild(vfsStream::newDirectory('sub

Full Screen

Full Screen

path

Using AI Code Generation

copy

Full Screen

1$root = vfsStreamWrapper::getRoot();2$path = vfsStream::url('root/subdir/file.txt');3$root->getChild('subdir')->getChild('file.txt')->getContent();4$root = vfsStreamWrapper::getRoot();5$path = vfsStream::url('root/subdir/file.txt');6$root->getChild('subdir')->getChild('file.txt')->getContent();7$root = vfsStreamWrapper::getRoot();8$path = vfsStream::url('root/subdir/file.txt');9$root->getChild('subdir')->getChild('file.txt')->getContent();10$root = vfsStreamWrapper::getRoot();11$path = vfsStream::url('root/subdir/file.txt');12$root->getChild('subdir')->getChild('file.txt')->getContent();13$root = vfsStreamWrapper::getRoot();14$path = vfsStream::url('root/subdir/file.txt');15$root->getChild('subdir')->getChild('file.txt')->getContent();16$root = vfsStreamWrapper::getRoot();17$path = vfsStream::url('root/subdir/file.txt');18$root->getChild('subdir')->getChild('file.txt')->getContent();19$root = vfsStreamWrapper::getRoot();20$path = vfsStream::url('root/subdir/file.txt');21$root->getChild('subdir')->getChild('file.txt')->getContent();22$root = vfsStreamWrapper::getRoot();23$path = vfsStream::url('root/subdir/file.txt');24$root->getChild('subdir')->getChild('file.txt')->getContent();25$root = vfsStreamWrapper::getRoot();26$path = vfsStream::url('root/subdir/file.txt');27$root->getChild('subdir')->getChild('file.txt')->getContent();

Full Screen

Full Screen

path

Using AI Code Generation

copy

Full Screen

1require_once 'vfsStream/vfsStream.php';2vfsStreamWrapper::register();3vfsStreamWrapper::setRoot(new vfsStreamDirectory('test'));4vfsStream::newFile('test.txt')->at(vfsStreamWrapper::getRoot());5vfsStream::newFile('test1.txt')->at(vfsStreamWrapper::getRoot());6vfsStream::newFile('test2.txt')->at(vfsStreamWrapper::getRoot());7vfsStream::newFile('test3.txt')->at(vfsStreamWrapper::getRoot());8vfsStream::newFile('test4.txt')->at(vfsStreamWrapper::getRoot());9vfsStream::newFile('test5.txt')->at(vfsStreamWrapper::getRoot());10vfsStream::newFile('test6.txt')->at(vfsStreamWrapper::getRoot());11vfsStream::newFile('test7.txt')->at(vfsStreamWrapper::getRoot());12vfsStream::newFile('test8.txt')->at(vfsStreamWrapper::getRoot());13vfsStream::newFile('test9.txt')->at(vfsStreamWrapper::getRoot());14vfsStream::newFile('test10.txt')->at(vfsStreamWrapper::getRoot());15vfsStream::newFile('test11.txt')->at(vfsStreamWrapper::getRoot());16vfsStream::newFile('test12.txt')->at(vfsStreamWrapper::getRoot());17vfsStream::newFile('test13.txt')->at(vfsStreamWrapper::getRoot());18vfsStream::newFile('test14.txt')->at(vfsStreamWrapper::getRoot());19vfsStream::newFile('test15.txt')->at(vfsStreamWrapper::getRoot());20vfsStream::newFile('test16.txt')->at(vfsStreamWrapper::getRoot());

Full Screen

Full Screen

path

Using AI Code Generation

copy

Full Screen

1$vfs = vfsStream::setup('exampleDir');2$dir = vfsStream::url('exampleDir');3$dir = str_replace('\\', '/', $dir);4$dir = str_replace('C:/', '', $dir);5$dir = str_replace('D:/', '', $dir);6$dir = str_replace('E:/', '', $dir);7$dir = str_replace('F:/', '', $dir);8$dir = str_replace('G:/', '', $dir);9$dir = str_replace('H:/', '', $dir);10$dir = str_replace('I:/', '', $dir);11$dir = str_replace('J:/', '', $dir);12$dir = str_replace('K:/', '', $dir);13$dir = str_replace('L:/', '', $dir);14$dir = str_replace('M:/', '', $dir);15$dir = str_replace('N:/', '', $dir);16$dir = str_replace('O:/', '', $dir);17$dir = str_replace('P:/', '', $dir);18$dir = str_replace('Q:/', '', $dir);19$dir = str_replace('R:/', '', $dir);20$dir = str_replace('S:/', '', $dir);21$dir = str_replace('T:/', '', $dir);22$dir = str_replace('U:/', '', $dir);23$dir = str_replace('V:/', '', $dir);24$dir = str_replace('W:/', '', $dir);25$dir = str_replace('X:/', '', $dir);26$dir = str_replace('Y:/', '', $dir);27$dir = str_replace('Z:/', '',

Full Screen

Full Screen

path

Using AI Code Generation

copy

Full Screen

1$root->path('test.txt')->lastChild()->setContent('This is a test file');2$root->path('test.txt')->lastChild()->chown('root');3$root->path('test.txt')->lastChild()->chgrp('root');4$root->path('test.txt')->lastChild()->chmod(0777);5$root->path('test.txt')->lastChild()->rename('test1.txt');6$root->path('test1.txt')->lastChild()->copy('test2.txt');7$root->path('test2.txt')->lastChild()->symlink('test3.txt');8$root->path('test3.txt')->lastChild()->touch();9$root->path('test3.txt')->lastChild()->unlink();10$root->path('test3.txt')->lastChild()->delete();11$root->path('test')->lastChild()->chown('root');12$root->path('test')->lastChild()->chgrp('root');13$root->path('test')->lastChild()->chmod(0777);14$root->path('test')->lastChild()->rename('test1');15$root->path('test1')->lastChild()->copy('test2');16$root->path('

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run VfsStream automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger path code on LambdaTest Cloud Grid

Execute automation tests with path on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful