pax_global_header00006660000000000000000000000064135563262640014526gustar00rootroot0000000000000052 comment=231c73783ebb7dd9ec77916c10037eff5a2b6efe vfsStream-1.6.8/000077500000000000000000000000001355632626400135145ustar00rootroot00000000000000vfsStream-1.6.8/CHANGELOG.md000066400000000000000000000233231355632626400153300ustar00rootroot000000000000001.6.8 (2019-10-30) ------------------ * Fix `StringBasedFileContent::doRead` to always return a string (#204) 1.6.7 (2019-07-31) ------------------ * fix PHP 7.4 deprecation warnings (backported #189 from master) 1.6.6 (2019-04-08) ------------------ * backported #174 from master, original PR provided by @localheinz 1.6.5 (2017-08-01) ------------------ * fixed #157 seeking before beginning of file should fail, reported and fixed by @merijnvdk * structure array in `vfsStream::create()` and `vfsStream::setup()` now can contain instances of `org\bovigo\vfs\content\FileContent` and `org\bovigo\vfs\vfsStreamFile`, patch provivded by Joshua Smith (@jsmitty12) 1.6.4 (2016-07-18) ------------------ * fixed #134 type safe directory names, reported and fixed by Sebastian Hopfe 1.6.3 (2016-04-09) ------------------ * fixed #131 recursive mkdir() fails if the last dirname is '0' 1.6.2 (2016-01-13) ------------------ * fixed #128 duplicate "valid" files/directories and incorrect file names 1.6.1 (2015-12-04) ------------------ * `vfsStream::url()` didn't urlencode single path parts while `vfsStream::path()` did urldecode them * fixed #120, #122: create directory with trailing slash results in "Uninitialized string offset: 0" 1.6.0 (2015-10-06) ------------------ * added `vfsStreamWrapper::unregister()`, provided by @malkusch with #114 * fixed #115: incorrect handling of `..` in root directory on PHP 5.5, fix provided by @acoulton with #116 1.5.0 (2015-03-29) ------------------ * implemented #91: `vfsStream::copyFromFileSystem()` should create large file instances * implemented #92: `vfsStream::copyFromFileSystem()` should respect block devices * fixed #107: `touch()` does not respect file permissions * fixed #105: vfs directory structure is not reset after each test * fixed #104: vfsStream can't handle url encoded pathes 1.4.0 (2014-09-14) ------------------ * implemented #85: Added support for emulating block devices in the virtual filesystem, feature provided by Harris Borawski * fixed #68: Unlink a non-existing file now triggers a PHP warning 1.3.0 (2014-07-21) ------------------ * implemented #79: possibility to mock large files without large memory footprint, see https://github.com/mikey179/vfsStream/wiki/MockingLargeFiles * implemented #67: added partial support for text-mode translation flag (i.e., no actual translation of line endings takes place) so it no longer throws an exception (provided by Anthon Pang) * fixed issue #74: issue with trailing windows path separators (provided by Sebastian Krüger) * fixed issue #50: difference between real file system and vfs with `RecursiveDirectoryIterator` * fixed issue #80: touch with no arguments for modification and access time behave incorrect * deprecated `org\bovigo\vfs\vfsStreamFile::readUntilEnd()` * deprecated `org\bovigo\vfs\vfsStreamFile::getBytesRead()` 1.2.0 (2013-04-01) ------------------ * implemented issue #34: provide `url()` method on all `vfsStreamContent` instances * added `org\bovigo\vfs\vfsStreamContent::url()` * added `org\bovigo\vfs\vfsStreamContent::path()` * fixed issue #40: flock implementation doesn't work correctly, patch provided by Kamil Dziedzic * fixed issue #49: call to member function on a non-object when trying to delete a file one above root where a file with same name in root exists * fixed issue #51: `unlink()` must consider permissions of directory where file is inside, not of the file to unlink itself * fixed issue #52: `chmod()`, `chown()` and `chgrp()` must consider permissions of directory where file/directory is inside * fixed issue #53: `chmod()`, `chown()` and `chgrp()` must consider current user and current owner of file/directoy to change 1.1.0 (2012-08-25) ------------------ * implemented issue #11: add support for `streamWrapper::stream_metadata()` vfsStream now supports `touch()`, `chown()`, `chgrp()` and `chmod()` * implemented issue #33: add support for `stream_truncate()` (provided by https://github.com/nikcorg) * implemented issue #35: size limit (quota) for VFS 1.0.0 (2012-05-15) ------------------ * raised requirement for PHP version to 5.3.0 * migrated codebase to use namespaces * changed distribution from PEAR to Composer * implemented issue #30: support "c" mode for `fopen()` * fixed issue #31: prohibit aquiring locks when already locked / release lock on `fclose()` * fixed issue #32: problems when subfolder has same name as folder * fixed issue #36: `vfsStreamWrapper::stream_open()` should return false while trying to open existing non-writable file, patch provided by Alexander Peresypkin 0.11.2 (2012-01-14) ------------------- * fixed issue #29: set permissions properly when using `vfsStream::copyFromFileSystem()`, patch provided by predakanga * fixed failing tests under PHP > 5.3.2 0.11.1 (2011-12-04) ------------------- * fixed issue #28: `mkdir()` overwrites existing directories/files 0.11.0 (2011-11-29) ------------------- * implemented issue #20: `vfsStream::create()` removes old structure * implemented issue #4: possibility to copy structure from existing file system * fixed issue #23: `unlink()` should not remove any directory * fixed issue #25: `vfsStreamDirectory::hasChild()` gives false positives for nested paths, patch provided by Andrew Coulton * fixed issue #26: opening a file for reading only should not update its modification time, reported and initial patch provided by Ludovic Chabant 0.10.1 (2011-08-22) ------------------- * fixed issue #16: replace `vfsStreamContent` to `vfsStreamContainer` for autocompletion * fixed issue #17: `vfsStream::create()` has issues with numeric directories, patch provided by mathieuk 0.10.0 (2011-07-22) ------------------- * added new method `vfsStreamContainer::hasChildren()` and `vfsStreamDirectory::hasChildren()` * implemented issue #14: less verbose way to initialize vfsStream * implemented issue #13: remove deprecated method `vfsStreamContent::setFilemtime()` * implemented issue #6: locking meachanism for files * ensured that `stream_set_blocking()`, `stream_set_timeout()` and `stream_set_write_buffer()` on vfsStream urls have the same behaviour with PHP 5.2 and 5.3 * implemented issue #10: method to print directory structure 0.9.0 (2011-07-13) ------------------ * implemented feature request issue #7: add support for `fileatime()` and `filectime()` * fixed issue #3: add support for `streamWrapper::stream_cast()` * fixed issue #9: resolve path not called everywhere its needed * deprecated `vfsStreamAbstractContent::setFilemtime()`, use `vfsStreamAbstractContent::lastModified()` instead, will be removed with 0.10.0 0.8.0 (2010-10-08) ------------------ * implemented enhancement #6: use `vfsStream::umask()` to influence initial file mode for files and directories * implemented enhancement #19: support of .. in the url, patch provided by Guislain Duthieuw * fixed issue #18: `getChild()` returns NULL when child's name contains parent name * fixed bug with incomplete error message when accessing non-existing files on root level 0.7.0 (2010-06-08) ------------------ * added new `vfsStream::setup()` method to simplify vfsStream usage * fixed issue #15: `mkdir()` creates a subfolder in a folder without permissions 0.6.0 (2010-02-15) ------------------ * added support for `$mode` param when opening files, implements enhancement #7 and fixes issue #13 * `vfsStreamWrapper::stream_open()` now evaluates `$options` for `STREAM_REPORT_ERRORS` 0.5.0 (2010-01-25) ------------------ * added support for `rename()`, patch provided by Benoit Aubuchon * added support for . as directory alias so that `vfs://foo/.` resolves to `vfs://foo`, can be used as workaround for bug #8 0.4.0 (2009-07-13) ------------------ * added support for file modes, users and groups (with restrictions, see http://code.google.com/p/bovigo/wiki/vfsStreamDocsKnownIssues) * fixed bug #5: `vfsStreamDirectory::addChild()` does not replace child with same name * fixed bug with `is_writable()` because of missing `stat()` fields, patch provided by Sergey Galkin 0.3.2 (2009-02-16) ------------------ * support trailing slashes on directories in vfsStream urls, patch provided by Gabriel Birke * fixed bug #4: vfsstream can only be read once, reported by Christoph Bloemer * enabled multiple iterations at the same time over the same directory 0.3.1 (2008-02-18) ------------------ * fixed path/directory separator issues under linux systems * fixed uid/gid issues under linux systems 0.3.0 (2008-01-02) ------------------ * added support for `rmdir()` * added `vfsStream::newDirectory()`, dropped `vfsStreamDirectory::ceate()` * added new interface `vfsStreamContainer` * added `vfsStreamContent::at()` which allows code like `$file = vfsStream::newFile('file.txt.')->withContent('foo')->at($otherDir);` * added `vfsStreamContent::lastModified()`, made `vfsStreamContent::setFilemtime()` an alias for this * moved from Stubbles development environment to bovigo * refactorings to reduce crap index of various methods 0.2.0 (2007-12-29) ------------------ * moved `vfsStreamWrapper::PROTOCOL` to `vfsStream::SCHEME` * added new `vfsStream::url()` method to assist in creating correct vfsStream urls * added `vfsStream::path()` method as opposite to `vfsStream::url()` * a call to `vfsStreamWrapper::register()` will now reset the root to null, implemented on request from David Zuelke * added support for `is_readable()`, `is_dir()`, `is_file()` * added `vfsStream::newFile()` to be able to do `$file = vfsStream::newFile("foo.txt")->withContent("bar");` 0.1.0 (2007-12-14) ------------------ * Initial release. vfsStream-1.6.8/LICENSE000066400000000000000000000027101355632626400145210ustar00rootroot00000000000000Copyright (c) 2007-2015, Frank Kleine All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Stubbles nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. vfsStream-1.6.8/README.md000066400000000000000000000015621355632626400147770ustar00rootroot00000000000000You can find documentation in the [wiki](https://github.com/mikey179/vfsStream/wiki). Also you might want to check [vfsStream examples](https://github.com/mikey179/vfsStream-examples). [![Build Status](https://secure.travis-ci.org/mikey179/vfsStream.png)](http://travis-ci.org/mikey179/vfsStream) [![Build Status Windows](https://ci.appveyor.com/api/projects/status/6whqgluyeggspjp1/branch/master?svg=true)](https://ci.appveyor.com/project/mikey179/vfsstream) [![Coverage Status](https://coveralls.io/repos/github/bovigo/vfsStream/badge.svg?branch=v1.x)](https://coveralls.io/github/bovigo/vfsStream?branch=v1.x) [![Latest Stable Version](https://poser.pugx.org/mikey179/vfsStream/version.png)](https://packagist.org/packages/mikey179/vfsStream) [![Latest Unstable Version](https://poser.pugx.org/mikey179/vfsStream/v/unstable.png)](//packagist.org/packages/mikey179/vfsStream) vfsStream-1.6.8/appveyor.yml000066400000000000000000000012621355632626400161050ustar00rootroot00000000000000build: false shallow_clone: true cache: - .\php -> appveyor.yml init: - set PATH=%PATH%;.\php - set COMPOSER_NO_INTERACTION=1 - set CACHED=0 install: - if exist .\php (set CACHED=1) else (mkdir .\php) - if %CACHED%==0 cd .\php - if %CACHED%==0 curl --fail --location --silent --show-error -o php.zip https://windows.php.net/downloads/releases/archives/php-7.0.7-nts-Win32-VC14-x64.zip - if %CACHED%==0 appveyor DownloadFile https://getcomposer.org/composer.phar - if %CACHED%==0 7z x php.zip -y - if %CACHED%==0 cd .. test_script: - php -d extension_dir=.\php\ext -d extension=php_openssl.dll .\php\composer.phar install - vendor/bin/phpunit.bat --coverage-text vfsStream-1.6.8/composer.json000066400000000000000000000015741355632626400162450ustar00rootroot00000000000000{ "name": "mikey179/vfsstream", "type": "library", "homepage": "http://vfs.bovigo.org/", "description": "Virtual file system to mock the real file system in unit tests.", "license": "BSD-3-Clause", "authors": [ { "name": "Frank Kleine", "homepage": "http://frankkleine.de/", "role": "Developer" } ], "support": { "issues": "https://github.com/bovigo/vfsStream/issues", "source": "https://github.com/bovigo/vfsStream/tree/master", "wiki": "https://github.com/bovigo/vfsStream/wiki" }, "require": { "php": ">=5.3.0" }, "require-dev": { "phpunit/phpunit": "^4.5|^5.0" }, "autoload": { "psr-0": { "org\\bovigo\\vfs\\": "src/main/php" } }, "extra": { "branch-alias": { "dev-master": "1.6.x-dev" } } } vfsStream-1.6.8/phpunit.xml.dist000066400000000000000000000026751355632626400167010ustar00rootroot00000000000000 ./src/test/phpt ./src/test/php src/main/php vfsStream-1.6.8/src/000077500000000000000000000000001355632626400143035ustar00rootroot00000000000000vfsStream-1.6.8/src/main/000077500000000000000000000000001355632626400152275ustar00rootroot00000000000000vfsStream-1.6.8/src/main/php/000077500000000000000000000000001355632626400160165ustar00rootroot00000000000000vfsStream-1.6.8/src/main/php/org/000077500000000000000000000000001355632626400166055ustar00rootroot00000000000000vfsStream-1.6.8/src/main/php/org/bovigo/000077500000000000000000000000001355632626400200725ustar00rootroot00000000000000vfsStream-1.6.8/src/main/php/org/bovigo/vfs/000077500000000000000000000000001355632626400206705ustar00rootroot00000000000000vfsStream-1.6.8/src/main/php/org/bovigo/vfs/DotDirectory.php000066400000000000000000000012241355632626400240130ustar00rootroot00000000000000amount = $amount; } /** * create with unlimited space * * @return Quota */ public static function unlimited() { return new self(self::UNLIMITED); } /** * checks if a quota is set * * @return bool */ public function isLimited() { return self::UNLIMITED < $this->amount; } /** * checks if given used space exceeda quota limit * * * @param int $usedSpace * @return int */ public function spaceLeft($usedSpace) { if (self::UNLIMITED === $this->amount) { return $usedSpace; } if ($usedSpace >= $this->amount) { return 0; } $spaceLeft = $this->amount - $usedSpace; if (0 >= $spaceLeft) { return 0; } return $spaceLeft; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/content/000077500000000000000000000000001355632626400223425ustar00rootroot00000000000000vfsStream-1.6.8/src/main/php/org/bovigo/vfs/content/FileContent.php000066400000000000000000000025071355632626400252710ustar00rootroot00000000000000size = $size; } /** * create large file with given size in kilobyte * * @param int $kilobyte * @return LargeFileContent */ public static function withKilobytes($kilobyte) { return new self($kilobyte * 1024); } /** * create large file with given size in megabyte * * @param int $megabyte * @return LargeFileContent */ public static function withMegabytes($megabyte) { return self::withKilobytes($megabyte * 1024); } /** * create large file with given size in gigabyte * * @param int $gigabyte * @return LargeFileContent */ public static function withGigabytes($gigabyte) { return self::withMegabytes($gigabyte * 1024); } /** * returns actual content * * @return string */ public function content() { return $this->doRead(0, $this->size); } /** * returns size of content * * @return int */ public function size() { return $this->size; } /** * actual reading of given byte count starting at given offset * * @param int $offset * @param int $count */ protected function doRead($offset, $count) { if (($offset + $count) > $this->size) { $count = $this->size - $offset; } $result = ''; for ($i = 0; $i < $count; $i++) { if (isset($this->content[$i + $offset])) { $result .= $this->content[$i + $offset]; } else { $result .= ' '; } } return $result; } /** * actual writing of data with specified length at given offset * * @param string $data * @param int $offset * @param int $length */ protected function doWrite($data, $offset, $length) { for ($i = 0; $i < $length; $i++) { $this->content[$i + $offset] = substr($data, $i, 1); } if ($offset >= $this->size) { $this->size += $length; } elseif (($offset + $length) > $this->size) { $this->size = $offset + $length; } } /** * Truncates a file to a given length * * @param int $size length to truncate file to * @return bool */ public function truncate($size) { $this->size = $size; foreach (array_filter(array_keys($this->content), function($pos) use ($size) { return $pos >= $size; } ) as $removePos) { unset($this->content[$removePos]); } return true; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/content/SeekableFileContent.php000066400000000000000000000055671355632626400267360ustar00rootroot00000000000000doRead($this->offset, $count); $this->offset += $count; return $data; } /** * actual reading of given byte count starting at given offset * * @param int $offset * @param int $count */ protected abstract function doRead($offset, $count); /** * seeks to the given offset * * @param int $offset * @param int $whence * @return bool */ public function seek($offset, $whence) { $newOffset = $this->offset; switch ($whence) { case SEEK_CUR: $newOffset += $offset; break; case SEEK_END: $newOffset = $this->size() + $offset; break; case SEEK_SET: $newOffset = $offset; break; default: return false; } if ($newOffset<0) { return false; } $this->offset = $newOffset; return true; } /** * checks whether pointer is at end of file * * @return bool */ public function eof() { return $this->size() <= $this->offset; } /** * writes an amount of data * * @param string $data * @return amount of written bytes */ public function write($data) { $dataLength = strlen($data); $this->doWrite($data, $this->offset, $dataLength); $this->offset += $dataLength; return $dataLength; } /** * actual writing of data with specified length at given offset * * @param string $data * @param int $offset * @param int $length */ protected abstract function doWrite($data, $offset, $length); /** * for backwards compatibility with vfsStreamFile::bytesRead() * * @return int * @deprecated */ public function bytesRead() { return $this->offset; } /** * for backwards compatibility with vfsStreamFile::readUntilEnd() * * @return string * @deprecated */ public function readUntilEnd() { return substr($this->content(), $this->offset); } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/content/StringBasedFileContent.php000066400000000000000000000041121355632626400274110ustar00rootroot00000000000000content = $content; } /** * returns actual content * * @return string */ public function content() { return $this->content; } /** * returns size of content * * @return int */ public function size() { return strlen($this->content); } /** * actual reading of length starting at given offset * * @param int $offset * @param int $count */ protected function doRead($offset, $count) { return (string) substr($this->content, $offset, $count); } /** * actual writing of data with specified length at given offset * * @param string $data * @param int $offset * @param int $length */ protected function doWrite($data, $offset, $length) { $this->content = substr($this->content, 0, $offset) . $data . substr($this->content, $offset + $length); } /** * Truncates a file to a given length * * @param int $size length to truncate file to * @return bool */ public function truncate($size) { if ($size > $this->size()) { // Pad with null-chars if we're "truncating up" $this->content .= str_repeat("\0", $size - $this->size()); } else { $this->content = substr($this->content, 0, $size); } return true; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/vfsStream.php000066400000000000000000000364301355632626400233610ustar00rootroot00000000000000 * array('Core' = array('AbstractFactory' => array('test.php' => 'some text content', * 'other.php' => 'Some more text content', * 'Invalid.csv' => 'Something else', * ), * 'AnEmptyFolder' => array(), * 'badlocation.php' => 'some bad content', * ) * ) * * the resulting directory tree will look like this: *
     * root
     * \- Core
     *  |- badlocation.php
     *  |- AbstractFactory
     *  | |- test.php
     *  | |- other.php
     *  | \- Invalid.csv
     *  \- AnEmptyFolder
     * 
* Arrays will become directories with their key as directory name, and * strings becomes files with their key as file name and their value as file * content. * * @param string $rootDirName name of root directory * @param int $permissions file permissions of root directory * @param array $structure directory structure to add under root directory * @return \org\bovigo\vfs\vfsStreamDirectory * @since 0.7.0 * @see https://github.com/mikey179/vfsStream/issues/14 * @see https://github.com/mikey179/vfsStream/issues/20 */ public static function setup($rootDirName = 'root', $permissions = null, array $structure = array()) { vfsStreamWrapper::register(); return self::create($structure, vfsStreamWrapper::setRoot(self::newDirectory($rootDirName, $permissions))); } /** * creates vfsStream directory structure from an array and adds it to given base dir * * Assumed $structure contains an array like this: * * array('Core' = array('AbstractFactory' => array('test.php' => 'some text content', * 'other.php' => 'Some more text content', * 'Invalid.csv' => 'Something else', * ), * 'AnEmptyFolder' => array(), * 'badlocation.php' => 'some bad content', * ) * ) * * the resulting directory tree will look like this: *
     * baseDir
     * \- Core
     *  |- badlocation.php
     *  |- AbstractFactory
     *  | |- test.php
     *  | |- other.php
     *  | \- Invalid.csv
     *  \- AnEmptyFolder
     * 
* Arrays will become directories with their key as directory name, and * strings becomes files with their key as file name and their value as file * content. * * If no baseDir is given it will try to add the structure to the existing * root directory without replacing existing childs except those with equal * names. * * @param array $structure directory structure to add under root directory * @param vfsStreamDirectory $baseDir base directory to add structure to * @return vfsStreamDirectory * @throws \InvalidArgumentException * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/14 * @see https://github.com/mikey179/vfsStream/issues/20 */ public static function create(array $structure, vfsStreamDirectory $baseDir = null) { if (null === $baseDir) { $baseDir = vfsStreamWrapper::getRoot(); } if (null === $baseDir) { throw new \InvalidArgumentException('No baseDir given and no root directory set.'); } return self::addStructure($structure, $baseDir); } /** * helper method to create subdirectories recursively * * @param array $structure subdirectory structure to add * @param vfsStreamDirectory $baseDir directory to add the structure to * @return vfsStreamDirectory */ protected static function addStructure(array $structure, vfsStreamDirectory $baseDir) { foreach ($structure as $name => $data) { $name = (string) $name; if (is_array($data) === true) { self::addStructure($data, self::newDirectory($name)->at($baseDir)); } elseif (is_string($data) === true) { $matches = null; preg_match('/^\[(.*)\]$/', $name, $matches); if ($matches !== array()) { self::newBlock($matches[1])->withContent($data)->at($baseDir); } else { self::newFile($name)->withContent($data)->at($baseDir); } } elseif ($data instanceof FileContent) { self::newFile($name)->withContent($data)->at($baseDir); } elseif ($data instanceof vfsStreamFile) { $baseDir->addChild($data); } } return $baseDir; } /** * copies the file system structure from given path into the base dir * * If no baseDir is given it will try to add the structure to the existing * root directory without replacing existing childs except those with equal * names. * File permissions are copied as well. * Please note that file contents will only be copied if their file size * does not exceed the given $maxFileSize which defaults to 1024 KB. In case * the file is larger file content will be mocked, see * https://github.com/mikey179/vfsStream/wiki/MockingLargeFiles. * * @param string $path path to copy the structure from * @param vfsStreamDirectory $baseDir directory to add the structure to * @param int $maxFileSize maximum file size of files to copy content from * @return vfsStreamDirectory * @throws \InvalidArgumentException * @since 0.11.0 * @see https://github.com/mikey179/vfsStream/issues/4 */ public static function copyFromFileSystem($path, vfsStreamDirectory $baseDir = null, $maxFileSize = 1048576) { if (null === $baseDir) { $baseDir = vfsStreamWrapper::getRoot(); } if (null === $baseDir) { throw new \InvalidArgumentException('No baseDir given and no root directory set.'); } $dir = new \DirectoryIterator($path); foreach ($dir as $fileinfo) { switch (filetype($fileinfo->getPathname())) { case 'file': if ($fileinfo->getSize() <= $maxFileSize) { $content = file_get_contents($fileinfo->getPathname()); } else { $content = new LargeFileContent($fileinfo->getSize()); } self::newFile( $fileinfo->getFilename(), octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)) ) ->withContent($content) ->at($baseDir); break; case 'dir': if (!$fileinfo->isDot()) { self::copyFromFileSystem( $fileinfo->getPathname(), self::newDirectory( $fileinfo->getFilename(), octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)) )->at($baseDir), $maxFileSize ); } break; case 'block': self::newBlock( $fileinfo->getFilename(), octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)) )->at($baseDir); break; } } return $baseDir; } /** * returns a new file with given name * * @param string $name name of file to create * @param int $permissions permissions of file to create * @return vfsStreamFile */ public static function newFile($name, $permissions = null) { return new vfsStreamFile($name, $permissions); } /** * returns a new directory with given name * * If the name contains slashes, a new directory structure will be created. * The returned directory will always be the parent directory of this * directory structure. * * @param string $name name of directory to create * @param int $permissions permissions of directory to create * @return vfsStreamDirectory */ public static function newDirectory($name, $permissions = null) { if ('/' === substr($name, 0, 1)) { $name = substr($name, 1); } $firstSlash = strpos($name, '/'); if (false === $firstSlash) { return new vfsStreamDirectory($name, $permissions); } $ownName = substr($name, 0, $firstSlash); $subDirs = substr($name, $firstSlash + 1); $directory = new vfsStreamDirectory($ownName, $permissions); if (is_string($subDirs) && strlen($subDirs) > 0) { self::newDirectory($subDirs, $permissions)->at($directory); } return $directory; } /** * returns a new block with the given name * * @param string $name name of the block device * @param int $permissions permissions of block to create * @return vfsStreamBlock */ public static function newBlock($name, $permissions = null) { return new vfsStreamBlock($name, $permissions); } /** * returns current user * * If the system does not support posix_getuid() the current user will be root (0). * * @return int */ public static function getCurrentUser() { return function_exists('posix_getuid') ? posix_getuid() : self::OWNER_ROOT; } /** * returns current group * * If the system does not support posix_getgid() the current group will be root (0). * * @return int */ public static function getCurrentGroup() { return function_exists('posix_getgid') ? posix_getgid() : self::GROUP_ROOT; } /** * use visitor to inspect a content structure * * If the given content is null it will fall back to use the current root * directory of the stream wrapper. * * Returns given visitor for method chaining comfort. * * @param vfsStreamVisitor $visitor the visitor who inspects * @param vfsStreamContent $content directory structure to inspect * @return vfsStreamVisitor * @throws \InvalidArgumentException * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/10 */ public static function inspect(vfsStreamVisitor $visitor, vfsStreamContent $content = null) { if (null !== $content) { return $visitor->visit($content); } $root = vfsStreamWrapper::getRoot(); if (null === $root) { throw new \InvalidArgumentException('No content given and no root directory set.'); } return $visitor->visitDirectory($root); } /** * sets quota to given amount of bytes * * @param int $bytes * @since 1.1.0 */ public static function setQuota($bytes) { vfsStreamWrapper::setQuota(new Quota($bytes)); } /** * checks if vfsStream lists dotfiles in directory listings * * @return bool * @since 1.3.0 */ public static function useDotfiles() { return self::$dotFiles; } /** * disable dotfiles in directory listings * * @since 1.3.0 */ public static function disableDotfiles() { self::$dotFiles = false; } /** * enable dotfiles in directory listings * * @since 1.3.0 */ public static function enableDotfiles() { self::$dotFiles = true; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/vfsStreamAbstractContent.php000066400000000000000000000210261355632626400263730ustar00rootroot00000000000000name = "{$name}"; $time = time(); if (null === $permissions) { $permissions = $this->getDefaultPermissions() & ~vfsStream::umask(); } $this->lastAccessed = $time; $this->lastAttributeModified = $time; $this->lastModified = $time; $this->permissions = $permissions; $this->user = vfsStream::getCurrentUser(); $this->group = vfsStream::getCurrentGroup(); } /** * returns default permissions for concrete implementation * * @return int * @since 0.8.0 */ protected abstract function getDefaultPermissions(); /** * returns the file name of the content * * @return string */ public function getName() { return $this->name; } /** * renames the content * * @param string $newName */ public function rename($newName) { $this->name = "{$newName}"; } /** * checks whether the container can be applied to given name * * @param string $name * @return bool */ public function appliesTo($name) { if ($name === $this->name) { return true; } $segment_name = $this->name.'/'; return (strncmp($segment_name, $name, strlen($segment_name)) == 0); } /** * returns the type of the container * * @return int */ public function getType() { return $this->type; } /** * sets the last modification time of the stream content * * @param int $filemtime * @return $this */ public function lastModified($filemtime) { $this->lastModified = $filemtime; return $this; } /** * returns the last modification time of the stream content * * @return int */ public function filemtime() { return $this->lastModified; } /** * sets last access time of the stream content * * @param int $fileatime * @return $this * @since 0.9 */ public function lastAccessed($fileatime) { $this->lastAccessed = $fileatime; return $this; } /** * returns the last access time of the stream content * * @return int * @since 0.9 */ public function fileatime() { return $this->lastAccessed; } /** * sets the last attribute modification time of the stream content * * @param int $filectime * @return $this * @since 0.9 */ public function lastAttributeModified($filectime) { $this->lastAttributeModified = $filectime; return $this; } /** * returns the last attribute modification time of the stream content * * @return int * @since 0.9 */ public function filectime() { return $this->lastAttributeModified; } /** * adds content to given container * * @param vfsStreamContainer $container * @return $this */ public function at(vfsStreamContainer $container) { $container->addChild($this); return $this; } /** * change file mode to given permissions * * @param int $permissions * @return $this */ public function chmod($permissions) { $this->permissions = $permissions; $this->lastAttributeModified = time(); clearstatcache(); return $this; } /** * returns permissions * * @return int */ public function getPermissions() { return $this->permissions; } /** * checks whether content is readable * * @param int $user id of user to check for * @param int $group id of group to check for * @return bool */ public function isReadable($user, $group) { if ($this->user === $user) { $check = 0400; } elseif ($this->group === $group) { $check = 0040; } else { $check = 0004; } return (bool) ($this->permissions & $check); } /** * checks whether content is writable * * @param int $user id of user to check for * @param int $group id of group to check for * @return bool */ public function isWritable($user, $group) { if ($this->user === $user) { $check = 0200; } elseif ($this->group === $group) { $check = 0020; } else { $check = 0002; } return (bool) ($this->permissions & $check); } /** * checks whether content is executable * * @param int $user id of user to check for * @param int $group id of group to check for * @return bool */ public function isExecutable($user, $group) { if ($this->user === $user) { $check = 0100; } elseif ($this->group === $group) { $check = 0010; } else { $check = 0001; } return (bool) ($this->permissions & $check); } /** * change owner of file to given user * * @param int $user * @return $this */ public function chown($user) { $this->user = $user; $this->lastAttributeModified = time(); return $this; } /** * checks whether file is owned by given user * * @param int $user * @return bool */ public function isOwnedByUser($user) { return $this->user === $user; } /** * returns owner of file * * @return int */ public function getUser() { return $this->user; } /** * change owner group of file to given group * * @param int $group * @return $this */ public function chgrp($group) { $this->group = $group; $this->lastAttributeModified = time(); return $this; } /** * checks whether file is owned by group * * @param int $group * @return bool */ public function isOwnedByGroup($group) { return $this->group === $group; } /** * returns owner group of file * * @return int */ public function getGroup() { return $this->group; } /** * sets parent path * * @param string $parentPath * @internal only to be set by parent * @since 1.2.0 */ public function setParentPath($parentPath) { $this->parentPath = $parentPath; } /** * returns path to this content * * @return string * @since 1.2.0 */ public function path() { if (null === $this->parentPath) { return $this->name; } return $this->parentPath . '/' . $this->name; } /** * returns complete vfsStream url for this content * * @return string * @since 1.2.0 */ public function url() { return vfsStream::url($this->path()); } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/vfsStreamBlock.php000066400000000000000000000013311355632626400243240ustar00rootroot00000000000000type = vfsStreamContent::TYPE_BLOCK; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/vfsStreamContainer.php000066400000000000000000000025051355632626400252200ustar00rootroot00000000000000children = $children; if (vfsStream::useDotfiles()) { array_unshift($this->children, new DotDirectory('.'), new DotDirectory('..')); } reset($this->children); } /** * resets children pointer */ public function rewind() { reset($this->children); } /** * returns the current child * * @return vfsStreamContent */ public function current() { $child = current($this->children); if (false === $child) { return null; } return $child; } /** * returns the name of the current child * * @return string */ public function key() { $child = current($this->children); if (false === $child) { return null; } return $child->getName(); } /** * iterates to next child */ public function next() { next($this->children); } /** * checks if the current value is valid * * @return bool */ public function valid() { return (false !== current($this->children)); } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/vfsStreamContent.php000066400000000000000000000103301355632626400247030ustar00rootroot00000000000000type = vfsStreamContent::TYPE_DIR; parent::__construct($name, $permissions); } /** * returns default permissions for concrete implementation * * @return int * @since 0.8.0 */ protected function getDefaultPermissions() { return 0777; } /** * returns size of directory * * The size of a directory is always 0 bytes. To calculate the summarized * size of all children in the directory use sizeSummarized(). * * @return int */ public function size() { return 0; } /** * returns summarized size of directory and its children * * @return int */ public function sizeSummarized() { $size = 0; foreach ($this->children as $child) { if ($child->getType() === vfsStreamContent::TYPE_DIR) { $size += $child->sizeSummarized(); } else { $size += $child->size(); } } return $size; } /** * renames the content * * @param string $newName * @throws vfsStreamException */ public function rename($newName) { if (strstr($newName, '/') !== false) { throw new vfsStreamException('Directory name can not contain /.'); } parent::rename($newName); } /** * sets parent path * * @param string $parentPath * @internal only to be set by parent * @since 1.2.0 */ public function setParentPath($parentPath) { parent::setParentPath($parentPath); foreach ($this->children as $child) { $child->setParentPath($this->path()); } } /** * adds child to the directory * * @param vfsStreamContent $child */ public function addChild(vfsStreamContent $child) { $child->setParentPath($this->path()); $this->children[$child->getName()] = $child; $this->updateModifications(); } /** * removes child from the directory * * @param string $name * @return bool */ public function removeChild($name) { foreach ($this->children as $key => $child) { if ($child->appliesTo($name)) { $child->setParentPath(null); unset($this->children[$key]); $this->updateModifications(); return true; } } return false; } /** * updates internal timestamps */ protected function updateModifications() { $time = time(); $this->lastAttributeModified = $time; $this->lastModified = $time; } /** * checks whether the container contains a child with the given name * * @param string $name * @return bool */ public function hasChild($name) { return ($this->getChild($name) !== null); } /** * returns the child with the given name * * @param string $name * @return vfsStreamContent */ public function getChild($name) { $childName = $this->getRealChildName($name); foreach ($this->children as $child) { if ($child->getName() === $childName) { return $child; } if ($child->appliesTo($childName) === true && $child->hasChild($childName) === true) { return $child->getChild($childName); } } return null; } /** * helper method to detect the real child name * * @param string $name * @return string */ protected function getRealChildName($name) { if ($this->appliesTo($name) === true) { return self::getChildName($name, $this->name); } return $name; } /** * helper method to calculate the child name * * @param string $name * @param string $ownName * @return string */ protected static function getChildName($name, $ownName) { if ($name === $ownName) { return $name; } return substr($name, strlen($ownName) + 1); } /** * checks whether directory contains any children * * @return bool * @since 0.10.0 */ public function hasChildren() { return (count($this->children) > 0); } /** * returns a list of children for this directory * * @return vfsStreamContent[] */ public function getChildren() { return array_values($this->children); } /** * returns iterator for the children * * @return vfsStreamContainerIterator */ public function getIterator() { return new vfsStreamContainerIterator($this->children); } /** * checks whether dir is a dot dir * * @return bool */ public function isDot() { if ('.' === $this->name || '..' === $this->name) { return true; } return false; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/vfsStreamException.php000066400000000000000000000005551355632626400252370ustar00rootroot00000000000000content = new StringBasedFileContent(null); $this->type = vfsStreamContent::TYPE_FILE; parent::__construct($name, $permissions); } /** * returns default permissions for concrete implementation * * @return int * @since 0.8.0 */ protected function getDefaultPermissions() { return 0666; } /** * checks whether the container can be applied to given name * * @param string $name * @return bool */ public function appliesTo($name) { return ($name === $this->name); } /** * alias for withContent() * * @param string $content * @return vfsStreamFile * @see withContent() */ public function setContent($content) { return $this->withContent($content); } /** * sets the contents of the file * * Setting content with this method does not change the time when the file * was last modified. * * @param string]FileContent $content * @return vfsStreamFile * @throws \InvalidArgumentException */ public function withContent($content) { if (is_string($content)) { $this->content = new StringBasedFileContent($content); } elseif ($content instanceof FileContent) { $this->content = $content; } else { throw new \InvalidArgumentException('Given content must either be a string or an instance of org\bovigo\vfs\content\FileContent'); } return $this; } /** * returns the contents of the file * * Getting content does not change the time when the file * was last accessed. * * @return string */ public function getContent() { return $this->content->content(); } /** * simply open the file * * @since 0.9 */ public function open() { $this->content->seek(0, SEEK_SET); $this->lastAccessed = time(); } /** * open file and set pointer to end of file * * @since 0.9 */ public function openForAppend() { $this->content->seek(0, SEEK_END); $this->lastAccessed = time(); } /** * open file and truncate content * * @since 0.9 */ public function openWithTruncate() { $this->open(); $this->content->truncate(0); $time = time(); $this->lastAccessed = $time; $this->lastModified = $time; } /** * reads the given amount of bytes from content * * Using this method changes the time when the file was last accessed. * * @param int $count * @return string */ public function read($count) { $this->lastAccessed = time(); return $this->content->read($count); } /** * returns the content until its end from current offset * * Using this method changes the time when the file was last accessed. * * @return string * @deprecated since 1.3.0 */ public function readUntilEnd() { $this->lastAccessed = time(); return $this->content->readUntilEnd(); } /** * writes an amount of data * * Using this method changes the time when the file was last modified. * * @param string $data * @return amount of written bytes */ public function write($data) { $this->lastModified = time(); return $this->content->write($data); } /** * Truncates a file to a given length * * @param int $size length to truncate file to * @return bool * @since 1.1.0 */ public function truncate($size) { $this->content->truncate($size); $this->lastModified = time(); return true; } /** * checks whether pointer is at end of file * * @return bool */ public function eof() { return $this->content->eof(); } /** * returns the current position within the file * * @return int * @deprecated since 1.3.0 */ public function getBytesRead() { return $this->content->bytesRead(); } /** * seeks to the given offset * * @param int $offset * @param int $whence * @return bool */ public function seek($offset, $whence) { return $this->content->seek($offset, $whence); } /** * returns size of content * * @return int */ public function size() { return $this->content->size(); } /** * locks file for * * @param resource|vfsStreamWrapper $resource * @param int $operation * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 * @see https://github.com/mikey179/vfsStream/issues/40 */ public function lock($resource, $operation) { if ((LOCK_NB & $operation) == LOCK_NB) { $operation = $operation - LOCK_NB; } // call to lock file on the same file handler firstly releases the lock $this->unlock($resource); if (LOCK_EX === $operation) { if ($this->isLocked()) { return false; } $this->setExclusiveLock($resource); } elseif(LOCK_SH === $operation) { if ($this->hasExclusiveLock()) { return false; } $this->addSharedLock($resource); } return true; } /** * Removes lock from file acquired by given resource * * @param resource|vfsStreamWrapper $resource * @see https://github.com/mikey179/vfsStream/issues/40 */ public function unlock($resource) { if ($this->hasExclusiveLock($resource)) { $this->exclusiveLock = null; } if ($this->hasSharedLock($resource)) { unset($this->sharedLock[$this->getResourceId($resource)]); } } /** * Set exlusive lock on file by given resource * * @param resource|vfsStreamWrapper $resource * @see https://github.com/mikey179/vfsStream/issues/40 */ protected function setExclusiveLock($resource) { $this->exclusiveLock = $this->getResourceId($resource); } /** * Add shared lock on file by given resource * * @param resource|vfsStreamWrapper $resource * @see https://github.com/mikey179/vfsStream/issues/40 */ protected function addSharedLock($resource) { $this->sharedLock[$this->getResourceId($resource)] = true; } /** * checks whether file is locked * * @param resource|vfsStreamWrapper $resource * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 * @see https://github.com/mikey179/vfsStream/issues/40 */ public function isLocked($resource = null) { return $this->hasSharedLock($resource) || $this->hasExclusiveLock($resource); } /** * checks whether file is locked in shared mode * * @param resource|vfsStreamWrapper $resource * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 * @see https://github.com/mikey179/vfsStream/issues/40 */ public function hasSharedLock($resource = null) { if (null !== $resource) { return isset($this->sharedLock[$this->getResourceId($resource)]); } return !empty($this->sharedLock); } /** * Returns unique resource id * * @param resource|vfsStreamWrapper $resource * @return string * @see https://github.com/mikey179/vfsStream/issues/40 */ public function getResourceId($resource) { if (is_resource($resource)) { $data = stream_get_meta_data($resource); $resource = $data['wrapper_data']; } return spl_object_hash($resource); } /** * checks whether file is locked in exclusive mode * * @param resource|vfsStreamWrapper $resource * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 * @see https://github.com/mikey179/vfsStream/issues/40 */ public function hasExclusiveLock($resource = null) { if (null !== $resource) { return $this->exclusiveLock === $this->getResourceId($resource); } return null !== $this->exclusiveLock; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php000066400000000000000000000714031355632626400247210ustar00rootroot00000000000000getName() === $path) { return self::$root; } if ($this->isInRoot($path) && self::$root->hasChild($path) === true) { return self::$root->getChild($path); } return null; } /** * helper method to detect whether given path is in root path * * @param string $path * @return bool */ private function isInRoot($path) { return substr($path, 0, strlen(self::$root->getName())) === self::$root->getName(); } /** * returns content for given path but only when it is of given type * * @param string $path * @param int $type * @return vfsStreamContent */ protected function getContentOfType($path, $type) { $content = $this->getContent($path); if (null !== $content && $content->getType() === $type) { return $content; } return null; } /** * splits path into its dirname and the basename * * @param string $path * @return string[] */ protected function splitPath($path) { $lastSlashPos = strrpos($path, '/'); if (false === $lastSlashPos) { return array('dirname' => '', 'basename' => $path); } return array('dirname' => substr($path, 0, $lastSlashPos), 'basename' => substr($path, $lastSlashPos + 1) ); } /** * helper method to resolve a path from /foo/bar/. to /foo/bar * * @param string $path * @return string */ protected function resolvePath($path) { $newPath = array(); foreach (explode('/', $path) as $pathPart) { if ('.' !== $pathPart) { if ('..' !== $pathPart) { $newPath[] = $pathPart; } elseif (count($newPath) > 1) { array_pop($newPath); } } } return implode('/', $newPath); } /** * open the stream * * @param string $path the path to open * @param string $mode mode for opening * @param string $options options for opening * @param string $opened_path full path that was actually opened * @return bool */ public function stream_open($path, $mode, $options, $opened_path) { $extended = ((strstr($mode, '+') !== false) ? (true) : (false)); $mode = str_replace(array('t', 'b', '+'), '', $mode); if (in_array($mode, array('r', 'w', 'a', 'x', 'c')) === false) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Illegal mode ' . $mode . ', use r, w, a, x or c, flavoured with t, b and/or +', E_USER_WARNING); } return false; } $this->mode = $this->calculateMode($mode, $extended); $path = $this->resolvePath(vfsStream::path($path)); $this->content = $this->getContentOfType($path, vfsStreamContent::TYPE_FILE); if (null !== $this->content) { if (self::WRITE === $mode) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('File ' . $path . ' already exists, can not open with mode x', E_USER_WARNING); } return false; } if ( (self::TRUNCATE === $mode || self::APPEND === $mode) && $this->content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false ) { return false; } if (self::TRUNCATE === $mode) { $this->content->openWithTruncate(); } elseif (self::APPEND === $mode) { $this->content->openForAppend(); } else { if (!$this->content->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Permission denied', E_USER_WARNING); } return false; } $this->content->open(); } return true; } $content = $this->createFile($path, $mode, $options); if (false === $content) { return false; } $this->content = $content; return true; } /** * creates a file at given path * * @param string $path the path to open * @param string $mode mode for opening * @param string $options options for opening * @return bool */ private function createFile($path, $mode = null, $options = null) { $names = $this->splitPath($path); if (empty($names['dirname']) === true) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('File ' . $names['basename'] . ' does not exist', E_USER_WARNING); } return false; } $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR); if (null === $dir) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Directory ' . $names['dirname'] . ' does not exist', E_USER_WARNING); } return false; } elseif ($dir->hasChild($names['basename']) === true) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Directory ' . $names['dirname'] . ' already contains a director named ' . $names['basename'], E_USER_WARNING); } return false; } if (self::READ === $mode) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Can not open non-existing file ' . $path . ' for reading', E_USER_WARNING); } return false; } if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Can not create new file in non-writable path ' . $names['dirname'], E_USER_WARNING); } return false; } return vfsStream::newFile($names['basename'])->at($dir); } /** * calculates the file mode * * @param string $mode opening mode: r, w, a or x * @param bool $extended true if + was set with opening mode * @return int */ protected function calculateMode($mode, $extended) { if (true === $extended) { return self::ALL; } if (self::READ === $mode) { return self::READONLY; } return self::WRITEONLY; } /** * closes the stream * * @see https://github.com/mikey179/vfsStream/issues/40 */ public function stream_close() { $this->content->lock($this, LOCK_UN); } /** * read the stream up to $count bytes * * @param int $count amount of bytes to read * @return string */ public function stream_read($count) { if (self::WRITEONLY === $this->mode) { return ''; } if ($this->content->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return ''; } return $this->content->read($count); } /** * writes data into the stream * * @param string $data * @return int amount of bytes written */ public function stream_write($data) { if (self::READONLY === $this->mode) { return 0; } if ($this->content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return 0; } if (self::$quota->isLimited()) { $data = substr($data, 0, self::$quota->spaceLeft(self::$root->sizeSummarized())); } return $this->content->write($data); } /** * truncates a file to a given length * * @param int $size length to truncate file to * @return bool * @since 1.1.0 */ public function stream_truncate($size) { if (self::READONLY === $this->mode) { return false; } if ($this->content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return false; } if ($this->content->getType() !== vfsStreamContent::TYPE_FILE) { return false; } if (self::$quota->isLimited() && $this->content->size() < $size) { $maxSize = self::$quota->spaceLeft(self::$root->sizeSummarized()); if (0 === $maxSize) { return false; } if ($size > $maxSize) { $size = $maxSize; } } return $this->content->truncate($size); } /** * sets metadata like owner, user or permissions * * @param string $path * @param int $option * @param mixed $var * @return bool * @since 1.1.0 */ public function stream_metadata($path, $option, $var) { $path = $this->resolvePath(vfsStream::path($path)); $content = $this->getContent($path); switch ($option) { case STREAM_META_TOUCH: if (null === $content) { $content = $this->createFile($path, null, STREAM_REPORT_ERRORS); // file creation may not be allowed at provided path if (false === $content) { return false; } } $currentTime = time(); $content->lastModified(((isset($var[0])) ? ($var[0]) : ($currentTime))) ->lastAccessed(((isset($var[1])) ? ($var[1]) : ($currentTime))); return true; case STREAM_META_OWNER_NAME: return false; case STREAM_META_OWNER: if (null === $content) { return false; } return $this->doPermChange($path, $content, function() use ($content, $var) { $content->chown($var); } ); case STREAM_META_GROUP_NAME: return false; case STREAM_META_GROUP: if (null === $content) { return false; } return $this->doPermChange($path, $content, function() use ($content, $var) { $content->chgrp($var); } ); case STREAM_META_ACCESS: if (null === $content) { return false; } return $this->doPermChange($path, $content, function() use ($content, $var) { $content->chmod($var); } ); default: return false; } } /** * executes given permission change when necessary rights allow such a change * * @param string $path * @param vfsStreamAbstractContent $content * @param \Closure $change * @return bool */ private function doPermChange($path, vfsStreamAbstractContent $content, \Closure $change) { if (!$content->isOwnedByUser(vfsStream::getCurrentUser())) { return false; } if (self::$root->getName() !== $path) { $names = $this->splitPath($path); $parent = $this->getContent($names['dirname']); if (!$parent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) { return false; } } $change(); return true; } /** * checks whether stream is at end of file * * @return bool */ public function stream_eof() { return $this->content->eof(); } /** * returns the current position of the stream * * @return int */ public function stream_tell() { return $this->content->getBytesRead(); } /** * seeks to the given offset * * @param int $offset * @param int $whence * @return bool */ public function stream_seek($offset, $whence) { return $this->content->seek($offset, $whence); } /** * flushes unstored data into storage * * @return bool */ public function stream_flush() { return true; } /** * returns status of stream * * @return array */ public function stream_stat() { $fileStat = array('dev' => 0, 'ino' => 0, 'mode' => $this->content->getType() | $this->content->getPermissions(), 'nlink' => 0, 'uid' => $this->content->getUser(), 'gid' => $this->content->getGroup(), 'rdev' => 0, 'size' => $this->content->size(), 'atime' => $this->content->fileatime(), 'mtime' => $this->content->filemtime(), 'ctime' => $this->content->filectime(), 'blksize' => -1, 'blocks' => -1 ); return array_merge(array_values($fileStat), $fileStat); } /** * retrieve the underlaying resource * * Please note that this method always returns false as there is no * underlaying resource to return. * * @param int $cast_as * @since 0.9.0 * @see https://github.com/mikey179/vfsStream/issues/3 * @return bool */ public function stream_cast($cast_as) { return false; } /** * set lock status for stream * * @param int $operation * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 * @see https://github.com/mikey179/vfsStream/issues/31 * @see https://github.com/mikey179/vfsStream/issues/40 */ public function stream_lock($operation) { if ((LOCK_NB & $operation) == LOCK_NB) { $operation = $operation - LOCK_NB; } return $this->content->lock($this, $operation); } /** * sets options on the stream * * @param int $option key of option to set * @param int $arg1 * @param int $arg2 * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/15 * @see http://www.php.net/manual/streamwrapper.stream-set-option.php */ public function stream_set_option($option, $arg1, $arg2) { switch ($option) { case STREAM_OPTION_BLOCKING: // break omitted case STREAM_OPTION_READ_TIMEOUT: // break omitted case STREAM_OPTION_WRITE_BUFFER: // break omitted default: // nothing to do here } return false; } /** * remove the data under the given path * * @param string $path * @return bool */ public function unlink($path) { $realPath = $this->resolvePath(vfsStream::path($path)); $content = $this->getContent($realPath); if (null === $content) { trigger_error('unlink(' . $path . '): No such file or directory', E_USER_WARNING); return false; } if ($content->getType() !== vfsStreamContent::TYPE_FILE) { trigger_error('unlink(' . $path . '): Operation not permitted', E_USER_WARNING); return false; } return $this->doUnlink($realPath); } /** * removes a path * * @param string $path * @return bool */ protected function doUnlink($path) { if (self::$root->getName() === $path) { // delete root? very brave. :) self::$root = null; clearstatcache(); return true; } $names = $this->splitPath($path); $content = $this->getContent($names['dirname']); if (!$content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) { return false; } clearstatcache(); return $content->removeChild($names['basename']); } /** * rename from one path to another * * @param string $path_from * @param string $path_to * @return bool * @author Benoit Aubuchon */ public function rename($path_from, $path_to) { $srcRealPath = $this->resolvePath(vfsStream::path($path_from)); $dstRealPath = $this->resolvePath(vfsStream::path($path_to)); $srcContent = $this->getContent($srcRealPath); if (null == $srcContent) { trigger_error(' No such file or directory', E_USER_WARNING); return false; } $dstNames = $this->splitPath($dstRealPath); $dstParentContent = $this->getContent($dstNames['dirname']); if (null == $dstParentContent) { trigger_error('No such file or directory', E_USER_WARNING); return false; } if (!$dstParentContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) { trigger_error('Permission denied', E_USER_WARNING); return false; } if ($dstParentContent->getType() !== vfsStreamContent::TYPE_DIR) { trigger_error('Target is not a directory', E_USER_WARNING); return false; } // remove old source first, so we can rename later // (renaming first would lead to not being able to remove the old path) if (!$this->doUnlink($srcRealPath)) { return false; } $dstContent = $srcContent; // Renaming the filename $dstContent->rename($dstNames['basename']); // Copying to the destination $dstParentContent->addChild($dstContent); return true; } /** * creates a new directory * * @param string $path * @param int $mode * @param int $options * @return bool */ public function mkdir($path, $mode, $options) { $umask = vfsStream::umask(); if (0 < $umask) { $permissions = $mode & ~$umask; } else { $permissions = $mode; } $path = $this->resolvePath(vfsStream::path($path)); if (null !== $this->getContent($path)) { trigger_error('mkdir(): Path vfs://' . $path . ' exists', E_USER_WARNING); return false; } if (null === self::$root) { self::$root = vfsStream::newDirectory($path, $permissions); return true; } $maxDepth = count(explode('/', $path)); $names = $this->splitPath($path); $newDirs = $names['basename']; $dir = null; $i = 0; while ($dir === null && $i < $maxDepth) { $dir = $this->getContent($names['dirname']); $names = $this->splitPath($names['dirname']); if (null == $dir) { $newDirs = $names['basename'] . '/' . $newDirs; } $i++; } if (null === $dir || $dir->getType() !== vfsStreamContent::TYPE_DIR || $dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return false; } $recursive = ((STREAM_MKDIR_RECURSIVE & $options) !== 0) ? (true) : (false); if (strpos($newDirs, '/') !== false && false === $recursive) { return false; } vfsStream::newDirectory($newDirs, $permissions)->at($dir); return true; } /** * removes a directory * * @param string $path * @param int $options * @return bool * @todo consider $options with STREAM_MKDIR_RECURSIVE */ public function rmdir($path, $options) { $path = $this->resolvePath(vfsStream::path($path)); $child = $this->getContentOfType($path, vfsStreamContent::TYPE_DIR); if (null === $child) { return false; } // can only remove empty directories if (count($child->getChildren()) > 0) { return false; } if (self::$root->getName() === $path) { // delete root? very brave. :) self::$root = null; clearstatcache(); return true; } $names = $this->splitPath($path); $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR); if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return false; } clearstatcache(); return $dir->removeChild($child->getName()); } /** * opens a directory * * @param string $path * @param int $options * @return bool */ public function dir_opendir($path, $options) { $path = $this->resolvePath(vfsStream::path($path)); $this->dir = $this->getContentOfType($path, vfsStreamContent::TYPE_DIR); if (null === $this->dir || $this->dir->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return false; } $this->dirIterator = $this->dir->getIterator(); return true; } /** * reads directory contents * * @return string */ public function dir_readdir() { $dir = $this->dirIterator->current(); if (null === $dir) { return false; } $this->dirIterator->next(); return $dir->getName(); } /** * reset directory iteration * * @return bool */ public function dir_rewinddir() { return $this->dirIterator->rewind(); } /** * closes directory * * @return bool */ public function dir_closedir() { $this->dirIterator = null; return true; } /** * returns status of url * * @param string $path path of url to return status for * @param int $flags flags set by the stream API * @return array */ public function url_stat($path, $flags) { $content = $this->getContent($this->resolvePath(vfsStream::path($path))); if (null === $content) { if (($flags & STREAM_URL_STAT_QUIET) != STREAM_URL_STAT_QUIET) { trigger_error(' No such file or directory: ' . $path, E_USER_WARNING); } return false; } $fileStat = array('dev' => 0, 'ino' => 0, 'mode' => $content->getType() | $content->getPermissions(), 'nlink' => 0, 'uid' => $content->getUser(), 'gid' => $content->getGroup(), 'rdev' => 0, 'size' => $content->size(), 'atime' => $content->fileatime(), 'mtime' => $content->filemtime(), 'ctime' => $content->filectime(), 'blksize' => -1, 'blocks' => -1 ); return array_merge(array_values($fileStat), $fileStat); } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/visitor/000077500000000000000000000000001355632626400223675ustar00rootroot00000000000000vfsStream-1.6.8/src/main/php/org/bovigo/vfs/visitor/vfsStreamAbstractVisitor.php000066400000000000000000000032331355632626400301170ustar00rootroot00000000000000getType()) { case vfsStreamContent::TYPE_BLOCK: $this->visitBlockDevice($content); break; case vfsStreamContent::TYPE_FILE: $this->visitFile($content); break; case vfsStreamContent::TYPE_DIR: if (!$content->isDot()) { $this->visitDirectory($content); } break; default: throw new \InvalidArgumentException('Unknown content type ' . $content->getType() . ' for ' . $content->getName()); } return $this; } /** * visit a block device and process it * * @param vfsStreamBlock $block * @return vfsStreamVisitor */ public function visitBlockDevice(vfsStreamBlock $block) { return $this->visitFile($block); } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php000066400000000000000000000047741355632626400274630ustar00rootroot00000000000000out = $out; } /** * visit a file and process it * * @param vfsStreamFile $file * @return vfsStreamPrintVisitor */ public function visitFile(vfsStreamFile $file) { $this->printContent($file->getName()); return $this; } /** * visit a block device and process it * * @param vfsStreamBlock $block * @return vfsStreamPrintVisitor */ public function visitBlockDevice(vfsStreamBlock $block) { $name = '[' . $block->getName() . ']'; $this->printContent($name); return $this; } /** * visit a directory and process it * * @param vfsStreamDirectory $dir * @return vfsStreamPrintVisitor */ public function visitDirectory(vfsStreamDirectory $dir) { $this->printContent($dir->getName()); $this->depth++; foreach ($dir as $child) { $this->visit($child); } $this->depth--; return $this; } /** * helper method to print the content * * @param string $name */ protected function printContent($name) { fwrite($this->out, str_repeat(' ', $this->depth) . '- ' . $name . "\n"); } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php000066400000000000000000000047011355632626400303550ustar00rootroot00000000000000reset(); } /** * visit a file and process it * * @param vfsStreamFile $file * @return vfsStreamStructureVisitor */ public function visitFile(vfsStreamFile $file) { $this->current[$file->getName()] = $file->getContent(); return $this; } /** * visit a block device and process it * * @param vfsStreamBlock $block * @return vfsStreamStructureVisitor */ public function visitBlockDevice(vfsStreamBlock $block) { $this->current['[' . $block->getName() . ']'] = $block->getContent(); return $this; } /** * visit a directory and process it * * @param vfsStreamDirectory $dir * @return vfsStreamStructureVisitor */ public function visitDirectory(vfsStreamDirectory $dir) { $this->current[$dir->getName()] = array(); $tmp =& $this->current; $this->current =& $tmp[$dir->getName()]; foreach ($dir as $child) { $this->visit($child); } $this->current =& $tmp; return $this; } /** * returns structure of visited contents * * @return array * @api */ public function getStructure() { return $this->structure; } /** * resets structure so visitor could be reused * * @return vfsStreamStructureVisitor */ public function reset() { $this->structure = array(); $this->current =& $this->structure; return $this; } } vfsStream-1.6.8/src/main/php/org/bovigo/vfs/visitor/vfsStreamVisitor.php000066400000000000000000000025051355632626400264340ustar00rootroot00000000000000getMockBuilder($originalClassName) ->setMethods($methods) ->getMock() ; } return parent::getMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget); } } // The only deprecation warnings we need to ignore/handle are in PHP 7.4 so far if (PHP_VERSION_ID >= 70400) { function customErrorHandler($errno, $errstr, $errfile, $errline) { // We know about this deprecation warning exists and it's already been // fixed in the 2.x branch. For BC reasons in the 1.x branch, we'll // ignore this warning to let tests pass. if ($errno === E_DEPRECATED) { if ($errstr === "Function ReflectionType::__toString() is deprecated") { return true; } } // Any other error should be left up to PHPUnit to handle return \PHPUnit_Util_ErrorHandler::handleError($errno, $errstr, $errfile, $errline); } set_error_handler("customErrorHandler"); } vfsStream-1.6.8/src/test/php/000077500000000000000000000000001355632626400160515ustar00rootroot00000000000000vfsStream-1.6.8/src/test/php/org/000077500000000000000000000000001355632626400166405ustar00rootroot00000000000000vfsStream-1.6.8/src/test/php/org/bovigo/000077500000000000000000000000001355632626400201255ustar00rootroot00000000000000vfsStream-1.6.8/src/test/php/org/bovigo/vfs/000077500000000000000000000000001355632626400207235ustar00rootroot00000000000000vfsStream-1.6.8/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php000066400000000000000000000267731355632626400267320ustar00rootroot00000000000000assertEquals($expectedCount, $actualCount, 'Directory foo contains ' . $expectedCount . ' children, but got ' . $actualCount . ' children while iterating over directory contents' ); } /** * @param \Closure $dotFilesSwitch * @param string[] $expectedDirectories * @test * @dataProvider provideSwitchWithExpectations */ public function directoryIteration(\Closure $dotFilesSwitch, array $expectedDirectories) { $dotFilesSwitch(); $dir = dir($this->fooURL); $i = 0; while (false !== ($entry = $dir->read())) { $i++; $this->assertTrue(in_array($entry, $expectedDirectories)); } $this->assertDirectoryCount(count($expectedDirectories), $i); $dir->rewind(); $i = 0; while (false !== ($entry = $dir->read())) { $i++; $this->assertTrue(in_array($entry, $expectedDirectories)); } $this->assertDirectoryCount(count($expectedDirectories), $i); $dir->close(); } /** * @param \Closure $dotFilesSwitch * @param string[] $expectedDirectories * @test * @dataProvider provideSwitchWithExpectations */ public function directoryIterationWithDot(\Closure $dotFilesSwitch, array $expectedDirectories) { $dotFilesSwitch(); $dir = dir($this->fooURL . '/.'); $i = 0; while (false !== ($entry = $dir->read())) { $i++; $this->assertTrue(in_array($entry, $expectedDirectories)); } $this->assertDirectoryCount(count($expectedDirectories), $i); $dir->rewind(); $i = 0; while (false !== ($entry = $dir->read())) { $i++; $this->assertTrue(in_array($entry, $expectedDirectories)); } $this->assertDirectoryCount(count($expectedDirectories), $i); $dir->close(); } /** * assure that a directory iteration works as expected * * @param \Closure $dotFilesSwitch * @param string[] $expectedDirectories * @test * @dataProvider provideSwitchWithExpectations * @group regression * @group bug_2 */ public function directoryIterationWithOpenDir_Bug_2(\Closure $dotFilesSwitch, array $expectedDirectories) { $dotFilesSwitch(); $handle = opendir($this->fooURL); $i = 0; while (false !== ($entry = readdir($handle))) { $i++; $this->assertTrue(in_array($entry, $expectedDirectories)); } $this->assertDirectoryCount(count($expectedDirectories), $i); rewinddir($handle); $i = 0; while (false !== ($entry = readdir($handle))) { $i++; $this->assertTrue(in_array($entry, $expectedDirectories)); } $this->assertDirectoryCount(count($expectedDirectories), $i); closedir($handle); } /** * assure that a directory iteration works as expected * * @author Christoph Bloemer * @param \Closure $dotFilesSwitch * @param string[] $expectedDirectories * @test * @dataProvider provideSwitchWithExpectations * @group regression * @group bug_4 */ public function directoryIteration_Bug_4(\Closure $dotFilesSwitch, array $expectedDirectories) { $dotFilesSwitch(); $dir = $this->fooURL; $list1 = array(); if ($handle = opendir($dir)) { while (false !== ($listItem = readdir($handle))) { if ('.' != $listItem && '..' != $listItem) { if (is_file($dir . '/' . $listItem) === true) { $list1[] = 'File:[' . $listItem . ']'; } elseif (is_dir($dir . '/' . $listItem) === true) { $list1[] = 'Folder:[' . $listItem . ']'; } } } closedir($handle); } $list2 = array(); if ($handle = opendir($dir)) { while (false !== ($listItem = readdir($handle))) { if ('.' != $listItem && '..' != $listItem) { if (is_file($dir . '/' . $listItem) === true) { $list2[] = 'File:[' . $listItem . ']'; } elseif (is_dir($dir . '/' . $listItem) === true) { $list2[] = 'Folder:[' . $listItem . ']'; } } } closedir($handle); } $this->assertEquals($list1, $list2); $this->assertEquals(2, count($list1)); $this->assertEquals(2, count($list2)); } /** * assure that a directory iteration works as expected * * @param \Closure $dotFilesSwitch * @param string[] $expectedDirectories * @test * @dataProvider provideSwitchWithExpectations */ public function directoryIterationShouldBeIndependent(\Closure $dotFilesSwitch, array $expectedDirectories) { $dotFilesSwitch(); $list1 = array(); $list2 = array(); $handle1 = opendir($this->fooURL); if (false !== ($listItem = readdir($handle1))) { $list1[] = $listItem; } $handle2 = opendir($this->fooURL); if (false !== ($listItem = readdir($handle2))) { $list2[] = $listItem; } if (false !== ($listItem = readdir($handle1))) { $list1[] = $listItem; } if (false !== ($listItem = readdir($handle2))) { $list2[] = $listItem; } closedir($handle1); closedir($handle2); $this->assertEquals($list1, $list2); $this->assertEquals(2, count($list1)); $this->assertEquals(2, count($list2)); } /** * @test * @group issue_50 */ public function recursiveDirectoryIterationWithDotsEnabled() { vfsStream::enableDotfiles(); vfsStream::setup(); $structure = array( 'Core' => array( 'AbstractFactory' => array( 'test.php' => 'some text content', 'other.php' => 'Some more text content', 'Invalid.csv' => 'Something else', ), 'AnEmptyFolder' => array(), 'badlocation.php' => 'some bad content', ) ); $root = vfsStream::create($structure); $rootPath = vfsStream::url($root->getName()); $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::CHILD_FIRST); $pathes = array(); foreach ($iterator as $fullFileName => $fileSPLObject) { $pathes[] = $fullFileName; } $this->assertEquals(array('vfs://root'.DIRECTORY_SEPARATOR.'.', 'vfs://root'.DIRECTORY_SEPARATOR.'..', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'.', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'.', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'..', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'test.php', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'other.php', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'Invalid.csv', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AnEmptyFolder'.DIRECTORY_SEPARATOR.'.', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AnEmptyFolder'.DIRECTORY_SEPARATOR.'..', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AnEmptyFolder', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'badlocation.php', 'vfs://root'.DIRECTORY_SEPARATOR.'Core' ), $pathes ); } /** * @test * @group issue_50 */ public function recursiveDirectoryIterationWithDotsDisabled() { vfsStream::disableDotfiles(); vfsStream::setup(); $structure = array( 'Core' => array( 'AbstractFactory' => array( 'test.php' => 'some text content', 'other.php' => 'Some more text content', 'Invalid.csv' => 'Something else', ), 'AnEmptyFolder' => array(), 'badlocation.php' => 'some bad content', ) ); $root = vfsStream::create($structure); $rootPath = vfsStream::url($root->getName()); $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::CHILD_FIRST); $pathes = array(); foreach ($iterator as $fullFileName => $fileSPLObject) { $pathes[] = $fullFileName; } $this->assertEquals(array('vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'test.php', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'other.php', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory'.DIRECTORY_SEPARATOR.'Invalid.csv', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AbstractFactory', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'AnEmptyFolder', 'vfs://root'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'badlocation.php', 'vfs://root'.DIRECTORY_SEPARATOR.'Core' ), $pathes ); } }vfsStream-1.6.8/src/test/php/org/bovigo/vfs/FilenameTestCase.php000066400000000000000000000042451355632626400246150ustar00rootroot00000000000000rootDir = vfsStream::url('root'); $this->lostAndFound = $this->rootDir . '/lost+found/'; mkdir($this->lostAndFound); } /** * @test */ public function worksWithCorrectName() { $results = array(); $it = new \RecursiveDirectoryIterator($this->lostAndFound); foreach ($it as $f) { $results[] = $f->getPathname(); } $this->assertEquals( array( 'vfs://root/lost+found' . DIRECTORY_SEPARATOR . '.', 'vfs://root/lost+found' . DIRECTORY_SEPARATOR . '..' ), $results ); } /** * @test * @expectedException UnexpectedValueException * @expectedExceptionMessage failed to open dir */ public function doesNotWorkWithInvalidName() { $results = array(); $it = new \RecursiveDirectoryIterator($this->rootDir . '/lost found/'); foreach ($it as $f) { $results[] = $f->getPathname(); } } /** * @test */ public function returnsCorrectNames() { $results = array(); $it = new \RecursiveDirectoryIterator($this->rootDir); foreach ($it as $f) { $results[] = $f->getPathname(); } $this->assertEquals( array( 'vfs://root' . DIRECTORY_SEPARATOR . '.', 'vfs://root' . DIRECTORY_SEPARATOR . '..', 'vfs://root' . DIRECTORY_SEPARATOR . 'lost+found' ), $results ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/Issue104TestCase.php000066400000000000000000000031641355632626400244110ustar00rootroot00000000000000 array( 'schema.xsd' => ' ', ) ); vfsStream::setup('root', null, $structure); $doc = new \DOMDocument(); $this->assertTrue($doc->load(vfsStream::url('root/foo bar/schema.xsd'))); } /** * @test */ public function vfsStreamCanHandleUrlEncodedPath() { $content = ' '; $structure = array('foo bar' => array( 'schema.xsd' => $content, ) ); vfsStream::setup('root', null, $structure); $this->assertEquals( $content, file_get_contents(vfsStream::url('root/foo bar/schema.xsd')) ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/PermissionsTestCase.php000066400000000000000000000063651355632626400254150ustar00rootroot00000000000000 array('test.file' => '')); $this->root = vfsStream::setup('root', null, $structure); } /** * @test * @group issue_52 */ public function canNotChangePermissionWhenDirectoryNotWriteable() { $this->root->getChild('test_directory')->chmod(0444); $this->assertFalse(@chmod(vfsStream::url('root/test_directory/test.file'), 0777)); } /** * @test * @group issue_53 */ public function canNotChangePermissionWhenFileNotOwned() { $this->root->getChild('test_directory')->getChild('test.file')->chown(vfsStream::OWNER_USER_1); $this->assertFalse(@chmod(vfsStream::url('root/test_directory/test.file'), 0777)); } /** * @test * @group issue_52 */ public function canNotChangeOwnerWhenDirectoryNotWriteable() { $this->root->getChild('test_directory')->chmod(0444); $this->assertFalse(@chown(vfsStream::url('root/test_directory/test.file'), vfsStream::OWNER_USER_2)); } /** * @test * @group issue_53 */ public function canNotChangeOwnerWhenFileNotOwned() { $this->root->getChild('test_directory')->getChild('test.file')->chown(vfsStream::OWNER_USER_1); $this->assertFalse(@chown(vfsStream::url('root/test_directory/test.file'), vfsStream::OWNER_USER_2)); } /** * @test * @group issue_52 */ public function canNotChangeGroupWhenDirectoryNotWriteable() { $this->root->getChild('test_directory')->chmod(0444); $this->assertFalse(@chgrp(vfsStream::url('root/test_directory/test.file'), vfsStream::GROUP_USER_2)); } /** * @test * @group issue_53 */ public function canNotChangeGroupWhenFileNotOwned() { $this->root->getChild('test_directory')->getChild('test.file')->chown(vfsStream::OWNER_USER_1); $this->assertFalse(@chgrp(vfsStream::url('root/test_directory/test.file'), vfsStream::GROUP_USER_2)); } /** * @test * @group issue_107 * @expectedException PHPUnit_Framework_Error * @expectedExceptionMessage Can not create new file in non-writable path root * @requires PHP 5.4 * @since 1.5.0 */ public function touchOnNonWriteableDirectoryTriggersError() { $this->root->chmod(0555); touch($this->root->url() . '/touch.txt'); } /** * @test * @group issue_107 * @requires PHP 5.4 * @since 1.5.0 */ public function touchOnNonWriteableDirectoryDoesNotCreateFile() { $this->root->chmod(0555); $this->assertFalse(@touch($this->root->url() . '/touch.txt')); $this->assertFalse($this->root->hasChild('touch.txt')); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/QuotaTestCase.php000066400000000000000000000030031355632626400241550ustar00rootroot00000000000000quota = new Quota(10); } /** * @test */ public function unlimitedQuotaIsNotLimited() { $this->assertFalse(Quota::unlimited()->isLimited()); } /** * @test */ public function limitedQuotaIsLimited() { $this->assertTrue($this->quota->isLimited()); } /** * @test */ public function unlimitedQuotaHasAlwaysSpaceLeft() { $this->assertEquals(303, Quota::unlimited()->spaceLeft(303)); } /** * @test */ public function hasNoSpaceLeftWhenUsedSpaceIsLargerThanQuota() { $this->assertEquals(0, $this->quota->spaceLeft(11)); } /** * @test */ public function hasNoSpaceLeftWhenUsedSpaceIsEqualToQuota() { $this->assertEquals(0, $this->quota->spaceLeft(10)); } /** * @test */ public function hasSpaceLeftWhenUsedSpaceIsLowerThanQuota() { $this->assertEquals(1, $this->quota->spaceLeft(9)); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/UnlinkTestCase.php000066400000000000000000000033401355632626400243300ustar00rootroot00000000000000 array('test.file' => '')); $root = vfsStream::setup('root', null, $structure); $root->getChild('test_directory')->chmod(0777); $root->getChild('test_directory')->getChild('test.file')->chmod(0444); $this->assertTrue(@unlink(vfsStream::url('root/test_directory/test.file'))); } /** * @test * @group issue_51 */ public function canNotRemoveWritableFileFromNonWritableDirectory() { $structure = array('test_directory' => array('test.file' => '')); $root = vfsStream::setup('root', null, $structure); $root->getChild('test_directory')->chmod(0444); $root->getChild('test_directory')->getChild('test.file')->chmod(0777); $this->assertFalse(@unlink(vfsStream::url('root/test_directory/test.file'))); } /** * @test * @since 1.4.0 * @group issue_68 */ public function unlinkNonExistingFileTriggersError() { vfsStream::setup(); try { $this->assertFalse(unlink('vfs://root/foo.txt')); } catch (\PHPUnit_Framework_Error $fe) { $this->assertEquals('unlink(vfs://root/foo.txt): No such file or directory', $fe->getMessage()); } } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/content/000077500000000000000000000000001355632626400223755ustar00rootroot00000000000000vfsStream-1.6.8/src/test/php/org/bovigo/vfs/content/LargeFileContentTestCase.php000066400000000000000000000130271355632626400277320ustar00rootroot00000000000000largeFileContent = new LargeFileContent(100); } /** * @test */ public function hasSizeOriginallyGiven() { $this->assertEquals(100, $this->largeFileContent->size()); } /** * @test */ public function contentIsFilledUpWithSpacesIfNoDataWritten() { $this->assertEquals( str_repeat(' ', 100), $this->largeFileContent->content() ); } /** * @test */ public function readReturnsSpacesWhenNothingWrittenAtOffset() { $this->assertEquals( str_repeat(' ', 10), $this->largeFileContent->read(10) ); } /** * @test */ public function readReturnsContentFilledWithSpaces() { $this->largeFileContent->write('foobarbaz'); $this->largeFileContent->seek(0, SEEK_SET); $this->assertEquals( 'foobarbaz ', $this->largeFileContent->read(10) ); } /** * @test */ public function writesDataAtStartWhenOffsetNotMoved() { $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals( 'foobarbaz' . str_repeat(' ', 91), $this->largeFileContent->content() ); } /** * @test */ public function writeDataAtStartDoesNotIncreaseSize() { $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals(100, $this->largeFileContent->size()); } /** * @test */ public function writesDataAtOffsetWhenOffsetMoved() { $this->largeFileContent->seek(50, SEEK_SET); $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals( str_repeat(' ', 50) . 'foobarbaz' . str_repeat(' ', 41), $this->largeFileContent->content() ); } /** * @test */ public function writeDataInBetweenDoesNotIncreaseSize() { $this->largeFileContent->seek(50, SEEK_SET); $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals(100, $this->largeFileContent->size()); } /** * @test */ public function writesDataOverEndWhenOffsetAndDataLengthLargerThanSize() { $this->largeFileContent->seek(95, SEEK_SET); $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals( str_repeat(' ', 95) . 'foobarbaz', $this->largeFileContent->content() ); } /** * @test */ public function writeDataOverLastOffsetIncreasesSize() { $this->largeFileContent->seek(95, SEEK_SET); $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals(104, $this->largeFileContent->size()); } /** * @test */ public function writesDataAfterEndWhenOffsetAfterEnd() { $this->largeFileContent->seek(0, SEEK_END); $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals( str_repeat(' ', 100) . 'foobarbaz', $this->largeFileContent->content() ); } /** * @test */ public function writeDataAfterLastOffsetIncreasesSize() { $this->largeFileContent->seek(0, SEEK_END); $this->assertEquals(9, $this->largeFileContent->write('foobarbaz')); $this->assertEquals(109, $this->largeFileContent->size()); } /** * @test */ public function truncateReducesSize() { $this->assertTrue($this->largeFileContent->truncate(50)); $this->assertEquals(50, $this->largeFileContent->size()); } /** * @test */ public function truncateRemovesWrittenContentAfterOffset() { $this->largeFileContent->seek(45, SEEK_SET); $this->largeFileContent->write('foobarbaz'); $this->assertTrue($this->largeFileContent->truncate(50)); $this->assertEquals( str_repeat(' ', 45) . 'fooba', $this->largeFileContent->content() ); } /** * @test */ public function createInstanceWithKilobytes() { $this->assertEquals( 100 * 1024, LargeFileContent::withKilobytes(100) ->size() ); } /** * @test */ public function createInstanceWithMegabytes() { $this->assertEquals( 100 * 1024 * 1024, LargeFileContent::withMegabytes(100) ->size() ); } /** * @test */ public function createInstanceWithGigabytes() { $this->assertEquals( 100 * 1024 * 1024 * 1024, LargeFileContent::withGigabytes(100) ->size() ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/content/StringBasedFileContentTestCase.php000066400000000000000000000132701355632626400311050ustar00rootroot00000000000000stringBasedFileContent = new StringBasedFileContent('foobarbaz'); } /** * @test */ public function hasContentOriginallySet() { $this->assertEquals('foobarbaz', $this->stringBasedFileContent->content()); } /** * @test */ public function hasNotReachedEofAfterCreation() { $this->assertFalse($this->stringBasedFileContent->eof()); } /** * @test */ public function sizeEqualsLengthOfGivenString() { $this->assertEquals(9, $this->stringBasedFileContent->size()); } /** * @test */ public function readReturnsSubstringWithRequestedLength() { $this->assertEquals('foo', $this->stringBasedFileContent->read(3)); } /** * @test */ public function readMovesOffset() { $this->assertEquals('foo', $this->stringBasedFileContent->read(3)); $this->assertEquals('bar', $this->stringBasedFileContent->read(3)); $this->assertEquals('baz', $this->stringBasedFileContent->read(3)); } /** * @test */ public function reaMoreThanSizeReturnsWholeContent() { $this->assertEquals('foobarbaz', $this->stringBasedFileContent->read(10)); } /** * @test */ public function readAfterEndReturnsEmptyString() { // Read more than the length of the string to test substr() returning // false. $this->stringBasedFileContent->read(10); $this->assertSame('', $this->stringBasedFileContent->read(3)); } /** * @test */ public function readDoesNotChangeSize() { $this->stringBasedFileContent->read(3); $this->assertEquals(9, $this->stringBasedFileContent->size()); } /** * @test */ public function readLessThenSizeDoesNotReachEof() { $this->stringBasedFileContent->read(3); $this->assertFalse($this->stringBasedFileContent->eof()); } /** * @test */ public function readSizeReachesEof() { $this->stringBasedFileContent->read(9); $this->assertTrue($this->stringBasedFileContent->eof()); } /** * @test */ public function readMoreThanSizeReachesEof() { $this->stringBasedFileContent->read(10); $this->assertTrue($this->stringBasedFileContent->eof()); } /** * @test */ public function seekWithInvalidOptionReturnsFalse() { $this->assertFalse($this->stringBasedFileContent->seek(0, 55)); } /** * @test */ public function canSeekToGivenOffset() { $this->assertTrue($this->stringBasedFileContent->seek(5, SEEK_SET)); $this->assertEquals('rbaz', $this->stringBasedFileContent->read(10)); } /** * @test */ public function canSeekFromCurrentOffset() { $this->assertTrue($this->stringBasedFileContent->seek(5, SEEK_SET)); $this->assertTrue($this->stringBasedFileContent->seek(2, SEEK_CUR)); $this->assertEquals('az', $this->stringBasedFileContent->read(10)); } /** * @test */ public function canSeekToEnd() { $this->assertTrue($this->stringBasedFileContent->seek(0, SEEK_END)); $this->assertEquals('', $this->stringBasedFileContent->read(10)); } /** * @test */ public function writeOverwritesExistingContentWhenOffsetNotAtEof() { $this->assertEquals(3, $this->stringBasedFileContent->write('bar')); $this->assertEquals('barbarbaz', $this->stringBasedFileContent->content()); } /** * @test */ public function writeAppendsContentWhenOffsetAtEof() { $this->assertTrue($this->stringBasedFileContent->seek(0, SEEK_END)); $this->assertEquals(3, $this->stringBasedFileContent->write('bar')); $this->assertEquals('foobarbazbar', $this->stringBasedFileContent->content()); } /** * @test * @group issue_33 * @since 1.1.0 */ public function truncateRemovesSuperflouosContent() { $this->assertTrue($this->stringBasedFileContent->truncate(6)); $this->assertEquals('foobar', $this->stringBasedFileContent->content()); } /** * @test * @group issue_33 * @since 1.1.0 */ public function truncateDecreasesSize() { $this->assertTrue($this->stringBasedFileContent->truncate(6)); $this->assertEquals(6, $this->stringBasedFileContent->size()); } /** * @test * @group issue_33 * @since 1.1.0 */ public function truncateToGreaterSizeAddsZeroBytes() { $this->assertTrue($this->stringBasedFileContent->truncate(25)); $this->assertEquals( "foobarbaz\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", $this->stringBasedFileContent->content() ); } /** * @test * @group issue_33 * @since 1.1.0 */ public function truncateToGreaterSizeIncreasesSize() { $this->assertTrue($this->stringBasedFileContent->truncate(25)); $this->assertEquals(25, $this->stringBasedFileContent->size()); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/proxy/000077500000000000000000000000001355632626400221045ustar00rootroot00000000000000vfsStream-1.6.8/src/test/php/org/bovigo/vfs/proxy/vfsStreamWrapperRecordingProxy.php000066400000000000000000000172671355632626400310440ustar00rootroot00000000000000 */ public static function getMethodCalls($path) { if (isset(self::$calledMethods[$path]) === true) { return self::$calledMethods[$path]; } return array(); } /** * helper method for setting up vfsStream with the proxy * * @param string $rootDirName optional name of root directory * @param int $permissions optional file permissions of root directory * @return vfsStreamDirectory * @throws vfsStreamException */ public static function setup($rootDirName = 'root', $permissions = null) { self::$root = vfsStream::newDirectory($rootDirName, $permissions); if (true === self::$registered) { return self::$root; } if (@stream_wrapper_register(vfsStream::SCHEME, __CLASS__) === false) { throw new vfsStreamException('A handler has already been registered for the ' . vfsStream::SCHEME . ' protocol.'); } self::$registered = true; return self::$root; } /** * open the stream * * @param string $path the path to open * @param string $mode mode for opening * @param string $options options for opening * @param string $opened_path full path that was actually opened * @return bool */ public function stream_open($path, $mode, $options, $opened_path) { $this->path = $path; self::recordMethodCall('stream_open', $this->path); return parent::stream_open($path, $mode, $options, $opened_path); } /** * closes the stream */ public function stream_close() { self::recordMethodCall('stream_close', $this->path); return parent::stream_close(); } /** * read the stream up to $count bytes * * @param int $count amount of bytes to read * @return string */ public function stream_read($count) { self::recordMethodCall('stream_read', $this->path); return parent::stream_read($count); } /** * writes data into the stream * * @param string $data * @return int amount of bytes written */ public function stream_write($data) { self::recordMethodCall('stream_write', $this->path); return parent::stream_write($data); } /** * checks whether stream is at end of file * * @return bool */ public function stream_eof() { self::recordMethodCall('stream_eof', $this->path); return parent::stream_eof(); } /** * returns the current position of the stream * * @return int */ public function stream_tell() { self::recordMethodCall('stream_tell', $this->path); return parent::stream_tell(); } /** * seeks to the given offset * * @param int $offset * @param int $whence * @return bool */ public function stream_seek($offset, $whence) { self::recordMethodCall('stream_seek', $this->path); return parent::stream_seek($offset, $whence); } /** * flushes unstored data into storage * * @return bool */ public function stream_flush() { self::recordMethodCall('stream_flush', $this->path); return parent::stream_flush(); } /** * returns status of stream * * @return array */ public function stream_stat() { self::recordMethodCall('stream_stat', $this->path); return parent::stream_stat(); } /** * retrieve the underlaying resource * * @param int $cast_as * @return bool */ public function stream_cast($cast_as) { self::recordMethodCall('stream_cast', $this->path); return parent::stream_cast($cast_as); } /** * set lock status for stream * * @param int $operation * @return bool */ public function stream_lock($operation) { self::recordMethodCall('stream_link', $this->path); return parent::stream_lock($operation); } /** * remove the data under the given path * * @param string $path * @return bool */ public function unlink($path) { self::recordMethodCall('unlink', $path); return parent::unlink($path); } /** * rename from one path to another * * @param string $path_from * @param string $path_to * @return bool */ public function rename($path_from, $path_to) { self::recordMethodCall('rename', $path_from); return parent::rename($path_from, $path_to); } /** * creates a new directory * * @param string $path * @param int $mode * @param int $options * @return bool */ public function mkdir($path, $mode, $options) { self::recordMethodCall('mkdir', $path); return parent::mkdir($path, $mode, $options); } /** * removes a directory * * @param string $path * @param int $options * @return bool */ public function rmdir($path, $options) { self::recordMethodCall('rmdir', $path); return parent::rmdir($path, $options); } /** * opens a directory * * @param string $path * @param int $options * @return bool */ public function dir_opendir($path, $options) { $this->path = $path; self::recordMethodCall('dir_opendir', $this->path); return parent::dir_opendir($path, $options); } /** * reads directory contents * * @return string */ public function dir_readdir() { self::recordMethodCall('dir_readdir', $this->path); return parent::dir_readdir(); } /** * reset directory iteration * * @return bool */ public function dir_rewinddir() { self::recordMethodCall('dir_rewinddir', $this->path); return parent::dir_rewinddir(); } /** * closes directory * * @return bool */ public function dir_closedir() { self::recordMethodCall('dir_closedir', $this->path); return parent::dir_closedir(); } /** * returns status of url * * @param string $path path of url to return status for * @param int $flags flags set by the stream API * @return array */ public function url_stat($path, $flags) { self::recordMethodCall('url_stat', $path); return parent::url_stat($path, $flags); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamAbstractContentTestCase.php000066400000000000000000001342041355632626400300650ustar00rootroot00000000000000assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function executePermissionsForUser() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0100); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function executePermissionsForGroup() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0010); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function executePermissionsForOther() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0001); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function writePermissionsForUser() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0200); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function writePermissionsForGroup() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0020); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function writePermissionsForOther() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0002); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function executeAndWritePermissionsForUser() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0300); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function executeAndWritePermissionsForGroup() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0030); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function executeAndWritePermissionsForOther() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0003); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readPermissionsForUser() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0400); $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readPermissionsForGroup() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0040); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readPermissionsForOther() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0004); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readAndExecutePermissionsForUser() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0500); $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readAndExecutePermissionsForGroup() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0050); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readAndExecutePermissionsForOther() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0005); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readAndWritePermissionsForUser() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0600); $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readAndWritePermissionsForGroup() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0060); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function readAndWritePermissionsForOther() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0006); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function allPermissionsForUser() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0700); $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function allPermissionsForGroup() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0070); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, -1 ) ); } /** * @test * @group permissions * @group bug_15 */ public function allPermissionsForOther() { $abstractContent = new TestvfsStreamAbstractContent('foo', 0007); $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isReadable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isReadable(-1, -1 ) ); $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isWritable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isWritable(-1, -1 ) ); $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup() ) ); $this->assertFalse($abstractContent->isExecutable(-1, vfsStream::getCurrentGroup() ) ); $this->assertTrue($abstractContent->isExecutable(-1, -1 ) ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamBlockTestCase.php000066400000000000000000000042451355632626400260220ustar00rootroot00000000000000block = new vfsStreamBlock('foo'); } /** * test default values and methods * * @test */ public function defaultValues() { $this->assertEquals(vfsStreamContent::TYPE_BLOCK, $this->block->getType()); $this->assertEquals('foo', $this->block->getName()); $this->assertTrue($this->block->appliesTo('foo')); $this->assertFalse($this->block->appliesTo('foo/bar')); $this->assertFalse($this->block->appliesTo('bar')); } /** * tests how external functions see this object * * @test */ public function external() { $root = vfsStream::setup('root'); $root->addChild(vfsStream::newBlock('foo')); $this->assertEquals('block', filetype(vfsStream::url('root/foo'))); } /** * tests adding a complex structure * * @test */ public function addStructure() { $structure = array( 'topLevel' => array( 'thisIsAFile' => 'file contents', '[blockDevice]' => 'block contents' ) ); $root = vfsStream::create($structure); $this->assertSame('block', filetype(vfsStream::url('root/topLevel/blockDevice'))); } /** * tests that a blank name for a block device throws an exception * @test * @expectedException org\bovigo\vfs\vfsStreamException */ public function createWithEmptyName() { $structure = array( 'topLevel' => array( 'thisIsAFile' => 'file contents', '[]' => 'block contents' ) ); $root = vfsStream::create($structure); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamContainerIteratorTestCase.php000066400000000000000000000056351355632626400304300ustar00rootroot00000000000000dir = new vfsStreamDirectory('foo'); $this->mockChild1 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $this->mockChild1->expects($this->any()) ->method('getName') ->will($this->returnValue('bar')); $this->dir->addChild($this->mockChild1); $this->mockChild2 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $this->mockChild2->expects($this->any()) ->method('getName') ->will($this->returnValue('baz')); $this->dir->addChild($this->mockChild2); } /** * clean up test environment */ public function tearDown() { vfsStream::enableDotfiles(); } /** * @return array */ public function provideSwitchWithExpectations() { return array(array(function() { vfsStream::disableDotfiles(); }, array() ), array(function() { vfsStream::enableDotfiles(); }, array('.', '..') ) ); } private function getDirName($dir) { if (is_string($dir)) { return $dir; } return $dir->getName(); } /** * @param \Closure $dotFilesSwitch * @param array $dirNames * @test * @dataProvider provideSwitchWithExpectations */ public function iteration(\Closure $dotFilesSwitch, array $dirs) { $dirs[] = $this->mockChild1; $dirs[] = $this->mockChild2; $dotFilesSwitch(); $dirIterator = $this->dir->getIterator(); foreach ($dirs as $dir) { $this->assertEquals($this->getDirName($dir), $dirIterator->key()); $this->assertTrue($dirIterator->valid()); if (!is_string($dir)) { $this->assertSame($dir, $dirIterator->current()); } $dirIterator->next(); } $this->assertFalse($dirIterator->valid()); $this->assertNull($dirIterator->key()); $this->assertNull($dirIterator->current()); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue134TestCase.php000066400000000000000000000026221355632626400301720ustar00rootroot00000000000000rootDirectory = vfsStream::newDirectory('/'); $this->rootDirectory->addChild(vfsStream::newDirectory('var/log/app')); } /** * Test: should save directory name as string internal * * @small */ public function testShouldSaveDirectoryNameAsStringInternal() { $dir = $this->rootDirectory->getChild('var/log/app'); $dir->addChild(vfsStream::newDirectory(80)); static::assertNotNull($this->rootDirectory->getChild('var/log/app/80')); } /** * Test: should rename directory name as string internal * * @small */ public function testShouldRenameDirectoryNameAsStringInternal() { $dir = $this->rootDirectory->getChild('var/log/app'); $dir->addChild(vfsStream::newDirectory(80)); $child = $this->rootDirectory->getChild('var/log/app/80'); $child->rename(90); static::assertNotNull($this->rootDirectory->getChild('var/log/app/90')); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue18TestCase.php000066400000000000000000000043741355632626400301210ustar00rootroot00000000000000rootDirectory = vfsStream::newDirectory('/'); $this->rootDirectory->addChild(vfsStream::newDirectory('var/log/app')); $dir = $this->rootDirectory->getChild('var/log/app'); $dir->addChild(vfsStream::newDirectory('app1')); $dir->addChild(vfsStream::newDirectory('app2')); $dir->addChild(vfsStream::newDirectory('foo')); } /** * @test */ public function shouldContainThreeSubdirectories() { $this->assertEquals(3, count($this->rootDirectory->getChild('var/log/app')->getChildren()) ); } /** * @test */ public function shouldContainSubdirectoryFoo() { $this->assertTrue($this->rootDirectory->getChild('var/log/app')->hasChild('foo')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $this->rootDirectory->getChild('var/log/app')->getChild('foo') ); } /** * @test */ public function shouldContainSubdirectoryApp1() { $this->assertTrue($this->rootDirectory->getChild('var/log/app')->hasChild('app1')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $this->rootDirectory->getChild('var/log/app')->getChild('app1') ); } /** * @test */ public function shouldContainSubdirectoryApp2() { $this->assertTrue($this->rootDirectory->getChild('var/log/app')->hasChild('app2')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $this->rootDirectory->getChild('var/log/app')->getChild('app2') ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamDirectoryTestCase.php000066400000000000000000000257541355632626400267440ustar00rootroot00000000000000dir = new vfsStreamDirectory('foo'); } /** * assure that a directory seperator inside the name throws an exception * * @test * @expectedException org\bovigo\vfs\vfsStreamException */ public function invalidCharacterInName() { $dir = new vfsStreamDirectory('foo/bar'); } /** * test default values and methods * * @test */ public function defaultValues() { $this->assertEquals(vfsStreamContent::TYPE_DIR, $this->dir->getType()); $this->assertEquals('foo', $this->dir->getName()); $this->assertTrue($this->dir->appliesTo('foo')); $this->assertTrue($this->dir->appliesTo('foo/bar')); $this->assertFalse($this->dir->appliesTo('bar')); $this->assertEquals(array(), $this->dir->getChildren()); } /** * test renaming the directory * * @test */ public function rename() { $this->dir->rename('bar'); $this->assertEquals('bar', $this->dir->getName()); $this->assertFalse($this->dir->appliesTo('foo')); $this->assertFalse($this->dir->appliesTo('foo/bar')); $this->assertTrue($this->dir->appliesTo('bar')); } /** * renaming the directory to an invalid name throws a vfsStreamException * * @test * @expectedException org\bovigo\vfs\vfsStreamException */ public function renameToInvalidNameThrowsvfsStreamException() { $this->dir->rename('foo/baz'); } /** * @test * @since 0.10.0 */ public function hasNoChildrenByDefault() { $this->assertFalse($this->dir->hasChildren()); } /** * @test * @since 0.10.0 */ public function hasChildrenReturnsTrueIfAtLeastOneChildPresent() { $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockChild->expects($this->any()) ->method('appliesTo') ->will($this->returnValue(false)); $mockChild->expects($this->any()) ->method('getName') ->will($this->returnValue('baz')); $this->dir->addChild($mockChild); $this->assertTrue($this->dir->hasChildren()); } /** * @test */ public function hasChildReturnsFalseForNonExistingChild() { $this->assertFalse($this->dir->hasChild('bar')); } /** * @test */ public function getChildReturnsNullForNonExistingChild() { $this->assertNull($this->dir->getChild('bar')); } /** * @test */ public function removeChildReturnsFalseForNonExistingChild() { $this->assertFalse($this->dir->removeChild('bar')); } /** * @test */ public function nonExistingChild() { $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockChild->expects($this->any()) ->method('appliesTo') ->will($this->returnValue(false)); $mockChild->expects($this->any()) ->method('getName') ->will($this->returnValue('baz')); $this->dir->addChild($mockChild); $this->assertFalse($this->dir->removeChild('bar')); } /** * test that adding, handling and removing of a child works as expected * * @test */ public function childHandling() { $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockChild->expects($this->any()) ->method('getType') ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); $mockChild->expects($this->any()) ->method('getName') ->will($this->returnValue('bar')); $mockChild->expects($this->any()) ->method('appliesTo') ->with($this->equalTo('bar')) ->will($this->returnValue(true)); $mockChild->expects($this->once()) ->method('size') ->will($this->returnValue(5)); $this->dir->addChild($mockChild); $this->assertTrue($this->dir->hasChild('bar')); $bar = $this->dir->getChild('bar'); $this->assertSame($mockChild, $bar); $this->assertEquals(array($mockChild), $this->dir->getChildren()); $this->assertEquals(0, $this->dir->size()); $this->assertEquals(5, $this->dir->sizeSummarized()); $this->assertTrue($this->dir->removeChild('bar')); $this->assertEquals(array(), $this->dir->getChildren()); $this->assertEquals(0, $this->dir->size()); $this->assertEquals(0, $this->dir->sizeSummarized()); } /** * test that adding, handling and removing of a child works as expected * * @test */ public function childHandlingWithSubdirectory() { $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockChild->expects($this->any()) ->method('getType') ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); $mockChild->expects($this->any()) ->method('getName') ->will($this->returnValue('bar')); $mockChild->expects($this->once()) ->method('size') ->will($this->returnValue(5)); $subdir = new vfsStreamDirectory('subdir'); $subdir->addChild($mockChild); $this->dir->addChild($subdir); $this->assertTrue($this->dir->hasChild('subdir')); $this->assertSame($subdir, $this->dir->getChild('subdir')); $this->assertEquals(array($subdir), $this->dir->getChildren()); $this->assertEquals(0, $this->dir->size()); $this->assertEquals(5, $this->dir->sizeSummarized()); $this->assertTrue($this->dir->removeChild('subdir')); $this->assertEquals(array(), $this->dir->getChildren()); $this->assertEquals(0, $this->dir->size()); $this->assertEquals(0, $this->dir->sizeSummarized()); } /** * dd * * @test * @group regression * @group bug_5 */ public function addChildReplacesChildWithSameName_Bug_5() { $mockChild1 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockChild1->expects($this->any()) ->method('getType') ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); $mockChild1->expects($this->any()) ->method('getName') ->will($this->returnValue('bar')); $mockChild2 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockChild2->expects($this->any()) ->method('getType') ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); $mockChild2->expects($this->any()) ->method('getName') ->will($this->returnValue('bar')); $this->dir->addChild($mockChild1); $this->assertTrue($this->dir->hasChild('bar')); $this->assertSame($mockChild1, $this->dir->getChild('bar')); $this->dir->addChild($mockChild2); $this->assertTrue($this->dir->hasChild('bar')); $this->assertSame($mockChild2, $this->dir->getChild('bar')); } /** * When testing for a nested path, verify that directory separators are respected properly * so that subdir1/subdir2 is not considered equal to subdir1Xsubdir2. * * @test * @group bug_24 * @group regression */ public function explicitTestForSeparatorWithNestedPaths_Bug_24() { $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockChild->expects($this->any()) ->method('getType') ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); $mockChild->expects($this->any()) ->method('getName') ->will($this->returnValue('bar')); $subdir1 = new vfsStreamDirectory('subdir1'); $this->dir->addChild($subdir1); $subdir2 = new vfsStreamDirectory('subdir2'); $subdir1->addChild($subdir2); $subdir2->addChild($mockChild); $this->assertTrue($this->dir->hasChild('subdir1'), "Level 1 path with separator exists"); $this->assertTrue($this->dir->hasChild('subdir1/subdir2'), "Level 2 path with separator exists"); $this->assertTrue($this->dir->hasChild('subdir1/subdir2/bar'), "Level 3 path with separator exists"); $this->assertFalse($this->dir->hasChild('subdir1.subdir2'), "Path with period does not exist"); $this->assertFalse($this->dir->hasChild('subdir1.subdir2/bar'), "Nested path with period does not exist"); } /** * setting and retrieving permissions for a directory * * @test * @group permissions */ public function permissions() { $this->assertEquals(0777, $this->dir->getPermissions()); $this->assertSame($this->dir, $this->dir->chmod(0755)); $this->assertEquals(0755, $this->dir->getPermissions()); } /** * setting and retrieving permissions for a directory * * @test * @group permissions */ public function permissionsSet() { $this->dir = new vfsStreamDirectory('foo', 0755); $this->assertEquals(0755, $this->dir->getPermissions()); $this->assertSame($this->dir, $this->dir->chmod(0700)); $this->assertEquals(0700, $this->dir->getPermissions()); } /** * setting and retrieving owner of a file * * @test * @group permissions */ public function owner() { $this->assertEquals(vfsStream::getCurrentUser(), $this->dir->getUser()); $this->assertTrue($this->dir->isOwnedByUser(vfsStream::getCurrentUser())); $this->assertSame($this->dir, $this->dir->chown(vfsStream::OWNER_USER_1)); $this->assertEquals(vfsStream::OWNER_USER_1, $this->dir->getUser()); $this->assertTrue($this->dir->isOwnedByUser(vfsStream::OWNER_USER_1)); } /** * setting and retrieving owner group of a file * * @test * @group permissions */ public function group() { $this->assertEquals(vfsStream::getCurrentGroup(), $this->dir->getGroup()); $this->assertTrue($this->dir->isOwnedByGroup(vfsStream::getCurrentGroup())); $this->assertSame($this->dir, $this->dir->chgrp(vfsStream::GROUP_USER_1)); $this->assertEquals(vfsStream::GROUP_USER_1, $this->dir->getGroup()); $this->assertTrue($this->dir->isOwnedByGroup(vfsStream::GROUP_USER_1)); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamExLockTestCase.php000066400000000000000000000030261355632626400261510ustar00rootroot00000000000000at($root); } /** * This test verifies the current behaviour where vfsStream URLs do not work * with file_put_contents() and LOCK_EX. The test is intended to break once * PHP changes this so we get notified about the change. * * @test */ public function filePutContentsLockShouldReportError() { @file_put_contents(vfsStream::url('root/testfile'), "some string\n", LOCK_EX); $php_error = error_get_last(); $this->assertEquals("file_put_contents(): Exclusive locks may only be set for regular files", $php_error['message']); } /** * @test */ public function flockSouldPass() { $fp = fopen(vfsStream::url('root/testfile'), 'w'); flock($fp, LOCK_EX); fwrite($fp, "another string\n"); flock($fp, LOCK_UN); fclose($fp); $this->assertEquals("another string\n", file_get_contents(vfsStream::url('root/testfile'))); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamFileTestCase.php000066400000000000000000000262421355632626400256500ustar00rootroot00000000000000file = new vfsStreamFile('foo'); } /** * test default values and methods * * @test */ public function defaultValues() { $this->assertEquals(vfsStreamContent::TYPE_FILE, $this->file->getType()); $this->assertEquals('foo', $this->file->getName()); $this->assertTrue($this->file->appliesTo('foo')); $this->assertFalse($this->file->appliesTo('foo/bar')); $this->assertFalse($this->file->appliesTo('bar')); } /** * test setting and getting the content of a file * * @test */ public function content() { $this->assertNull($this->file->getContent()); $this->assertSame($this->file, $this->file->setContent('bar')); $this->assertEquals('bar', $this->file->getContent()); $this->assertSame($this->file, $this->file->withContent('baz')); $this->assertEquals('baz', $this->file->getContent()); } /** * test renaming the directory * * @test */ public function rename() { $this->file->rename('bar'); $this->assertEquals('bar', $this->file->getName()); $this->assertFalse($this->file->appliesTo('foo')); $this->assertFalse($this->file->appliesTo('foo/bar')); $this->assertTrue($this->file->appliesTo('bar')); } /** * test reading contents from the file * * @test */ public function readEmptyFile() { $this->assertTrue($this->file->eof()); $this->assertEquals(0, $this->file->size()); $this->assertEquals('', $this->file->read(5)); $this->assertEquals(5, $this->file->getBytesRead()); $this->assertTrue($this->file->eof()); } /** * test reading contents from the file * * @test */ public function read() { $this->file->setContent('foobarbaz'); $this->assertFalse($this->file->eof()); $this->assertEquals(9, $this->file->size()); $this->assertEquals('foo', $this->file->read(3)); $this->assertEquals(3, $this->file->getBytesRead()); $this->assertFalse($this->file->eof()); $this->assertEquals(9, $this->file->size()); $this->assertEquals('bar', $this->file->read(3)); $this->assertEquals(6, $this->file->getBytesRead()); $this->assertFalse($this->file->eof()); $this->assertEquals(9, $this->file->size()); $this->assertEquals('baz', $this->file->read(3)); $this->assertEquals(9, $this->file->getBytesRead()); $this->assertEquals(9, $this->file->size()); $this->assertTrue($this->file->eof()); $this->assertEquals('', $this->file->read(3)); } /** * test seeking to offset * * @test */ public function seekEmptyFile() { $this->assertFalse($this->file->seek(0, 55)); $this->assertTrue($this->file->seek(0, SEEK_SET)); $this->assertEquals(0, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(5, SEEK_SET)); $this->assertEquals(5, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(0, SEEK_CUR)); $this->assertEquals(5, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(2, SEEK_CUR)); $this->assertEquals(7, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(0, SEEK_END)); $this->assertEquals(0, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(2, SEEK_END)); $this->assertEquals(2, $this->file->getBytesRead()); } /** * @test * @since 1.6.5 */ public function seekEmptyFileBeforeBeginningDoesNotChangeOffset() { $this->assertFalse($this->file->seek(-5, SEEK_SET), 'Seek before beginning of file'); $this->assertEquals(0, $this->file->getBytesRead()); } /** * test seeking to offset * * @test */ public function seekRead() { $this->file->setContent('foobarbaz'); $this->assertFalse($this->file->seek(0, 55)); $this->assertTrue($this->file->seek(0, SEEK_SET)); $this->assertEquals('foobarbaz', $this->file->readUntilEnd()); $this->assertEquals(0, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(5, SEEK_SET)); $this->assertEquals('rbaz', $this->file->readUntilEnd()); $this->assertEquals(5, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(0, SEEK_CUR)); $this->assertEquals('rbaz', $this->file->readUntilEnd()); $this->assertEquals(5, $this->file->getBytesRead(), 5); $this->assertTrue($this->file->seek(2, SEEK_CUR)); $this->assertEquals('az', $this->file->readUntilEnd()); $this->assertEquals(7, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(0, SEEK_END)); $this->assertEquals('', $this->file->readUntilEnd()); $this->assertEquals(9, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(2, SEEK_END)); $this->assertEquals('', $this->file->readUntilEnd()); $this->assertEquals(11, $this->file->getBytesRead()); } /** * @test * @since 1.6.5 */ public function seekFileBeforeBeginningDoesNotChangeOffset() { $this->file->setContent('foobarbaz'); $this->assertFalse($this->file->seek(-5, SEEK_SET), 'Seek before beginning of file'); $this->assertEquals(0, $this->file->getBytesRead()); $this->assertTrue($this->file->seek(2, SEEK_CUR)); $this->assertFalse($this->file->seek(-5, SEEK_SET), 'Seek before beginning of file'); $this->assertEquals(2, $this->file->getBytesRead()); $this->assertEquals('obarbaz', $this->file->readUntilEnd()); $this->assertFalse($this->file->seek(-5, SEEK_CUR), 'Seek before beginning of file'); $this->assertEquals(2, $this->file->getBytesRead()); $this->assertEquals('obarbaz', $this->file->readUntilEnd()); $this->assertFalse($this->file->seek(-20, SEEK_END), 'Seek before beginning of file'); $this->assertEquals(2, $this->file->getBytesRead()); $this->assertEquals('obarbaz', $this->file->readUntilEnd()); } /** * test writing data into the file * * @test */ public function writeEmptyFile() { $this->assertEquals(3, $this->file->write('foo')); $this->assertEquals('foo', $this->file->getContent()); $this->assertEquals(3, $this->file->size()); $this->assertEquals(3, $this->file->write('bar')); $this->assertEquals('foobar', $this->file->getContent()); $this->assertEquals(6, $this->file->size()); } /** * test writing data into the file * * @test */ public function write() { $this->file->setContent('foobarbaz'); $this->assertTrue($this->file->seek(3, SEEK_SET)); $this->assertEquals(3, $this->file->write('foo')); $this->assertEquals('foofoobaz', $this->file->getContent()); $this->assertEquals(9, $this->file->size()); $this->assertEquals(3, $this->file->write('bar')); $this->assertEquals('foofoobar', $this->file->getContent()); $this->assertEquals(9, $this->file->size()); } /** * setting and retrieving permissions for a file * * @test * @group permissions */ public function permissions() { $this->assertEquals(0666, $this->file->getPermissions()); $this->assertSame($this->file, $this->file->chmod(0644)); $this->assertEquals(0644, $this->file->getPermissions()); } /** * setting and retrieving permissions for a file * * @test * @group permissions */ public function permissionsSet() { $this->file = new vfsStreamFile('foo', 0644); $this->assertEquals(0644, $this->file->getPermissions()); $this->assertSame($this->file, $this->file->chmod(0600)); $this->assertEquals(0600, $this->file->getPermissions()); } /** * setting and retrieving owner of a file * * @test * @group permissions */ public function owner() { $this->assertEquals(vfsStream::getCurrentUser(), $this->file->getUser()); $this->assertTrue($this->file->isOwnedByUser(vfsStream::getCurrentUser())); $this->assertSame($this->file, $this->file->chown(vfsStream::OWNER_USER_1)); $this->assertEquals(vfsStream::OWNER_USER_1, $this->file->getUser()); $this->assertTrue($this->file->isOwnedByUser(vfsStream::OWNER_USER_1)); } /** * setting and retrieving owner group of a file * * @test * @group permissions */ public function group() { $this->assertEquals(vfsStream::getCurrentGroup(), $this->file->getGroup()); $this->assertTrue($this->file->isOwnedByGroup(vfsStream::getCurrentGroup())); $this->assertSame($this->file, $this->file->chgrp(vfsStream::GROUP_USER_1)); $this->assertEquals(vfsStream::GROUP_USER_1, $this->file->getGroup()); $this->assertTrue($this->file->isOwnedByGroup(vfsStream::GROUP_USER_1)); } /** * @test * @group issue_33 * @since 1.1.0 */ public function truncateRemovesSuperflouosContent() { $this->assertEquals(11, $this->file->write("lorem ipsum")); $this->assertTrue($this->file->truncate(5)); $this->assertEquals(5, $this->file->size()); $this->assertEquals('lorem', $this->file->getContent()); } /** * @test * @group issue_33 * @since 1.1.0 */ public function truncateToGreaterSizeAddsZeroBytes() { $this->assertEquals(11, $this->file->write("lorem ipsum")); $this->assertTrue($this->file->truncate(25)); $this->assertEquals(25, $this->file->size()); $this->assertEquals("lorem ipsum\0\0\0\0\0\0\0\0\0\0\0\0\0\0", $this->file->getContent()); } /** * @test * @group issue_79 * @since 1.3.0 */ public function withContentAcceptsAnyFileContentInstance() { $mockFileContent = $this->bc_getMock('org\bovigo\vfs\content\FileContent'); $mockFileContent->expects($this->once()) ->method('content') ->will($this->returnValue('foobarbaz')); $this->assertEquals( 'foobarbaz', $this->file->withContent($mockFileContent) ->getContent() ); } /** * @test * @group issue_79 * @expectedException \InvalidArgumentException * @since 1.3.0 */ public function withContentThrowsInvalidArgumentExceptionWhenContentIsNoStringAndNoFileContent() { $this->file->withContent(313); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamGlobTestCase.php000066400000000000000000000012431355632626400256460ustar00rootroot00000000000000assertEmpty(glob(vfsStream::url('example'), GLOB_MARK)); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamResolveIncludePathTestCase.php000066400000000000000000000026401355632626400305250ustar00rootroot00000000000000backupIncludePath = get_include_path(); vfsStream::setup(); mkdir('vfs://root/a/path', 0777, true); set_include_path('vfs://root/a' . PATH_SEPARATOR . $this->backupIncludePath); } /** * clean up test environment */ public function tearDown() { set_include_path($this->backupIncludePath); } /** * @test */ public function knownFileCanBeResolved() { file_put_contents('vfs://root/a/path/knownFile.php', ''); $this->assertEquals('vfs://root/a/path/knownFile.php', stream_resolve_include_path('path/knownFile.php')); } /** * @test */ public function unknownFileCanNotBeResolvedYieldsFalse() { $this->assertFalse(@stream_resolve_include_path('path/unknownFile.php')); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php000066400000000000000000000614011355632626400250440ustar00rootroot00000000000000assertEquals('vfs://foo', vfsStream::url('foo')); $this->assertEquals('vfs://foo/bar.baz', vfsStream::url('foo/bar.baz')); $this->assertEquals('vfs://foo/bar.baz', vfsStream::url('foo\bar.baz')); } /** * assure that url2path conversion works correct * * @test */ public function path() { $this->assertEquals('foo', vfsStream::path('vfs://foo')); $this->assertEquals('foo/bar.baz', vfsStream::path('vfs://foo/bar.baz')); $this->assertEquals('foo/bar.baz', vfsStream::path('vfs://foo\bar.baz')); } /** * windows directory separators are converted into default separator * * @author Gabriel Birke * @test */ public function pathConvertsWindowsDirectorySeparators() { $this->assertEquals('foo/bar', vfsStream::path('vfs://foo\\bar')); } /** * trailing whitespace should be removed * * @author Gabriel Birke * @test */ public function pathRemovesTrailingWhitespace() { $this->assertEquals('foo/bar', vfsStream::path('vfs://foo/bar ')); } /** * trailing slashes are removed * * @author Gabriel Birke * @test */ public function pathRemovesTrailingSlash() { $this->assertEquals('foo/bar', vfsStream::path('vfs://foo/bar/')); } /** * trailing slash and whitespace should be removed * * @author Gabriel Birke * @test */ public function pathRemovesTrailingSlashAndWhitespace() { $this->assertEquals('foo/bar', vfsStream::path('vfs://foo/bar/ ')); } /** * double slashes should be replaced by single slash * * @author Gabriel Birke * @test */ public function pathRemovesDoubleSlashes() { // Regular path $this->assertEquals('my/path', vfsStream::path('vfs://my/path')); // Path with double slashes $this->assertEquals('my/path', vfsStream::path('vfs://my//path')); } /** * test to create a new file * * @test */ public function newFile() { $file = vfsStream::newFile('filename.txt'); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamFile', $file); $this->assertEquals('filename.txt', $file->getName()); $this->assertEquals(0666, $file->getPermissions()); } /** * test to create a new file with non-default permissions * * @test * @group permissions */ public function newFileWithDifferentPermissions() { $file = vfsStream::newFile('filename.txt', 0644); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamFile', $file); $this->assertEquals('filename.txt', $file->getName()); $this->assertEquals(0644, $file->getPermissions()); } /** * test to create a new directory structure * * @test */ public function newSingleDirectory() { $foo = vfsStream::newDirectory('foo'); $this->assertEquals('foo', $foo->getName()); $this->assertEquals(0, count($foo->getChildren())); $this->assertEquals(0777, $foo->getPermissions()); } /** * test to create a new directory structure with non-default permissions * * @test * @group permissions */ public function newSingleDirectoryWithDifferentPermissions() { $foo = vfsStream::newDirectory('foo', 0755); $this->assertEquals('foo', $foo->getName()); $this->assertEquals(0, count($foo->getChildren())); $this->assertEquals(0755, $foo->getPermissions()); } /** * test to create a new directory structure * * @test */ public function newDirectoryStructure() { $foo = vfsStream::newDirectory('foo/bar/baz'); $this->assertEquals('foo', $foo->getName()); $this->assertEquals(0777, $foo->getPermissions()); $this->assertTrue($foo->hasChild('bar')); $this->assertTrue($foo->hasChild('bar/baz')); $this->assertFalse($foo->hasChild('baz')); $bar = $foo->getChild('bar'); $this->assertEquals('bar', $bar->getName()); $this->assertEquals(0777, $bar->getPermissions()); $this->assertTrue($bar->hasChild('baz')); $baz1 = $bar->getChild('baz'); $this->assertEquals('baz', $baz1->getName()); $this->assertEquals(0777, $baz1->getPermissions()); $baz2 = $foo->getChild('bar/baz'); $this->assertSame($baz1, $baz2); } /** * test that correct directory structure is created * * @test */ public function newDirectoryWithSlashAtStart() { $foo = vfsStream::newDirectory('/foo/bar/baz', 0755); $this->assertEquals('foo', $foo->getName()); $this->assertEquals(0755, $foo->getPermissions()); $this->assertTrue($foo->hasChild('bar')); $this->assertTrue($foo->hasChild('bar/baz')); $this->assertFalse($foo->hasChild('baz')); $bar = $foo->getChild('bar'); $this->assertEquals('bar', $bar->getName()); $this->assertEquals(0755, $bar->getPermissions()); $this->assertTrue($bar->hasChild('baz')); $baz1 = $bar->getChild('baz'); $this->assertEquals('baz', $baz1->getName()); $this->assertEquals(0755, $baz1->getPermissions()); $baz2 = $foo->getChild('bar/baz'); $this->assertSame($baz1, $baz2); } /** * @test * @group setup * @since 0.7.0 */ public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithDefaultNameAndPermissions() { $root = vfsStream::setup(); $this->assertSame($root, vfsStreamWrapper::getRoot()); $this->assertEquals('root', $root->getName()); $this->assertEquals(0777, $root->getPermissions()); } /** * @test * @group setup * @since 0.7.0 */ public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithGivenNameAndDefaultPermissions() { $root = vfsStream::setup('foo'); $this->assertSame($root, vfsStreamWrapper::getRoot()); $this->assertEquals('foo', $root->getName()); $this->assertEquals(0777, $root->getPermissions()); } /** * @test * @group setup * @since 0.7.0 */ public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithGivenNameAndPermissions() { $root = vfsStream::setup('foo', 0444); $this->assertSame($root, vfsStreamWrapper::getRoot()); $this->assertEquals('foo', $root->getName()); $this->assertEquals(0444, $root->getPermissions()); } /** * @test * @group issue_14 * @group issue_20 * @since 0.10.0 */ public function setupWithEmptyArrayIsEqualToSetup() { $root = vfsStream::setup('example', 0755, array() ); $this->assertEquals('example', $root->getName()); $this->assertEquals(0755, $root->getPermissions()); $this->assertFalse($root->hasChildren()); } /** * @test * @group issue_14 * @group issue_20 * @since 0.10.0 */ public function setupArraysAreTurnedIntoSubdirectories() { $root = vfsStream::setup('root', null, array('test' => array()) ); $this->assertTrue($root->hasChildren()); $this->assertTrue($root->hasChild('test')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $root->getChild('test') ); $this->assertFalse($root->getChild('test')->hasChildren()); } /** * @test * @group issue_14 * @group issue_20 * @since 0.10.0 */ public function setupStringsAreTurnedIntoFilesWithContent() { $root = vfsStream::setup('root', null, array('test.txt' => 'some content') ); $this->assertTrue($root->hasChildren()); $this->assertTrue($root->hasChild('test.txt')); $this->assertVfsFile($root->getChild('test.txt'), 'some content'); } /** * @test * @group issue_14 * @group issue_20 * @since 0.10.0 */ public function setupWorksRecursively() { $root = vfsStream::setup('root', null, array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world' ) ) ); $this->assertTrue($root->hasChildren()); $this->assertTrue($root->hasChild('test')); $test = $root->getChild('test'); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $test); $this->assertTrue($test->hasChildren()); $this->assertTrue($test->hasChild('baz.txt')); $this->assertVfsFile($test->getChild('baz.txt'), 'world'); $this->assertTrue($test->hasChild('foo')); $foo = $test->getChild('foo'); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $foo); $this->assertTrue($foo->hasChildren()); $this->assertTrue($foo->hasChild('test.txt')); $this->assertVfsFile($foo->getChild('test.txt'), 'hello'); } /** * @test * @group issue_17 * @group issue_20 */ public function setupCastsNumericDirectoriesToStrings() { $root = vfsStream::setup('root', null, array(2011 => array ('test.txt' => 'some content')) ); $this->assertTrue($root->hasChild('2011')); $directory = $root->getChild('2011'); $this->assertVfsFile($directory->getChild('test.txt'), 'some content'); $this->assertTrue(file_exists('vfs://root/2011/test.txt')); } /** * @test * @group issue_20 * @since 0.11.0 */ public function createArraysAreTurnedIntoSubdirectories() { $baseDir = vfsStream::create(array('test' => array()), new vfsStreamDirectory('baseDir')); $this->assertTrue($baseDir->hasChildren()); $this->assertTrue($baseDir->hasChild('test')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $baseDir->getChild('test') ); $this->assertFalse($baseDir->getChild('test')->hasChildren()); } /** * @test * @group issue_20 * @since 0.11.0 */ public function createArraysAreTurnedIntoSubdirectoriesOfRoot() { $root = vfsStream::setup(); $this->assertSame($root, vfsStream::create(array('test' => array()))); $this->assertTrue($root->hasChildren()); $this->assertTrue($root->hasChild('test')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $root->getChild('test') ); $this->assertFalse($root->getChild('test')->hasChildren()); } /** * @test * @group issue_20 * @expectedException \InvalidArgumentException * @since 0.11.0 */ public function createThrowsExceptionIfNoBaseDirGivenAndNoRootSet() { vfsStream::create(array('test' => array())); } /** * @test * @group issue_20 * @since 0.11.0 */ public function createWorksRecursively() { $baseDir = vfsStream::create(array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world' ) ), new vfsStreamDirectory('baseDir') ); $this->assertTrue($baseDir->hasChildren()); $this->assertTrue($baseDir->hasChild('test')); $test = $baseDir->getChild('test'); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $test); $this->assertTrue($test->hasChildren()); $this->assertTrue($test->hasChild('baz.txt')); $this->assertVfsFile($test->getChild('baz.txt'), 'world'); $this->assertTrue($test->hasChild('foo')); $foo = $test->getChild('foo'); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $foo); $this->assertTrue($foo->hasChildren()); $this->assertTrue($foo->hasChild('test.txt')); $this->assertVfsFile($foo->getChild('test.txt'), 'hello'); } /** * @test * @group issue_20 * @since 0.11.0 */ public function createWorksRecursivelyWithRoot() { $root = vfsStream::setup(); $this->assertSame($root, vfsStream::create(array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world' ) ) ) ); $this->assertTrue($root->hasChildren()); $this->assertTrue($root->hasChild('test')); $test = $root->getChild('test'); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $test); $this->assertTrue($test->hasChildren()); $this->assertTrue($test->hasChild('baz.txt')); $this->assertVfsFile($test->getChild('baz.txt'), 'world'); $this->assertTrue($test->hasChild('foo')); $foo = $test->getChild('foo'); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $foo); $this->assertTrue($foo->hasChildren()); $this->assertTrue($foo->hasChild('test.txt')); $this->assertVfsFile($foo->getChild('test.txt'), 'hello'); } /** * @test * @group issue_20 * @since 0.10.0 */ public function createStringsAreTurnedIntoFilesWithContent() { $baseDir = vfsStream::create(array('test.txt' => 'some content'), new vfsStreamDirectory('baseDir')); $this->assertTrue($baseDir->hasChildren()); $this->assertTrue($baseDir->hasChild('test.txt')); $this->assertVfsFile($baseDir->getChild('test.txt'), 'some content'); } /** * @test * @group issue_20 * @since 0.11.0 */ public function createStringsAreTurnedIntoFilesWithContentWithRoot() { $root = vfsStream::setup(); $this->assertSame($root, vfsStream::create(array('test.txt' => 'some content')) ); $this->assertTrue($root->hasChildren()); $this->assertTrue($root->hasChild('test.txt')); $this->assertVfsFile($root->getChild('test.txt'), 'some content'); } /** * @test * @group issue_20 * @since 0.11.0 */ public function createCastsNumericDirectoriesToStrings() { $baseDir = vfsStream::create(array(2011 => array ('test.txt' => 'some content')), new vfsStreamDirectory('baseDir')); $this->assertTrue($baseDir->hasChild('2011')); $directory = $baseDir->getChild('2011'); $this->assertVfsFile($directory->getChild('test.txt'), 'some content'); } /** * @test * @group issue_20 * @since 0.11.0 */ public function createCastsNumericDirectoriesToStringsWithRoot() { $root = vfsStream::setup(); $this->assertSame($root, vfsStream::create(array(2011 => array ('test.txt' => 'some content'))) ); $this->assertTrue($root->hasChild('2011')); $directory = $root->getChild('2011'); $this->assertVfsFile($directory->getChild('test.txt'), 'some content'); } /** * helper function for assertions on vfsStreamFile * * @param vfsStreamFile $file * @param string $content */ protected function assertVfsFile(vfsStreamFile $file, $content) { $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamFile', $file ); $this->assertEquals($content, $file->getContent() ); } /** * @test * @group issue_10 * @since 0.10.0 */ public function inspectWithContentGivesContentToVisitor() { $mockContent = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockVisitor = $this->bc_getMock('org\\bovigo\\vfs\\visitor\\vfsStreamVisitor'); $mockVisitor->expects($this->once()) ->method('visit') ->with($this->equalTo($mockContent)) ->will($this->returnValue($mockVisitor)); $this->assertSame($mockVisitor, vfsStream::inspect($mockVisitor, $mockContent)); } /** * @test * @group issue_10 * @since 0.10.0 */ public function inspectWithoutContentGivesRootToVisitor() { $root = vfsStream::setup(); $mockVisitor = $this->bc_getMock('org\\bovigo\\vfs\\visitor\\vfsStreamVisitor'); $mockVisitor->expects($this->once()) ->method('visitDirectory') ->with($this->equalTo($root)) ->will($this->returnValue($mockVisitor)); $this->assertSame($mockVisitor, vfsStream::inspect($mockVisitor)); } /** * @test * @group issue_10 * @expectedException \InvalidArgumentException * @since 0.10.0 */ public function inspectWithoutContentAndWithoutRootThrowsInvalidArgumentException() { $mockVisitor = $this->bc_getMock('org\\bovigo\\vfs\\visitor\\vfsStreamVisitor'); $mockVisitor->expects($this->never()) ->method('visit'); $mockVisitor->expects($this->never()) ->method('visitDirectory'); vfsStream::inspect($mockVisitor); } /** * returns path to file system copy resource directory * * @return string */ protected function getFileSystemCopyDir() { return realpath(dirname(__FILE__) . '/../../../../resources/filesystemcopy'); } /** * @test * @group issue_4 * @expectedException \InvalidArgumentException * @since 0.11.0 */ public function copyFromFileSystemThrowsExceptionIfNoBaseDirGivenAndNoRootSet() { vfsStream::copyFromFileSystem($this->getFileSystemCopyDir()); } /** * @test * @group issue_4 * @since 0.11.0 */ public function copyFromEmptyFolder() { $baseDir = vfsStream::copyFromFileSystem($this->getFileSystemCopyDir() . '/emptyFolder', vfsStream::newDirectory('test') ); $baseDir->removeChild('.gitignore'); $this->assertFalse($baseDir->hasChildren()); } /** * @test * @group issue_4 * @since 0.11.0 */ public function copyFromEmptyFolderWithRoot() { $root = vfsStream::setup(); $this->assertEquals($root, vfsStream::copyFromFileSystem($this->getFileSystemCopyDir() . '/emptyFolder') ); $root->removeChild('.gitignore'); $this->assertFalse($root->hasChildren()); } /** * @test * @group issue_4 * @since 0.11.0 */ public function copyFromWithSubFolders() { $baseDir = vfsStream::copyFromFileSystem($this->getFileSystemCopyDir(), vfsStream::newDirectory('test'), 3 ); $this->assertTrue($baseDir->hasChildren()); $this->assertTrue($baseDir->hasChild('emptyFolder')); $this->assertTrue($baseDir->hasChild('withSubfolders')); $subfolderDir = $baseDir->getChild('withSubfolders'); $this->assertTrue($subfolderDir->hasChild('subfolder1')); $this->assertTrue($subfolderDir->getChild('subfolder1')->hasChild('file1.txt')); $this->assertVfsFile($subfolderDir->getChild('subfolder1/file1.txt'), ' '); $this->assertTrue($subfolderDir->hasChild('subfolder2')); $this->assertTrue($subfolderDir->hasChild('aFile.txt')); $this->assertVfsFile($subfolderDir->getChild('aFile.txt'), 'foo'); } /** * @test * @group issue_4 * @since 0.11.0 */ public function copyFromWithSubFoldersWithRoot() { $root = vfsStream::setup(); $this->assertEquals($root, vfsStream::copyFromFileSystem($this->getFileSystemCopyDir(), null, 3 ) ); $this->assertTrue($root->hasChildren()); $this->assertTrue($root->hasChild('emptyFolder')); $this->assertTrue($root->hasChild('withSubfolders')); $subfolderDir = $root->getChild('withSubfolders'); $this->assertTrue($subfolderDir->hasChild('subfolder1')); $this->assertTrue($subfolderDir->getChild('subfolder1')->hasChild('file1.txt')); $this->assertVfsFile($subfolderDir->getChild('subfolder1/file1.txt'), ' '); $this->assertTrue($subfolderDir->hasChild('subfolder2')); $this->assertTrue($subfolderDir->hasChild('aFile.txt')); $this->assertVfsFile($subfolderDir->getChild('aFile.txt'), 'foo'); } /** * @test * @group issue_4 * @group issue_29 * @since 0.11.2 */ public function copyFromPreservesFilePermissions() { if (DIRECTORY_SEPARATOR !== '/') { $this->markTestSkipped('Only applicable on Linux style systems.'); } $copyDir = $this->getFileSystemCopyDir(); $root = vfsStream::setup(); $this->assertEquals($root, vfsStream::copyFromFileSystem($copyDir, null ) ); $this->assertEquals(fileperms($copyDir . '/withSubfolders') - vfsStreamContent::TYPE_DIR, $root->getChild('withSubfolders') ->getPermissions() ); $this->assertEquals(fileperms($copyDir . '/withSubfolders/aFile.txt') - vfsStreamContent::TYPE_FILE, $root->getChild('withSubfolders/aFile.txt') ->getPermissions() ); } /** * To test this the max file size is reduced to something reproduceable. * * @test * @group issue_91 * @since 1.5.0 */ public function copyFromFileSystemMocksLargeFiles() { if (DIRECTORY_SEPARATOR !== '/') { $this->markTestSkipped('Only applicable on Linux style systems.'); } $copyDir = $this->getFileSystemCopyDir(); $root = vfsStream::setup(); vfsStream::copyFromFileSystem($copyDir, $root, 3); $this->assertEquals( ' ', $root->getChild('withSubfolders/subfolder1/file1.txt')->getContent() ); } /** * @test * @group issue_121 * @since 1.6.1 */ public function createDirectoryWithTrailingSlashShouldNotCreateSubdirectoryWithEmptyName() { $directory = vfsStream::newDirectory('foo/'); $this->assertFalse($directory->hasChildren()); } /** * @test * @group issue_149 */ public function addStructureHandlesVfsStreamFileObjects() { $structure = array( 'topLevel' => array( 'thisIsAFile' => 'file contents', vfsStream::newFile('anotherFile'), ), ); vfsStream::setup(); $root = vfsStream::create($structure); $this->assertTrue($root->hasChild('topLevel/anotherFile')); } /** * @test * @group issue_149 */ public function createHandlesLargeFileContentObjects() { $structure = array( 'topLevel' => array( 'thisIsAFile' => 'file contents', 'anotherFile' => LargeFileContent::withMegabytes(2), ), ); vfsStream::setup(); $root = vfsStream::create($structure); $this->assertTrue($root->hasChild('topLevel/anotherFile')); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamUmaskTestCase.php000066400000000000000000000113161355632626400260450ustar00rootroot00000000000000assertEquals(vfsStream::umask(), vfsStream::umask() ); $this->assertEquals(0000, vfsStream::umask() ); } /** * @test */ public function changingUmaskSettingReturnsOldUmaskSetting() { $this->assertEquals(0000, vfsStream::umask(0022) ); $this->assertEquals(0022, vfsStream::umask() ); } /** * @test */ public function createFileWithDefaultUmaskSetting() { $file = new vfsStreamFile('foo'); $this->assertEquals(0666, $file->getPermissions()); } /** * @test */ public function createFileWithDifferentUmaskSetting() { vfsStream::umask(0022); $file = new vfsStreamFile('foo'); $this->assertEquals(0644, $file->getPermissions()); } /** * @test */ public function createDirectoryWithDefaultUmaskSetting() { $directory = new vfsStreamDirectory('foo'); $this->assertEquals(0777, $directory->getPermissions()); } /** * @test */ public function createDirectoryWithDifferentUmaskSetting() { vfsStream::umask(0022); $directory = new vfsStreamDirectory('foo'); $this->assertEquals(0755, $directory->getPermissions()); } /** * @test */ public function createFileUsingStreamWithDefaultUmaskSetting() { $root = vfsStream::setup(); file_put_contents(vfsStream::url('root/newfile.txt'), 'file content'); $this->assertEquals(0666, $root->getChild('newfile.txt')->getPermissions()); } /** * @test */ public function createFileUsingStreamWithDifferentUmaskSetting() { $root = vfsStream::setup(); vfsStream::umask(0022); file_put_contents(vfsStream::url('root/newfile.txt'), 'file content'); $this->assertEquals(0644, $root->getChild('newfile.txt')->getPermissions()); } /** * @test */ public function createDirectoryUsingStreamWithDefaultUmaskSetting() { $root = vfsStream::setup(); mkdir(vfsStream::url('root/newdir')); $this->assertEquals(0777, $root->getChild('newdir')->getPermissions()); } /** * @test */ public function createDirectoryUsingStreamWithDifferentUmaskSetting() { $root = vfsStream::setup(); vfsStream::umask(0022); mkdir(vfsStream::url('root/newdir')); $this->assertEquals(0755, $root->getChild('newdir')->getPermissions()); } /** * @test */ public function createDirectoryUsingStreamWithExplicit0() { $root = vfsStream::setup(); vfsStream::umask(0022); mkdir(vfsStream::url('root/newdir'), null); $this->assertEquals(0000, $root->getChild('newdir')->getPermissions()); } /** * @test * */ public function createDirectoryUsingStreamWithDifferentUmaskSettingButExplicit0777() { $root = vfsStream::setup(); vfsStream::umask(0022); mkdir(vfsStream::url('root/newdir'), 0777); $this->assertEquals(0755, $root->getChild('newdir')->getPermissions()); } /** * @test */ public function createDirectoryUsingStreamWithDifferentUmaskSettingButExplicitModeRequestedByCall() { $root = vfsStream::setup(); vfsStream::umask(0022); mkdir(vfsStream::url('root/newdir'), 0700); $this->assertEquals(0700, $root->getChild('newdir')->getPermissions()); } /** * @test */ public function defaultUmaskSettingDoesNotInfluenceSetup() { $root = vfsStream::setup(); $this->assertEquals(0777, $root->getPermissions()); } /** * @test */ public function umaskSettingShouldBeRespectedBySetup() { vfsStream::umask(0022); $root = vfsStream::setup(); $this->assertEquals(0755, $root->getPermissions()); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperAlreadyRegisteredTestCase.php000066400000000000000000000027471355632626400317350ustar00rootroot00000000000000bc_getMock('org\\bovigo\\vfs\\vfsStreamWrapper'); stream_wrapper_register(vfsStream::SCHEME, get_class($mock)); } /** * clean up test environment */ public function tearDown() { TestvfsStreamWrapper::unregister(); } /** * registering the stream wrapper when another stream wrapper is already * registered for the vfs scheme should throw an exception * * @test * @expectedException org\bovigo\vfs\vfsStreamException */ public function registerOverAnotherStreamWrapper() { vfsStreamWrapper::register(); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperBaseTestCase.php000066400000000000000000000047561355632626400272120ustar00rootroot00000000000000fooURL = vfsStream::url('foo'); $this->barURL = vfsStream::url('foo/bar'); $this->baz1URL = vfsStream::url('foo/bar/baz1'); $this->baz2URL = vfsStream::url('foo/baz2'); $this->foo = new vfsStreamDirectory('foo'); $this->bar = new vfsStreamDirectory('bar'); $this->baz1 = vfsStream::newFile('baz1') ->lastModified(300) ->lastAccessed(300) ->lastAttributeModified(300) ->withContent('baz 1'); $this->baz2 = vfsStream::newFile('baz2') ->withContent('baz2') ->lastModified(400) ->lastAccessed(400) ->lastAttributeModified(400); $this->bar->addChild($this->baz1); $this->foo->addChild($this->bar); $this->foo->addChild($this->baz2); $this->foo->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); $this->bar->lastModified(200) ->lastAccessed(100) ->lastAttributeModified(100); vfsStreamWrapper::register(); vfsStreamWrapper::setRoot($this->foo); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirSeparatorTestCase.php000066400000000000000000000032501355632626400307230ustar00rootroot00000000000000root = vfsStream::setup(); } /** * @test */ public function fileCanBeAccessedUsingWinDirSeparator() { vfsStream::newFile('foo/bar/baz.txt') ->at($this->root) ->withContent('test'); $this->assertEquals('test', file_get_contents('vfs://root/foo\bar\baz.txt')); } /** * @test */ public function directoryCanBeCreatedUsingWinDirSeparator() { mkdir('vfs://root/dir\bar\foo', true, 0777); $this->assertTrue($this->root->hasChild('dir')); $this->assertTrue($this->root->getChild('dir')->hasChild('bar')); $this->assertTrue($this->root->getChild('dir/bar')->hasChild('foo')); } /** * @test */ public function directoryExitsTestUsingTrailingWinDirSeparator() { $structure = array( 'dir' => array( 'bar' => array( ) ) ); vfsStream::create($structure, $this->root); $this->assertTrue(file_exists(vfsStream::url('root/').'dir\\')); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirTestCase.php000066400000000000000000000360531355632626400270510ustar00rootroot00000000000000assertFalse(mkdir(vfsStream::url('another'))); $this->assertEquals(2, count($this->foo->getChildren())); $this->assertSame($this->foo, vfsStreamWrapper::getRoot()); } /** * mkdir() should not overwrite existing root * * @test */ public function mkdirNoNewRootRecursively() { $this->assertFalse(mkdir(vfsStream::url('another/more'), 0777, true)); $this->assertEquals(2, count($this->foo->getChildren())); $this->assertSame($this->foo, vfsStreamWrapper::getRoot()); } /** * assert that mkdir() creates the correct directory structure * * @test * @group permissions */ public function mkdirNonRecursively() { $this->assertFalse(mkdir($this->barURL . '/another/more')); $this->assertEquals(2, count($this->foo->getChildren())); $this->assertTrue(mkdir($this->fooURL . '/another')); $this->assertEquals(3, count($this->foo->getChildren())); $this->assertEquals(0777, $this->foo->getChild('another')->getPermissions()); } /** * assert that mkdir() creates the correct directory structure * * @test * @group permissions */ public function mkdirRecursively() { $this->assertTrue(mkdir($this->fooURL . '/another/more', 0777, true)); $this->assertEquals(3, count($this->foo->getChildren())); $another = $this->foo->getChild('another'); $this->assertTrue($another->hasChild('more')); $this->assertEquals(0777, $this->foo->getChild('another')->getPermissions()); $this->assertEquals(0777, $this->foo->getChild('another')->getChild('more')->getPermissions()); } /** * @test * @group issue_9 * @since 0.9.0 */ public function mkdirWithDots() { $this->assertTrue(mkdir($this->fooURL . '/another/../more/.', 0777, true)); $this->assertEquals(3, count($this->foo->getChildren())); $this->assertTrue($this->foo->hasChild('more')); } /** * no root > new directory becomes root * * @test * @group permissions */ public function mkdirWithoutRootCreatesNewRoot() { vfsStreamWrapper::register(); $this->assertTrue(@mkdir(vfsStream::url('foo'))); $this->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()->getType()); $this->assertEquals('foo', vfsStreamWrapper::getRoot()->getName()); $this->assertEquals(0777, vfsStreamWrapper::getRoot()->getPermissions()); } /** * trying to create a subdirectory of a file should not work * * @test */ public function mkdirOnFileReturnsFalse() { $this->assertFalse(mkdir($this->baz1URL . '/another/more', 0777, true)); } /** * assert that mkdir() creates the correct directory structure * * @test * @group permissions */ public function mkdirNonRecursivelyDifferentPermissions() { $this->assertTrue(mkdir($this->fooURL . '/another', 0755)); $this->assertEquals(0755, $this->foo->getChild('another')->getPermissions()); } /** * assert that mkdir() creates the correct directory structure * * @test * @group permissions */ public function mkdirRecursivelyDifferentPermissions() { $this->assertTrue(mkdir($this->fooURL . '/another/more', 0755, true)); $this->assertEquals(3, count($this->foo->getChildren())); $another = $this->foo->getChild('another'); $this->assertTrue($another->hasChild('more')); $this->assertEquals(0755, $this->foo->getChild('another')->getPermissions()); $this->assertEquals(0755, $this->foo->getChild('another')->getChild('more')->getPermissions()); } /** * assert that mkdir() creates the correct directory structure * * @test * @group permissions */ public function mkdirRecursivelyUsesDefaultPermissions() { $this->foo->chmod(0700); $this->assertTrue(mkdir($this->fooURL . '/another/more', 0777, true)); $this->assertEquals(3, count($this->foo->getChildren())); $another = $this->foo->getChild('another'); $this->assertTrue($another->hasChild('more')); $this->assertEquals(0777, $this->foo->getChild('another')->getPermissions()); $this->assertEquals(0777, $this->foo->getChild('another')->getChild('more')->getPermissions()); } /** * no root > new directory becomes root * * @test * @group permissions */ public function mkdirWithoutRootCreatesNewRootDifferentPermissions() { vfsStreamWrapper::register(); $this->assertTrue(@mkdir(vfsStream::url('foo'), 0755)); $this->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()->getType()); $this->assertEquals('foo', vfsStreamWrapper::getRoot()->getName()); $this->assertEquals(0755, vfsStreamWrapper::getRoot()->getPermissions()); } /** * no root > new directory becomes root * * @test * @group permissions */ public function mkdirWithoutRootCreatesNewRootWithDefaultPermissions() { vfsStreamWrapper::register(); $this->assertTrue(@mkdir(vfsStream::url('foo'))); $this->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()->getType()); $this->assertEquals('foo', vfsStreamWrapper::getRoot()->getName()); $this->assertEquals(0777, vfsStreamWrapper::getRoot()->getPermissions()); } /** * @test * @group permissions * @group bug_15 */ public function mkdirDirCanNotCreateNewDirInNonWritingDirectory() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); vfsStreamWrapper::getRoot()->addChild(new vfsStreamDirectory('restrictedFolder', 0000)); $this->assertFalse(is_writable(vfsStream::url('root/restrictedFolder/'))); $this->assertFalse(mkdir(vfsStream::url('root/restrictedFolder/newFolder'))); $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('restrictedFolder/newFolder')); } /** * @test * @group issue_28 */ public function mkDirShouldNotOverwriteExistingDirectories() { vfsStream::setup('root'); $dir = vfsStream::url('root/dir'); $this->assertTrue(mkdir($dir)); $this->assertFalse(@mkdir($dir)); } /** * @test * @group issue_28 * @expectedException PHPUnit_Framework_Error * @expectedExceptionMessage mkdir(): Path vfs://root/dir exists */ public function mkDirShouldNotOverwriteExistingDirectoriesAndTriggerE_USER_WARNING() { vfsStream::setup('root'); $dir = vfsStream::url('root/dir'); $this->assertTrue(mkdir($dir)); $this->assertFalse(mkdir($dir)); } /** * @test * @group issue_28 */ public function mkDirShouldNotOverwriteExistingFiles() { $root = vfsStream::setup('root'); vfsStream::newFile('test.txt')->at($root); $this->assertFalse(@mkdir(vfsStream::url('root/test.txt'))); } /** * @test * @group issue_28 * @expectedException PHPUnit_Framework_Error * @expectedExceptionMessage mkdir(): Path vfs://root/test.txt exists */ public function mkDirShouldNotOverwriteExistingFilesAndTriggerE_USER_WARNING() { $root = vfsStream::setup('root'); vfsStream::newFile('test.txt')->at($root); $this->assertFalse(mkdir(vfsStream::url('root/test.txt'))); } /** * @test * @group issue_131 * @since 1.6.3 */ public function allowsRecursiveMkDirWithDirectoryName0() { vfsStream::setup('root'); $subdir = vfsStream::url('root/a/0'); mkdir($subdir, 0777, true); $this->assertFileExists($subdir); } /** * @test * @group permissions * @group bug_15 */ public function canNotIterateOverNonReadableDirectory() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); $this->assertFalse(@opendir(vfsStream::url('root'))); $this->assertFalse(@dir(vfsStream::url('root'))); } /** * assert is_dir() returns correct result * * @test */ public function is_dir() { $this->assertTrue(is_dir($this->fooURL)); $this->assertTrue(is_dir($this->fooURL . '/.')); $this->assertTrue(is_dir($this->barURL)); $this->assertTrue(is_dir($this->barURL . '/.')); $this->assertFalse(is_dir($this->baz1URL)); $this->assertFalse(is_dir($this->baz2URL)); $this->assertFalse(is_dir($this->fooURL . '/another')); $this->assertFalse(is_dir(vfsStream::url('another'))); } /** * can not unlink without root * * @test */ public function canNotUnlinkDirectoryWithoutRoot() { vfsStreamWrapper::register(); $this->assertFalse(@rmdir(vfsStream::url('foo'))); } /** * rmdir() can not remove files * * @test */ public function rmdirCanNotRemoveFiles() { $this->assertFalse(rmdir($this->baz1URL)); $this->assertFalse(rmdir($this->baz2URL)); } /** * rmdir() can not remove a non-existing directory * * @test */ public function rmdirCanNotRemoveNonExistingDirectory() { $this->assertFalse(rmdir($this->fooURL . '/another')); } /** * rmdir() can not remove non-empty directories * * @test */ public function rmdirCanNotRemoveNonEmptyDirectory() { $this->assertFalse(rmdir($this->fooURL)); $this->assertFalse(rmdir($this->barURL)); } /** * @test */ public function rmdirCanRemoveEmptyDirectory() { vfsStream::newDirectory('empty')->at($this->foo); $this->assertTrue($this->foo->hasChild('empty')); $this->assertTrue(rmdir($this->fooURL . '/empty')); $this->assertFalse($this->foo->hasChild('empty')); } /** * @test */ public function rmdirCanRemoveEmptyDirectoryWithDot() { vfsStream::newDirectory('empty')->at($this->foo); $this->assertTrue($this->foo->hasChild('empty')); $this->assertTrue(rmdir($this->fooURL . '/empty/.')); $this->assertFalse($this->foo->hasChild('empty')); } /** * rmdir() can remove empty directories * * @test */ public function rmdirCanRemoveEmptyRoot() { $this->foo->removeChild('bar'); $this->foo->removeChild('baz2'); $this->assertTrue(rmdir($this->fooURL)); $this->assertFalse(file_exists($this->fooURL)); // make sure statcache was cleared $this->assertNull(vfsStreamWrapper::getRoot()); } /** * @test * @group permissions * @group bug_15 */ public function rmdirDirCanNotRemoveDirFromNonWritingDirectory() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); vfsStreamWrapper::getRoot()->addChild(new vfsStreamDirectory('nonRemovableFolder')); $this->assertFalse(is_writable(vfsStream::url('root'))); $this->assertFalse(rmdir(vfsStream::url('root/nonRemovableFolder'))); $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('nonRemovableFolder')); } /** * @test * @group permissions * @group bug_17 */ public function issue17() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0770)); vfsStreamWrapper::getRoot()->chgrp(vfsStream::GROUP_USER_1) ->chown(vfsStream::OWNER_USER_1); $this->assertFalse(mkdir(vfsStream::url('root/doesNotWork'))); $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('doesNotWork')); } /** * @test * @group bug_19 */ public function accessWithDoubleDotReturnsCorrectContent() { $this->assertEquals('baz2', file_get_contents(vfsStream::url('foo/bar/../baz2')) ); } /** * @test * @group bug_115 */ public function accessWithExcessDoubleDotsReturnsCorrectContent() { $this->assertEquals('baz2', file_get_contents(vfsStream::url('foo/../../../../bar/../baz2')) ); } /** * @test * @group bug_115 */ public function alwaysResolvesRootDirectoryAsOwnParentWithDoubleDot() { vfsStreamWrapper::getRoot()->chown(vfsStream::OWNER_USER_1); $this->assertTrue(is_dir(vfsStream::url('foo/..'))); $stat = stat(vfsStream::url('foo/..')); $this->assertEquals( vfsStream::OWNER_USER_1, $stat['uid'] ); } /** * @test * @since 0.11.0 * @group issue_23 */ public function unlinkCanNotRemoveNonEmptyDirectory() { try { $this->assertFalse(unlink($this->barURL)); } catch (\PHPUnit_Framework_Error $fe) { $this->assertEquals('unlink(vfs://foo/bar): Operation not permitted', $fe->getMessage()); } $this->assertTrue($this->foo->hasChild('bar')); $this->assertFileExists($this->barURL); } /** * @test * @since 0.11.0 * @group issue_23 */ public function unlinkCanNotRemoveEmptyDirectory() { vfsStream::newDirectory('empty')->at($this->foo); try { $this->assertTrue(unlink($this->fooURL . '/empty')); } catch (\PHPUnit_Framework_Error $fe) { $this->assertEquals('unlink(vfs://foo/empty): Operation not permitted', $fe->getMessage()); } $this->assertTrue($this->foo->hasChild('empty')); $this->assertFileExists($this->fooURL . '/empty'); } /** * @test * @group issue_32 */ public function canCreateFolderOfSameNameAsParentFolder() { $root = vfsStream::setup('testFolder'); mkdir(vfsStream::url('testFolder') . '/testFolder/subTestFolder', 0777, true); $this->assertTrue(file_exists(vfsStream::url('testFolder/testFolder/subTestFolder/.'))); } /** * @test * @group issue_32 */ public function canRetrieveFolderOfSameNameAsParentFolder() { $root = vfsStream::setup('testFolder'); mkdir(vfsStream::url('testFolder') . '/testFolder/subTestFolder', 0777, true); $this->assertTrue($root->hasChild('testFolder')); $this->assertNotNull($root->getChild('testFolder')); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperFileTestCase.php000066400000000000000000000322471355632626400272130ustar00rootroot00000000000000assertEquals('baz2', file_get_contents($this->baz2URL)); $this->assertEquals('baz 1', file_get_contents($this->baz1URL)); $this->assertFalse(@file_get_contents($this->barURL)); $this->assertFalse(@file_get_contents($this->fooURL)); } /** * @test * @group permissions * @group bug_15 */ public function file_get_contentsNonReadableFile() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); vfsStream::newFile('new.txt', 0000)->at(vfsStreamWrapper::getRoot())->withContent('content'); $this->assertEquals('', @file_get_contents(vfsStream::url('root/new.txt'))); } /** * assert that file_put_contents() delivers correct file contents * * @test */ public function file_put_contentsExistingFile() { $this->assertEquals(14, file_put_contents($this->baz2URL, 'baz is not bar')); $this->assertEquals('baz is not bar', $this->baz2->getContent()); $this->assertEquals(6, file_put_contents($this->baz1URL, 'foobar')); $this->assertEquals('foobar', $this->baz1->getContent()); $this->assertFalse(@file_put_contents($this->barURL, 'This does not work.')); $this->assertFalse(@file_put_contents($this->fooURL, 'This does not work, too.')); } /** * @test * @group permissions * @group bug_15 */ public function file_put_contentsExistingFileNonWritableDirectory() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); vfsStream::newFile('new.txt')->at(vfsStreamWrapper::getRoot())->withContent('content'); $this->assertEquals(15, @file_put_contents(vfsStream::url('root/new.txt'), 'This does work.')); $this->assertEquals('This does work.', file_get_contents(vfsStream::url('root/new.txt'))); } /** * @test * @group permissions * @group bug_15 */ public function file_put_contentsExistingNonWritableFile() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); vfsStream::newFile('new.txt', 0400)->at(vfsStreamWrapper::getRoot())->withContent('content'); $this->assertFalse(@file_put_contents(vfsStream::url('root/new.txt'), 'This does not work.')); $this->assertEquals('content', file_get_contents(vfsStream::url('root/new.txt'))); } /** * assert that file_put_contents() delivers correct file contents * * @test */ public function file_put_contentsNonExistingFile() { $this->assertEquals(14, file_put_contents($this->fooURL . '/baznot.bar', 'baz is not bar')); $this->assertEquals(3, count($this->foo->getChildren())); $this->assertEquals(14, file_put_contents($this->barURL . '/baznot.bar', 'baz is not bar')); $this->assertEquals(2, count($this->bar->getChildren())); } /** * @test * @group permissions * @group bug_15 */ public function file_put_contentsNonExistingFileNonWritableDirectory() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); $this->assertFalse(@file_put_contents(vfsStream::url('root/new.txt'), 'This does not work.')); $this->assertFalse(file_exists(vfsStream::url('root/new.txt'))); } /** * using a file pointer should work without any problems * * @test */ public function usingFilePointer() { $fp = fopen($this->baz1URL, 'r'); $this->assertEquals(0, ftell($fp)); $this->assertFalse(feof($fp)); $this->assertEquals(0, fseek($fp, 2)); $this->assertEquals(2, ftell($fp)); $this->assertEquals(0, fseek($fp, 1, SEEK_CUR)); $this->assertEquals(3, ftell($fp)); $this->assertEquals(0, fseek($fp, 1, SEEK_END)); $this->assertEquals(6, ftell($fp)); $this->assertTrue(feof($fp)); $this->assertEquals(0, fseek($fp, 2)); $this->assertFalse(feof($fp)); $this->assertEquals(2, ftell($fp)); $this->assertEquals('z', fread($fp, 1)); $this->assertEquals(3, ftell($fp)); $this->assertEquals(' 1', fread($fp, 8092)); $this->assertEquals(5, ftell($fp)); $this->assertTrue(fclose($fp)); } /** * assert is_file() returns correct result * * @test */ public function is_file() { $this->assertFalse(is_file($this->fooURL)); $this->assertFalse(is_file($this->barURL)); $this->assertTrue(is_file($this->baz1URL)); $this->assertTrue(is_file($this->baz2URL)); $this->assertFalse(is_file($this->fooURL . '/another')); $this->assertFalse(is_file(vfsStream::url('another'))); } /** * @test * @group issue7 * @group issue13 */ public function issue13CanNotOverwriteFiles() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); file_put_contents($vfsFile, 'd'); $this->assertEquals('d', file_get_contents($vfsFile)); } /** * @test * @group issue7 * @group issue13 */ public function appendContentIfOpenedWithModeA() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); $fp = fopen($vfsFile, 'ab'); fwrite($fp, 'd'); fclose($fp); $this->assertEquals('testd', file_get_contents($vfsFile)); } /** * @test * @group issue7 * @group issue13 */ public function canOverwriteNonExistingFileWithModeX() { $vfsFile = vfsStream::url('foo/overwrite.txt'); $fp = fopen($vfsFile, 'xb'); fwrite($fp, 'test'); fclose($fp); $this->assertEquals('test', file_get_contents($vfsFile)); } /** * @test * @group issue7 * @group issue13 */ public function canNotOverwriteExistingFileWithModeX() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); $this->assertFalse(@fopen($vfsFile, 'xb')); $this->assertEquals('test', file_get_contents($vfsFile)); } /** * @test * @group issue7 * @group issue13 */ public function canNotOpenNonExistingFileReadonly() { $this->assertFalse(@fopen(vfsStream::url('foo/doesNotExist.txt'), 'rb')); } /** * @test * @group issue7 * @group issue13 */ public function canNotOpenNonExistingFileReadAndWrite() { $this->assertFalse(@fopen(vfsStream::url('foo/doesNotExist.txt'), 'rb+')); } /** * @test * @group issue7 * @group issue13 */ public function canNotOpenWithIllegalMode() { $this->assertFalse(@fopen($this->baz2URL, 'invalid')); } /** * @test * @group issue7 * @group issue13 */ public function canNotWriteToReadOnlyFile() { $fp = fopen($this->baz2URL, 'rb'); $this->assertEquals('baz2', fread($fp, 4096)); $this->assertEquals(0, fwrite($fp, 'foo')); fclose($fp); $this->assertEquals('baz2', file_get_contents($this->baz2URL)); } /** * @test * @group issue7 * @group issue13 */ public function canNotReadFromWriteOnlyFileWithModeW() { $fp = fopen($this->baz2URL, 'wb'); $this->assertEquals('', fread($fp, 4096)); $this->assertEquals(3, fwrite($fp, 'foo')); fseek($fp, 0); $this->assertEquals('', fread($fp, 4096)); fclose($fp); $this->assertEquals('foo', file_get_contents($this->baz2URL)); } /** * @test * @group issue7 * @group issue13 */ public function canNotReadFromWriteOnlyFileWithModeA() { $fp = fopen($this->baz2URL, 'ab'); $this->assertEquals('', fread($fp, 4096)); $this->assertEquals(3, fwrite($fp, 'foo')); fseek($fp, 0); $this->assertEquals('', fread($fp, 4096)); fclose($fp); $this->assertEquals('baz2foo', file_get_contents($this->baz2URL)); } /** * @test * @group issue7 * @group issue13 */ public function canNotReadFromWriteOnlyFileWithModeX() { $vfsFile = vfsStream::url('foo/modeXtest.txt'); $fp = fopen($vfsFile, 'xb'); $this->assertEquals('', fread($fp, 4096)); $this->assertEquals(3, fwrite($fp, 'foo')); fseek($fp, 0); $this->assertEquals('', fread($fp, 4096)); fclose($fp); $this->assertEquals('foo', file_get_contents($vfsFile)); } /** * @test * @group permissions * @group bug_15 */ public function canNotRemoveFileFromDirectoryWithoutWritePermissions() { vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); vfsStream::newFile('new.txt')->at(vfsStreamWrapper::getRoot()); $this->assertFalse(unlink(vfsStream::url('root/new.txt'))); $this->assertTrue(file_exists(vfsStream::url('root/new.txt'))); } /** * @test * @group issue_30 */ public function truncatesFileWhenOpenedWithModeW() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); $fp = fopen($vfsFile, 'wb'); $this->assertEquals('', file_get_contents($vfsFile)); fclose($fp); } /** * @test * @group issue_30 */ public function createsNonExistingFileWhenOpenedWithModeC() { $vfsFile = vfsStream::url('foo/tobecreated.txt'); $fp = fopen($vfsFile, 'cb'); fwrite($fp, 'some content'); $this->assertTrue($this->foo->hasChild('tobecreated.txt')); fclose($fp); $this->assertEquals('some content', file_get_contents($vfsFile)); } /** * @test * @group issue_30 */ public function createsNonExistingFileWhenOpenedWithModeCplus() { $vfsFile = vfsStream::url('foo/tobecreated.txt'); $fp = fopen($vfsFile, 'cb+'); fwrite($fp, 'some content'); $this->assertTrue($this->foo->hasChild('tobecreated.txt')); fclose($fp); $this->assertEquals('some content', file_get_contents($vfsFile)); } /** * @test * @group issue_30 */ public function doesNotTruncateFileWhenOpenedWithModeC() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); $fp = fopen($vfsFile, 'cb'); $this->assertEquals('test', file_get_contents($vfsFile)); fclose($fp); } /** * @test * @group issue_30 */ public function setsPointerToStartWhenOpenedWithModeC() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); $fp = fopen($vfsFile, 'cb'); $this->assertEquals(0, ftell($fp)); fclose($fp); } /** * @test * @group issue_30 */ public function doesNotTruncateFileWhenOpenedWithModeCplus() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); $fp = fopen($vfsFile, 'cb+'); $this->assertEquals('test', file_get_contents($vfsFile)); fclose($fp); } /** * @test * @group issue_30 */ public function setsPointerToStartWhenOpenedWithModeCplus() { $vfsFile = vfsStream::url('foo/overwrite.txt'); file_put_contents($vfsFile, 'test'); $fp = fopen($vfsFile, 'cb+'); $this->assertEquals(0, ftell($fp)); fclose($fp); } /** * @test */ public function cannotOpenExistingNonwritableFileWithModeA() { $this->baz1->chmod(0400); $this->assertFalse(@fopen($this->baz1URL, 'a')); } /** * @test */ public function cannotOpenExistingNonwritableFileWithModeW() { $this->baz1->chmod(0400); $this->assertFalse(@fopen($this->baz1URL, 'w')); } /** * @test */ public function cannotOpenNonReadableFileWithModeR() { $this->baz1->chmod(0); $this->assertFalse(@fopen($this->baz1URL, 'r')); } /** * @test */ public function cannotRenameToNonWritableDir() { $this->bar->chmod(0); $this->assertFalse(@rename($this->baz2URL, vfsStream::url('foo/bar/baz3'))); } /** * @test * @group issue_38 */ public function cannotReadFileFromNonReadableDir() { $this->markTestSkipped("Issue #38."); $this->bar->chmod(0); $this->assertFalse(@file_get_contents($this->baz1URL)); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperFileTimesTestCase.php000066400000000000000000000263631355632626400302170ustar00rootroot00000000000000lastModified(50) ->lastAccessed(50) ->lastAttributeModified(50); $this->fooUrl = vfsStream::url('root/foo.txt'); $this->barUrl = vfsStream::url('root/bar'); $this->bazUrl = vfsStream::url('root/bar/baz.txt'); } /** * helper assertion for the tests * * @param string $url url to check * @param vfsStreamContent $content content to compare */ protected function assertFileTimesEqualStreamTimes($url, vfsStreamContent $content) { $this->assertEquals(filemtime($url), $content->filemtime()); $this->assertEquals(fileatime($url), $content->fileatime()); $this->assertEquals(filectime($url), $content->filectime()); } /** * @test * @group issue_7 * @group issue_26 */ public function openFileChangesAttributeTimeOnly() { $file = vfsStream::newFile('foo.txt') ->withContent('test') ->at(vfsStreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); fclose(fopen($this->fooUrl, 'rb')); $this->assertGreaterThan(time() - 2, fileatime($this->fooUrl)); $this->assertLessThanOrEqual(time(), fileatime($this->fooUrl)); $this->assertLessThanOrEqual(100, filemtime($this->fooUrl)); $this->assertEquals(100, filectime($this->fooUrl)); $this->assertFileTimesEqualStreamTimes($this->fooUrl, $file); } /** * @test * @group issue_7 * @group issue_26 */ public function fileGetContentsChangesAttributeTimeOnly() { $file = vfsStream::newFile('foo.txt') ->withContent('test') ->at(vfsStreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); file_get_contents($this->fooUrl); $this->assertGreaterThan(time() - 2, fileatime($this->fooUrl)); $this->assertLessThanOrEqual(time(), fileatime($this->fooUrl)); $this->assertLessThanOrEqual(100, filemtime($this->fooUrl)); $this->assertEquals(100, filectime($this->fooUrl)); $this->assertFileTimesEqualStreamTimes($this->fooUrl, $file); } /** * @test * @group issue_7 * @group issue_26 */ public function openFileWithTruncateChangesAttributeAndModificationTime() { $file = vfsStream::newFile('foo.txt') ->withContent('test') ->at(vfsStreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); fclose(fopen($this->fooUrl, 'wb')); $this->assertGreaterThan(time() - 2, filemtime($this->fooUrl)); $this->assertGreaterThan(time() - 2, fileatime($this->fooUrl)); $this->assertLessThanOrEqual(time(), filemtime($this->fooUrl)); $this->assertLessThanOrEqual(time(), fileatime($this->fooUrl)); $this->assertEquals(100, filectime($this->fooUrl)); $this->assertFileTimesEqualStreamTimes($this->fooUrl, $file); } /** * @test * @group issue_7 */ public function readFileChangesAccessTime() { $file = vfsStream::newFile('foo.txt') ->withContent('test') ->at(vfsStreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); $fp = fopen($this->fooUrl, 'rb'); $openTime = time(); sleep(2); fread($fp, 1024); fclose($fp); $this->assertLessThanOrEqual($openTime, filemtime($this->fooUrl)); $this->assertLessThanOrEqual($openTime + 3, fileatime($this->fooUrl)); $this->assertEquals(100, filectime($this->fooUrl)); $this->assertFileTimesEqualStreamTimes($this->fooUrl, $file); } /** * @test * @group issue_7 */ public function writeFileChangesModificationTime() { $file = vfsStream::newFile('foo.txt') ->at(vfsStreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); $fp = fopen($this->fooUrl, 'wb'); $openTime = time(); sleep(2); fwrite($fp, 'test'); fclose($fp); $this->assertLessThanOrEqual($openTime + 3, filemtime($this->fooUrl)); $this->assertLessThanOrEqual($openTime, fileatime($this->fooUrl)); $this->assertEquals(100, filectime($this->fooUrl)); $this->assertFileTimesEqualStreamTimes($this->fooUrl, $file); } /** * @test * @group issue_7 */ public function createNewFileSetsAllTimesToCurrentTime() { file_put_contents($this->fooUrl, 'test'); $this->assertLessThanOrEqual(time(), filemtime($this->fooUrl)); $this->assertEquals(fileatime($this->fooUrl), filectime($this->fooUrl)); $this->assertEquals(fileatime($this->fooUrl), filemtime($this->fooUrl)); $this->assertFileTimesEqualStreamTimes($this->fooUrl, vfsStreamWrapper::getRoot()->getChild('foo.txt')); } /** * @test * @group issue_7 */ public function createNewFileChangesAttributeAndModificationTimeOfContainingDirectory() { $dir = vfsStream::newDirectory('bar') ->at(vfsStreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); file_put_contents($this->bazUrl, 'test'); $this->assertLessThanOrEqual(time(), filemtime($this->barUrl)); $this->assertLessThanOrEqual(time(), filectime($this->barUrl)); $this->assertEquals(100, fileatime($this->barUrl)); $this->assertFileTimesEqualStreamTimes($this->barUrl, $dir); } /** * @test * @group issue_7 */ public function addNewFileNameWithLinkFunctionChangesAttributeTimeOfOriginalFile() { $this->markTestSkipped('Links are currently not supported by vfsStream.'); } /** * @test * @group issue_7 */ public function addNewFileNameWithLinkFunctionChangesAttributeAndModificationTimeOfDirectoryContainingLink() { $this->markTestSkipped('Links are currently not supported by vfsStream.'); } /** * @test * @group issue_7 */ public function removeFileChangesAttributeAndModificationTimeOfContainingDirectory() { $dir = vfsStream::newDirectory('bar') ->at(vfsStreamWrapper::getRoot()); $file = vfsStream::newFile('baz.txt') ->at($dir) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); $dir->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); unlink($this->bazUrl); $this->assertLessThanOrEqual(time(), filemtime($this->barUrl)); $this->assertLessThanOrEqual(time(), filectime($this->barUrl)); $this->assertEquals(100, fileatime($this->barUrl)); $this->assertFileTimesEqualStreamTimes($this->barUrl, $dir); } /** * @test * @group issue_7 */ public function renameFileChangesAttributeAndModificationTimeOfAffectedDirectories() { $target = vfsStream::newDirectory('target') ->at(vfsStreamWrapper::getRoot()) ->lastModified(200) ->lastAccessed(200) ->lastAttributeModified(200); $source = vfsStream::newDirectory('bar') ->at(vfsStreamWrapper::getRoot()); $file = vfsStream::newFile('baz.txt') ->at($source) ->lastModified(300) ->lastAccessed(300) ->lastAttributeModified(300); $source->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); rename($this->bazUrl, vfsStream::url('root/target/baz.txt')); $this->assertLessThanOrEqual(time(), filemtime($this->barUrl)); $this->assertLessThanOrEqual(time(), filectime($this->barUrl)); $this->assertEquals(100, fileatime($this->barUrl)); $this->assertFileTimesEqualStreamTimes($this->barUrl, $source); $this->assertLessThanOrEqual(time(), filemtime(vfsStream::url('root/target'))); $this->assertLessThanOrEqual(time(), filectime(vfsStream::url('root/target'))); $this->assertEquals(200, fileatime(vfsStream::url('root/target'))); $this->assertFileTimesEqualStreamTimes(vfsStream::url('root/target'), $target); } /** * @test * @group issue_7 */ public function renameFileDoesNotChangeFileTimesOfFileItself() { $target = vfsStream::newDirectory('target') ->at(vfsStreamWrapper::getRoot()) ->lastModified(200) ->lastAccessed(200) ->lastAttributeModified(200); $source = vfsStream::newDirectory('bar') ->at(vfsStreamWrapper::getRoot()); $file = vfsStream::newFile('baz.txt') ->at($source) ->lastModified(300) ->lastAccessed(300) ->lastAttributeModified(300); $source->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); rename($this->bazUrl, vfsStream::url('root/target/baz.txt')); $this->assertEquals(300, filemtime(vfsStream::url('root/target/baz.txt'))); $this->assertEquals(300, filectime(vfsStream::url('root/target/baz.txt'))); $this->assertEquals(300, fileatime(vfsStream::url('root/target/baz.txt'))); $this->assertFileTimesEqualStreamTimes(vfsStream::url('root/target/baz.txt'), $file); } /** * @test * @group issue_7 */ public function changeFileAttributesChangesAttributeTimeOfFileItself() { $this->markTestSkipped('Changing file attributes via stream wrapper for self-defined streams is not supported by PHP.'); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperFlockTestCase.php000066400000000000000000000343141355632626400273670ustar00rootroot00000000000000root = vfsStream::setup(); } /** * @test */ public function fileIsNotLockedByDefault() { $this->assertFalse(vfsStream::newFile('foo.txt')->isLocked()); } /** * @test */ public function streamIsNotLockedByDefault() { file_put_contents(vfsStream::url('root/foo.txt'), 'content'); $this->assertFalse($this->root->getChild('foo.txt')->isLocked()); } /** * @test */ public function canAquireSharedLock() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertTrue(flock($fp, LOCK_SH)); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp); } /** * @test */ public function canAquireSharedLockWithNonBlockingFlockCall() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertTrue(flock($fp, LOCK_SH | LOCK_NB)); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp); } /** * @test */ public function canAquireEclusiveLock() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertTrue(flock($fp, LOCK_EX)); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); fclose($fp); } /** * @test */ public function canAquireEclusiveLockWithNonBlockingFlockCall() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertTrue(flock($fp, LOCK_EX | LOCK_NB)); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); fclose($fp); } /** * @test */ public function canRemoveLock() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_EX); $this->assertTrue(flock($fp, LOCK_UN)); $this->assertFalse($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canRemoveLockWhenNotLocked() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertTrue(flock($fp, LOCK_UN)); $this->assertFalse($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertFalse($file->hasSharedLock($fp)); $this->assertFalse($file->hasExclusiveLock()); $this->assertFalse($file->hasExclusiveLock($fp)); fclose($fp); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canRemoveSharedLockWithoutRemovingSharedLockOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp1, LOCK_SH); $file->lock($fp2, LOCK_SH); $this->assertTrue(flock($fp1, LOCK_UN)); $this->assertTrue($file->hasSharedLock()); $this->assertFalse($file->hasSharedLock($fp1)); $this->assertTrue($file->hasSharedLock($fp2)); fclose($fp1); fclose($fp2); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canNotRemoveSharedLockAcquiredOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp1, LOCK_SH); $this->assertTrue(flock($fp2, LOCK_UN)); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp1); fclose($fp2); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canNotRemoveExlusiveLockAcquiredOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp1, LOCK_EX); $this->assertTrue(flock($fp2, LOCK_UN)); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); fclose($fp1); fclose($fp2); } /** * @test */ public function canRemoveLockWithNonBlockingFlockCall() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_EX); $this->assertTrue(flock($fp, LOCK_UN | LOCK_NB)); $this->assertFalse($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canNotAquireExclusiveLockIfAlreadyExclusivelyLockedOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp1, LOCK_EX); $this->assertFalse(flock($fp2, LOCK_EX + LOCK_NB)); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); $this->assertTrue($file->hasExclusiveLock($fp1)); $this->assertFalse($file->hasExclusiveLock($fp2)); fclose($fp1); fclose($fp2); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canAquireExclusiveLockIfAlreadySelfExclusivelyLocked() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_EX); $this->assertTrue(flock($fp, LOCK_EX + LOCK_NB)); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); fclose($fp); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canNotAquireExclusiveLockIfAlreadySharedLockedOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp1, LOCK_SH); $this->assertFalse(flock($fp2, LOCK_EX)); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp1); fclose($fp2); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canAquireExclusiveLockIfAlreadySelfSharedLocked() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_SH); $this->assertTrue(flock($fp, LOCK_EX)); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); fclose($fp); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canNotAquireSharedLockIfAlreadyExclusivelyLockedOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp1, LOCK_EX); $this->assertFalse(flock($fp2, LOCK_SH + LOCK_NB)); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); fclose($fp1); fclose($fp2); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canAquireSharedLockIfAlreadySelfExclusivelyLocked() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_EX); $this->assertTrue(flock($fp, LOCK_SH + LOCK_NB)); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canAquireSharedLockIfAlreadySelfSharedLocked() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_SH); $this->assertTrue(flock($fp, LOCK_SH)); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); fclose($fp); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function canAquireSharedLockIfAlreadySharedLockedOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp1, LOCK_SH); $this->assertTrue(flock($fp2, LOCK_SH)); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertTrue($file->hasSharedLock($fp1)); $this->assertTrue($file->hasSharedLock($fp2)); $this->assertFalse($file->hasExclusiveLock()); fclose($fp1); fclose($fp2); } /** * @see https://github.com/mikey179/vfsStream/issues/31 * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_31 * @group issue_40 */ public function removesExclusiveLockOnStreamClose() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_EX); fclose($fp); $this->assertFalse($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); } /** * @see https://github.com/mikey179/vfsStream/issues/31 * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_31 * @group issue_40 */ public function removesSharedLockOnStreamClose() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp, LOCK_SH); fclose($fp); $this->assertFalse($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertFalse($file->hasExclusiveLock()); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function notRemovesExclusiveLockOnStreamCloseIfExclusiveLockAcquiredOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp2, LOCK_EX); fclose($fp1); $this->assertTrue($file->isLocked()); $this->assertFalse($file->hasSharedLock()); $this->assertTrue($file->hasExclusiveLock()); $this->assertTrue($file->hasExclusiveLock($fp2)); fclose($fp2); } /** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function notRemovesSharedLockOnStreamCloseIfSharedLockAcquiredOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp2, LOCK_SH); fclose($fp1); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertTrue($file->hasSharedLock($fp2)); $this->assertFalse($file->hasExclusiveLock()); fclose($fp2); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperLargeFileTestCase.php000066400000000000000000000036121355632626400301600ustar00rootroot00000000000000largeFile = vfsStream::newFile('large.txt') ->withContent(LargeFileContent::withGigabytes(100)) ->at($root); } /** * @test */ public function hasLargeFileSize() { if (PHP_INT_MAX == 2147483647) { $this->markTestSkipped('Requires 64-bit version of PHP'); } $this->assertEquals( 100 * 1024 * 1024 * 1024, filesize($this->largeFile->url()) ); } /** * @test */ public function canReadFromLargeFile() { $fp = fopen($this->largeFile->url(), 'rb'); $data = fread($fp, 15); fclose($fp); $this->assertEquals(str_repeat(' ', 15), $data); } /** * @test */ public function canWriteIntoLargeFile() { $fp = fopen($this->largeFile->url(), 'rb+'); fseek($fp, 100 * 1024 * 1024, SEEK_SET); fwrite($fp, 'foobarbaz'); fclose($fp); $this->largeFile->seek((100 * 1024 * 1024) - 3, SEEK_SET); $this->assertEquals( ' foobarbaz ', $this->largeFile->read(15) ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperQuotaTestCase.php000066400000000000000000000150121355632626400274140ustar00rootroot00000000000000root = vfsStream::setup(); vfsStream::setQuota(10); } /** * @test */ public function writeLessThanQuotaWritesEverything() { $this->assertEquals(9, file_put_contents(vfsStream::url('root/file.txt'), '123456789')); $this->assertEquals('123456789', $this->root->getChild('file.txt')->getContent()); } /** * @test */ public function writeUpToQotaWritesEverything() { $this->assertEquals(10, file_put_contents(vfsStream::url('root/file.txt'), '1234567890')); $this->assertEquals('1234567890', $this->root->getChild('file.txt')->getContent()); } /** * @test */ public function writeMoreThanQotaWritesOnlyUpToQuota() { try { file_put_contents(vfsStream::url('root/file.txt'), '12345678901'); } catch (\PHPUnit_Framework_Error $e) { $this->assertEquals('file_put_contents(): Only 10 of 11 bytes written, possibly out of free disk space', $e->getMessage() ); } $this->assertEquals('1234567890', $this->root->getChild('file.txt')->getContent()); } /** * @test */ public function considersAllFilesForQuota() { vfsStream::newFile('foo.txt') ->withContent('foo') ->at(vfsStream::newDirectory('bar') ->at($this->root) ); try { file_put_contents(vfsStream::url('root/file.txt'), '12345678901'); } catch (\PHPUnit_Framework_Error $e) { $this->assertEquals('file_put_contents(): Only 7 of 11 bytes written, possibly out of free disk space', $e->getMessage() ); } $this->assertEquals('1234567', $this->root->getChild('file.txt')->getContent()); } /** * @test * @group issue_33 */ public function truncateToLessThanQuotaWritesEverything() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { $this->markTestSkipped('Requires PHP 5.4'); } if (strstr(PHP_VERSION, 'hiphop') !== false) { $this->markTestSkipped('Not supported on hhvm'); } $fp = fopen(vfsStream::url('root/file.txt'), 'w+'); $this->assertTrue(ftruncate($fp, 9)); fclose($fp); $this->assertEquals(9, $this->root->getChild('file.txt')->size() ); $this->assertEquals("\0\0\0\0\0\0\0\0\0", $this->root->getChild('file.txt')->getContent() ); } /** * @test * @group issue_33 */ public function truncateUpToQotaWritesEverything() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { $this->markTestSkipped('Requires PHP 5.4'); } if (strstr(PHP_VERSION, 'hiphop') !== false) { $this->markTestSkipped('Not supported on hhvm'); } $fp = fopen(vfsStream::url('root/file.txt'), 'w+'); $this->assertTrue(ftruncate($fp, 10)); fclose($fp); $this->assertEquals(10, $this->root->getChild('file.txt')->size() ); $this->assertEquals("\0\0\0\0\0\0\0\0\0\0", $this->root->getChild('file.txt')->getContent() ); } /** * @test * @group issue_33 */ public function truncateToMoreThanQotaWritesOnlyUpToQuota() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { $this->markTestSkipped('Requires PHP 5.4'); } if (strstr(PHP_VERSION, 'hiphop') !== false) { $this->markTestSkipped('Not supported on hhvm'); } $fp = fopen(vfsStream::url('root/file.txt'), 'w+'); $this->assertTrue(ftruncate($fp, 11)); fclose($fp); $this->assertEquals(10, $this->root->getChild('file.txt')->size() ); $this->assertEquals("\0\0\0\0\0\0\0\0\0\0", $this->root->getChild('file.txt')->getContent() ); } /** * @test * @group issue_33 */ public function truncateConsidersAllFilesForQuota() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { $this->markTestSkipped('Requires PHP 5.4'); } if (strstr(PHP_VERSION, 'hiphop') !== false) { $this->markTestSkipped('Not supported on hhvm'); } vfsStream::newFile('bar.txt') ->withContent('bar') ->at(vfsStream::newDirectory('bar') ->at($this->root) ); $fp = fopen(vfsStream::url('root/file.txt'), 'w+'); $this->assertTrue(ftruncate($fp, 11)); fclose($fp); $this->assertEquals(7, $this->root->getChild('file.txt')->size() ); $this->assertEquals("\0\0\0\0\0\0\0", $this->root->getChild('file.txt')->getContent() ); } /** * @test * @group issue_33 */ public function canNotTruncateToGreaterLengthWhenDiscQuotaReached() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { $this->markTestSkipped('Requires PHP 5.4'); } if (strstr(PHP_VERSION, 'hiphop') !== false) { $this->markTestSkipped('Not supported on hhvm'); } vfsStream::newFile('bar.txt') ->withContent('1234567890') ->at(vfsStream::newDirectory('bar') ->at($this->root) ); $fp = fopen(vfsStream::url('root/file.txt'), 'w+'); $this->assertFalse(ftruncate($fp, 11)); fclose($fp); $this->assertEquals(0, $this->root->getChild('file.txt')->size() ); $this->assertEquals('', $this->root->getChild('file.txt')->getContent() ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperSetOptionTestCase.php000066400000000000000000000032061355632626400302510ustar00rootroot00000000000000root = vfsStream::setup(); vfsStream::newFile('foo.txt')->at($this->root); } /** * @test */ public function setBlockingDoesNotWork() { $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertFalse(stream_set_blocking($fp, 1)); fclose($fp); } /** * @test */ public function removeBlockingDoesNotWork() { $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertFalse(stream_set_blocking($fp, 0)); fclose($fp); } /** * @test */ public function setTimeoutDoesNotWork() { $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertFalse(stream_set_timeout($fp, 1)); fclose($fp); } /** * @test */ public function setWriteBufferDoesNotWork() { $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $this->assertEquals(-1, stream_set_write_buffer($fp, 512)); fclose($fp); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperStreamSelectTestCase.php000066400000000000000000000015671355632626400307300ustar00rootroot00000000000000at($root)->withContent('testContent'); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $readarray = array($fp); $writearray = array(); $exceptarray = array(); stream_select($readarray, $writearray, $exceptarray, 1); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperTestCase.php000066400000000000000000000653231355632626400264140ustar00rootroot00000000000000assertSame($this->foo, vfsStreamWrapper::getRoot()); vfsStreamWrapper::register(); $this->assertNull(vfsStreamWrapper::getRoot()); } /** * @test * @since 0.11.0 */ public function setRootReturnsRoot() { vfsStreamWrapper::register(); $root = vfsStream::newDirectory('root'); $this->assertSame($root, vfsStreamWrapper::setRoot($root)); } /** * assure that filesize is returned correct * * @test */ public function filesize() { $this->assertEquals(0, filesize($this->fooURL)); $this->assertEquals(0, filesize($this->fooURL . '/.')); $this->assertEquals(0, filesize($this->barURL)); $this->assertEquals(0, filesize($this->barURL . '/.')); $this->assertEquals(4, filesize($this->baz2URL)); $this->assertEquals(5, filesize($this->baz1URL)); } /** * assert that file_exists() delivers correct result * * @test */ public function file_exists() { $this->assertTrue(file_exists($this->fooURL)); $this->assertTrue(file_exists($this->fooURL . '/.')); $this->assertTrue(file_exists($this->barURL)); $this->assertTrue(file_exists($this->barURL . '/.')); $this->assertTrue(file_exists($this->baz1URL)); $this->assertTrue(file_exists($this->baz2URL)); $this->assertFalse(file_exists($this->fooURL . '/another')); $this->assertFalse(file_exists(vfsStream::url('another'))); } /** * assert that filemtime() delivers correct result * * @test */ public function filemtime() { $this->assertEquals(100, filemtime($this->fooURL)); $this->assertEquals(100, filemtime($this->fooURL . '/.')); $this->assertEquals(200, filemtime($this->barURL)); $this->assertEquals(200, filemtime($this->barURL . '/.')); $this->assertEquals(300, filemtime($this->baz1URL)); $this->assertEquals(400, filemtime($this->baz2URL)); } /** * @test * @group issue_23 */ public function unlinkRemovesFilesOnly() { $this->assertTrue(unlink($this->baz2URL)); $this->assertFalse(file_exists($this->baz2URL)); // make sure statcache was cleared $this->assertEquals(array($this->bar), $this->foo->getChildren()); $this->assertFalse(@unlink($this->fooURL . '/another')); $this->assertFalse(@unlink(vfsStream::url('another'))); $this->assertEquals(array($this->bar), $this->foo->getChildren()); } /** * @test * @group issue_49 */ public function unlinkReturnsFalseWhenFileDoesNotExist() { vfsStream::setup()->addChild(vfsStream::newFile('foo.blubb')); $this->assertFalse(@unlink(vfsStream::url('foo.blubb2'))); } /** * @test * @group issue_49 */ public function unlinkReturnsFalseWhenFileDoesNotExistAndFileWithSameNameExistsInRoot() { vfsStream::setup()->addChild(vfsStream::newFile('foo.blubb')); $this->assertFalse(@unlink(vfsStream::url('foo.blubb'))); } /** * assert dirname() returns correct directory name * * @test */ public function dirname() { $this->assertEquals($this->fooURL, dirname($this->barURL)); $this->assertEquals($this->barURL, dirname($this->baz1URL)); # returns "vfs:" instead of "." # however this seems not to be fixable because dirname() does not # call the stream wrapper #$this->assertEquals(dirname(vfsStream::url('doesNotExist')), '.'); } /** * assert basename() returns correct file name * * @test */ public function basename() { $this->assertEquals('bar', basename($this->barURL)); $this->assertEquals('baz1', basename($this->baz1URL)); $this->assertEquals('doesNotExist', basename(vfsStream::url('doesNotExist'))); } /** * assert is_readable() works correct * * @test */ public function is_readable() { $this->assertTrue(is_readable($this->fooURL)); $this->assertTrue(is_readable($this->fooURL . '/.')); $this->assertTrue(is_readable($this->barURL)); $this->assertTrue(is_readable($this->barURL . '/.')); $this->assertTrue(is_readable($this->baz1URL)); $this->assertTrue(is_readable($this->baz2URL)); $this->assertFalse(is_readable($this->fooURL . '/another')); $this->assertFalse(is_readable(vfsStream::url('another'))); $this->foo->chmod(0222); $this->assertFalse(is_readable($this->fooURL)); $this->baz1->chmod(0222); $this->assertFalse(is_readable($this->baz1URL)); } /** * assert is_writable() works correct * * @test */ public function is_writable() { $this->assertTrue(is_writable($this->fooURL)); $this->assertTrue(is_writable($this->fooURL . '/.')); $this->assertTrue(is_writable($this->barURL)); $this->assertTrue(is_writable($this->barURL . '/.')); $this->assertTrue(is_writable($this->baz1URL)); $this->assertTrue(is_writable($this->baz2URL)); $this->assertFalse(is_writable($this->fooURL . '/another')); $this->assertFalse(is_writable(vfsStream::url('another'))); $this->foo->chmod(0444); $this->assertFalse(is_writable($this->fooURL)); $this->baz1->chmod(0444); $this->assertFalse(is_writable($this->baz1URL)); } /** * assert is_executable() works correct * * @test */ public function is_executable() { $this->assertFalse(is_executable($this->baz1URL)); $this->baz1->chmod(0766); $this->assertTrue(is_executable($this->baz1URL)); $this->assertFalse(is_executable($this->baz2URL)); } /** * assert is_executable() works correct * * @test */ public function directoriesAndNonExistingFilesAreSometimesExecutable() { // Inconsistent behavior has been fixed in 7.3 // see https://github.com/php/php-src/commit/94b4abdbc4d if (PHP_VERSION_ID >= 70300) { $this->assertTrue(is_executable($this->fooURL)); $this->assertTrue(is_executable($this->fooURL . '/.')); $this->assertTrue(is_executable($this->barURL)); $this->assertTrue(is_executable($this->barURL . '/.')); } else { $this->assertFalse(is_executable($this->fooURL)); $this->assertFalse(is_executable($this->fooURL . '/.')); $this->assertFalse(is_executable($this->barURL)); $this->assertFalse(is_executable($this->barURL . '/.')); } $this->assertFalse(is_executable($this->fooURL . '/another')); $this->assertFalse(is_executable(vfsStream::url('another'))); } /** * file permissions * * @test * @group permissions */ public function chmod() { $this->assertEquals(40777, decoct(fileperms($this->fooURL))); $this->assertEquals(40777, decoct(fileperms($this->fooURL . '/.'))); $this->assertEquals(40777, decoct(fileperms($this->barURL))); $this->assertEquals(40777, decoct(fileperms($this->barURL . '/.'))); $this->assertEquals(100666, decoct(fileperms($this->baz1URL))); $this->assertEquals(100666, decoct(fileperms($this->baz2URL))); $this->foo->chmod(0755); $this->bar->chmod(0700); $this->baz1->chmod(0644); $this->baz2->chmod(0600); $this->assertEquals(40755, decoct(fileperms($this->fooURL))); $this->assertEquals(40755, decoct(fileperms($this->fooURL . '/.'))); $this->assertEquals(40700, decoct(fileperms($this->barURL))); $this->assertEquals(40700, decoct(fileperms($this->barURL . '/.'))); $this->assertEquals(100644, decoct(fileperms($this->baz1URL))); $this->assertEquals(100600, decoct(fileperms($this->baz2URL))); } /** * @test * @group issue_11 * @group permissions */ public function chmodModifiesPermissions() { if (version_compare(phpversion(), '5.4.0', '<')) { $this->assertFalse(@chmod($this->fooURL, 0755)); $this->assertFalse(@chmod($this->barURL, 0711)); $this->assertFalse(@chmod($this->baz1URL, 0644)); $this->assertFalse(@chmod($this->baz2URL, 0664)); $this->assertEquals(40777, decoct(fileperms($this->fooURL))); $this->assertEquals(40777, decoct(fileperms($this->barURL))); $this->assertEquals(100666, decoct(fileperms($this->baz1URL))); $this->assertEquals(100666, decoct(fileperms($this->baz2URL))); } else { $this->assertTrue(chmod($this->fooURL, 0755)); $this->assertTrue(chmod($this->barURL, 0711)); $this->assertTrue(chmod($this->baz1URL, 0644)); $this->assertTrue(chmod($this->baz2URL, 0664)); $this->assertEquals(40755, decoct(fileperms($this->fooURL))); $this->assertEquals(40711, decoct(fileperms($this->barURL))); $this->assertEquals(100644, decoct(fileperms($this->baz1URL))); $this->assertEquals(100664, decoct(fileperms($this->baz2URL))); } } /** * @test * @group permissions */ public function fileownerIsCurrentUserByDefault() { $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL)); $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL . '/.')); $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->barURL)); $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->barURL . '/.')); $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->baz1URL)); $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->baz2URL)); } /** * @test * @group issue_11 * @group permissions */ public function chownChangesUser() { if (version_compare(phpversion(), '5.4.0', '<')) { $this->foo->chown(vfsStream::OWNER_USER_1); $this->bar->chown(vfsStream::OWNER_USER_1); $this->baz1->chown(vfsStream::OWNER_USER_2); $this->baz2->chown(vfsStream::OWNER_USER_2); } else { chown($this->fooURL, vfsStream::OWNER_USER_1); chown($this->barURL, vfsStream::OWNER_USER_1); chown($this->baz1URL, vfsStream::OWNER_USER_2); chown($this->baz2URL, vfsStream::OWNER_USER_2); } $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->fooURL)); $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->fooURL . '/.')); $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->barURL)); $this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->barURL . '/.')); $this->assertEquals(vfsStream::OWNER_USER_2, fileowner($this->baz1URL)); $this->assertEquals(vfsStream::OWNER_USER_2, fileowner($this->baz2URL)); } /** * @test * @group issue_11 * @group permissions */ public function chownDoesNotWorkOnVfsStreamUrls() { if (version_compare(phpversion(), '5.4.0', '<')) { $this->assertFalse(@chown($this->fooURL, vfsStream::OWNER_USER_2)); $this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL)); } } /** * @test * @group issue_11 * @group permissions */ public function groupIsCurrentGroupByDefault() { $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL)); $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL . '/.')); $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->barURL)); $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->barURL . '/.')); $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->baz1URL)); $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->baz2URL)); } /** * @test * @group issue_11 * @group permissions */ public function chgrp() { if (version_compare(phpversion(), '5.4.0', '<')) { $this->foo->chgrp(vfsStream::GROUP_USER_1); $this->bar->chgrp(vfsStream::GROUP_USER_1); $this->baz1->chgrp(vfsStream::GROUP_USER_2); $this->baz2->chgrp(vfsStream::GROUP_USER_2); } else { chgrp($this->fooURL, vfsStream::GROUP_USER_1); chgrp($this->barURL, vfsStream::GROUP_USER_1); chgrp($this->baz1URL, vfsStream::GROUP_USER_2); chgrp($this->baz2URL, vfsStream::GROUP_USER_2); } $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->fooURL)); $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->fooURL . '/.')); $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->barURL)); $this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->barURL . '/.')); $this->assertEquals(vfsStream::GROUP_USER_2, filegroup($this->baz1URL)); $this->assertEquals(vfsStream::GROUP_USER_2, filegroup($this->baz2URL)); } /** * @test * @group issue_11 * @group permissions */ public function chgrpDoesNotWorkOnVfsStreamUrls() { if (version_compare(phpversion(), '5.4.0', '<')) { $this->assertFalse(@chgrp($this->fooURL, vfsStream::GROUP_USER_2)); $this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL)); } } /** * @test * @author Benoit Aubuchon */ public function renameDirectory() { // move foo/bar to foo/baz3 $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(rename($this->barURL, $baz3URL)); $this->assertFileExists($baz3URL); $this->assertFileNotExists($this->barURL); } /** * @test */ public function renameDirectoryWithDots() { // move foo/bar to foo/baz3 $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(rename($this->barURL . '/.', $baz3URL)); $this->assertFileExists($baz3URL); $this->assertFileNotExists($this->barURL); } /** * @test * @group issue_9 * @since 0.9.0 */ public function renameDirectoryWithDotsInTarget() { // move foo/bar to foo/baz3 $baz3URL = vfsStream::url('foo/../baz3/.'); $this->assertTrue(rename($this->barURL . '/.', $baz3URL)); $this->assertFileExists($baz3URL); $this->assertFileNotExists($this->barURL); } /** * @test * @author Benoit Aubuchon */ public function renameDirectoryOverwritingExistingFile() { // move foo/bar to foo/baz2 $this->assertTrue(rename($this->barURL, $this->baz2URL)); $this->assertFileExists(vfsStream::url('foo/baz2/baz1')); $this->assertFileNotExists($this->barURL); } /** * @test * @expectedException PHPUnit_Framework_Error */ public function renameFileIntoFile() { // foo/baz2 is a file, so it can not be turned into a directory $baz3URL = vfsStream::url('foo/baz2/baz3'); $this->assertTrue(rename($this->baz1URL, $baz3URL)); $this->assertFileExists($baz3URL); $this->assertFileNotExists($this->baz1URL); } /** * @test * @author Benoit Aubuchon */ public function renameFileToDirectory() { // move foo/bar/baz1 to foo/baz3 $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(rename($this->baz1URL, $baz3URL)); $this->assertFileExists($this->barURL); $this->assertFileExists($baz3URL); $this->assertFileNotExists($this->baz1URL); } /** * assert that trying to rename from a non existing file trigger a warning * * @expectedException PHPUnit_Framework_Error * @test */ public function renameOnSourceFileNotFound() { rename(vfsStream::url('notfound'), $this->baz1URL); } /** * assert that trying to rename to a directory that is not found trigger a warning * @expectedException PHPUnit_Framework_Error * @test */ public function renameOnDestinationDirectoryFileNotFound() { rename($this->baz1URL, vfsStream::url('foo/notfound/file2')); } /** * stat() and fstat() should return the same result * * @test */ public function statAndFstatReturnSameResult() { $fp = fopen($this->baz2URL, 'r'); $this->assertEquals(stat($this->baz2URL), fstat($fp) ); fclose($fp); } /** * stat() returns full data * * @test */ public function statReturnsFullDataForFiles() { $this->assertEquals(array(0 => 0, 1 => 0, 2 => 0100666, 3 => 0, 4 => vfsStream::getCurrentUser(), 5 => vfsStream::getCurrentGroup(), 6 => 0, 7 => 4, 8 => 400, 9 => 400, 10 => 400, 11 => -1, 12 => -1, 'dev' => 0, 'ino' => 0, 'mode' => 0100666, 'nlink' => 0, 'uid' => vfsStream::getCurrentUser(), 'gid' => vfsStream::getCurrentGroup(), 'rdev' => 0, 'size' => 4, 'atime' => 400, 'mtime' => 400, 'ctime' => 400, 'blksize' => -1, 'blocks' => -1 ), stat($this->baz2URL) ); } /** * @test */ public function statReturnsFullDataForDirectories() { $this->assertEquals(array(0 => 0, 1 => 0, 2 => 0040777, 3 => 0, 4 => vfsStream::getCurrentUser(), 5 => vfsStream::getCurrentGroup(), 6 => 0, 7 => 0, 8 => 100, 9 => 100, 10 => 100, 11 => -1, 12 => -1, 'dev' => 0, 'ino' => 0, 'mode' => 0040777, 'nlink' => 0, 'uid' => vfsStream::getCurrentUser(), 'gid' => vfsStream::getCurrentGroup(), 'rdev' => 0, 'size' => 0, 'atime' => 100, 'mtime' => 100, 'ctime' => 100, 'blksize' => -1, 'blocks' => -1 ), stat($this->fooURL) ); } /** * @test */ public function statReturnsFullDataForDirectoriesWithDot() { $this->assertEquals(array(0 => 0, 1 => 0, 2 => 0040777, 3 => 0, 4 => vfsStream::getCurrentUser(), 5 => vfsStream::getCurrentGroup(), 6 => 0, 7 => 0, 8 => 100, 9 => 100, 10 => 100, 11 => -1, 12 => -1, 'dev' => 0, 'ino' => 0, 'mode' => 0040777, 'nlink' => 0, 'uid' => vfsStream::getCurrentUser(), 'gid' => vfsStream::getCurrentGroup(), 'rdev' => 0, 'size' => 0, 'atime' => 100, 'mtime' => 100, 'ctime' => 100, 'blksize' => -1, 'blocks' => -1 ), stat($this->fooURL . '/.') ); } /** * @test * @expectedException PHPUnit_Framework_Error */ public function openFileWithoutDirectory() { vfsStreamWrapper::register(); $this->assertFalse(file_get_contents(vfsStream::url('file.txt'))); } /** * @test * @group issue_33 * @since 1.1.0 * @requires PHP 5.4.0 */ public function truncateRemovesSuperflouosContent() { if (strstr(PHP_VERSION, 'hiphop') !== false) { $this->markTestSkipped('Not supported on hhvm'); } $handle = fopen($this->baz1URL, "r+"); $this->assertTrue(ftruncate($handle, 0)); $this->assertEquals(0, filesize($this->baz1URL)); $this->assertEquals('', file_get_contents($this->baz1URL)); fclose($handle); } /** * @test * @group issue_33 * @since 1.1.0 * @requires PHP 5.4.0 */ public function truncateToGreaterSizeAddsZeroBytes() { if (strstr(PHP_VERSION, 'hiphop') !== false) { $this->markTestSkipped('Not supported on hhvm'); } $handle = fopen($this->baz1URL, "r+"); $this->assertTrue(ftruncate($handle, 25)); $this->assertEquals(25, filesize($this->baz1URL)); $this->assertEquals("baz 1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", file_get_contents($this->baz1URL)); fclose($handle); } /** * @test * @group issue_11 * @requires PHP 5.4.0 */ public function touchCreatesNonExistingFile() { $this->assertTrue(touch($this->fooURL . '/new.txt')); $this->assertTrue($this->foo->hasChild('new.txt')); } /** * @test * @group issue_11 * @requires PHP 5.4.0 */ public function touchChangesAccessAndModificationTimeForFile() { $this->assertTrue(touch($this->baz1URL, 303, 313)); $this->assertEquals(303, $this->baz1->filemtime()); $this->assertEquals(313, $this->baz1->fileatime()); } /** * @test * @group issue_11 * @group issue_80 * @requires PHP 5.4.0 */ public function touchChangesTimesToCurrentTimestampWhenNoTimesGiven() { $this->assertTrue(touch($this->baz1URL)); $this->assertEquals(time(), $this->baz1->filemtime(), '', 1); $this->assertEquals(time(), $this->baz1->fileatime(), '', 1); } /** * @test * @group issue_11 * @requires PHP 5.4.0 */ public function touchWithModifiedTimeChangesAccessAndModifiedTime() { $this->assertTrue(touch($this->baz1URL, 303)); $this->assertEquals(303, $this->baz1->filemtime()); $this->assertEquals(303, $this->baz1->fileatime()); } /** * @test * @group issue_11 * @requires PHP 5.4.0 */ public function touchChangesAccessAndModificationTimeForDirectory() { $this->assertTrue(touch($this->fooURL, 303, 313)); $this->assertEquals(303, $this->foo->filemtime()); $this->assertEquals(313, $this->foo->fileatime()); } /** * @test * @group issue_34 * @since 1.2.0 */ public function pathesAreCorrectlySet() { $this->assertEquals(vfsStream::path($this->fooURL), $this->foo->path()); $this->assertEquals(vfsStream::path($this->barURL), $this->bar->path()); $this->assertEquals(vfsStream::path($this->baz1URL), $this->baz1->path()); $this->assertEquals(vfsStream::path($this->baz2URL), $this->baz2->path()); } /** * @test * @group issue_34 * @since 1.2.0 */ public function urlsAreCorrectlySet() { $this->assertEquals($this->fooURL, $this->foo->url()); $this->assertEquals($this->barURL, $this->bar->url()); $this->assertEquals($this->baz1URL, $this->baz1->url()); $this->assertEquals($this->baz2URL, $this->baz2->url()); } /** * @test * @group issue_34 * @since 1.2.0 */ public function pathIsUpdatedAfterMove() { // move foo/bar/baz1 to foo/baz3 $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(rename($this->baz1URL, $baz3URL)); $this->assertEquals(vfsStream::path($baz3URL), $this->baz1->path()); } /** * @test * @group issue_34 * @since 1.2.0 */ public function urlIsUpdatedAfterMove() { // move foo/bar/baz1 to foo/baz3 $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(rename($this->baz1URL, $baz3URL)); $this->assertEquals($baz3URL, $this->baz1->url()); } /** * @test */ public function fileCopy() { $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(copy($this->baz1URL, $baz3URL)); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperUnregisterTestCase.php000066400000000000000000000036501355632626400304570ustar00rootroot00000000000000assertNotContains(vfsStream::SCHEME, stream_get_wrappers()); } /** * Unregistering a third party wrapper for vfs:// fails. * * @test * @expectedException org\bovigo\vfs\vfsStreamException * @runInSeparateProcess */ public function unregisterThirdPartyVfsScheme() { // Unregister possible registered URL wrapper. vfsStreamWrapper::unregister(); $mock = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamWrapper'); stream_wrapper_register(vfsStream::SCHEME, get_class($mock)); vfsStreamWrapper::unregister(); } /** * Unregistering when not in registered state will fail. * * @test * @expectedException org\bovigo\vfs\vfsStreamException * @runInSeparateProcess */ public function unregisterWhenNotInRegisteredState() { vfsStreamWrapper::register(); stream_wrapper_unregister(vfsStream::SCHEME); vfsStreamWrapper::unregister(); } /** * Unregistering while not registers won't fail. * * @test */ public function unregisterWhenNotRegistered() { // Unregister possible registered URL wrapper. vfsStreamWrapper::unregister(); $this->assertNotContains(vfsStream::SCHEME, stream_get_wrappers()); vfsStreamWrapper::unregister(); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamWrapperWithoutRootTestCase.php000066400000000000000000000023531355632626400306360ustar00rootroot00000000000000 no directory to open * * @test */ public function canNotOpenDirectory() { $this->assertFalse(@dir(vfsStream::url('foo'))); } /** * can not unlink without root * * @test */ public function canNotUnlink() { $this->assertFalse(@unlink(vfsStream::url('foo'))); } /** * can not open a file without root * * @test */ public function canNotOpen() { $this->assertFalse(@fopen(vfsStream::url('foo'), 'r')); } /** * can not rename a file without root * * @test */ public function canNotRename() { $this->assertFalse(@rename(vfsStream::url('foo'), vfsStream::url('bar'))); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/vfsStreamZipTestCase.php000066400000000000000000000030531355632626400255260ustar00rootroot00000000000000markTestSkipped('No ext/zip installed, skipping test.'); } $this->markTestSkipped('Zip extension can not work with vfsStream urls.'); vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(vfsStream::newDirectory('root')); } /** * @test */ public function createZipArchive() { $zip = new ZipArchive(); $this->assertTrue($zip->open(vfsStream::url('root/test.zip'), ZipArchive::CREATE)); $this->assertTrue($zip->addFromString("testfile1.txt", "#1 This is a test string added as testfile1.txt.\n")); $this->assertTrue($zip->addFromString("testfile2.txt", "#2 This is a test string added as testfile2.txt.\n")); $zip->setArchiveComment('a test'); var_dump($zip); $this->assertTrue($zip->close()); var_dump($zip->getStatusString()); var_dump($zip->close()); var_dump($zip->getStatusString()); var_dump($zip); var_dump(file_exists(vfsStream::url('root/test.zip'))); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/visitor/000077500000000000000000000000001355632626400224225ustar00rootroot00000000000000vfsStream-1.6.8/src/test/php/org/bovigo/vfs/visitor/vfsStreamAbstractVisitorTestCase.php000066400000000000000000000055751355632626400316210ustar00rootroot00000000000000abstractVisitor = $this->bc_getMock('org\\bovigo\\vfs\\visitor\\vfsStreamAbstractVisitor', array('visitFile', 'visitDirectory') ); } /** * @test * @expectedException \InvalidArgumentException */ public function visitThrowsInvalidArgumentExceptionOnUnknownContentType() { $mockContent = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockContent->expects($this->any()) ->method('getType') ->will($this->returnValue('invalid')); $this->assertSame($this->abstractVisitor, $this->abstractVisitor->visit($mockContent) ); } /** * @test */ public function visitWithFileCallsVisitFile() { $file = new vfsStreamFile('foo.txt'); $this->abstractVisitor->expects($this->once()) ->method('visitFile') ->with($this->equalTo($file)); $this->assertSame($this->abstractVisitor, $this->abstractVisitor->visit($file) ); } /** * tests that a block device eventually calls out to visit file * * @test */ public function visitWithBlockCallsVisitFile() { $block = new vfsStreamBlock('foo'); $this->abstractVisitor->expects($this->once()) ->method('visitFile') ->with($this->equalTo($block)); $this->assertSame($this->abstractVisitor, $this->abstractVisitor->visit($block) ); } /** * @test */ public function visitWithDirectoryCallsVisitDirectory() { $dir = new vfsStreamDirectory('bar'); $this->abstractVisitor->expects($this->once()) ->method('visitDirectory') ->with($this->equalTo($dir)); $this->assertSame($this->abstractVisitor, $this->abstractVisitor->visit($dir) ); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php000066400000000000000000000066461355632626400311520ustar00rootroot00000000000000at(vfsStream::setup()); $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb')); $this->assertSame($printVisitor, $printVisitor->visitFile(vfsStream::newFile('bar.txt')) ); $this->assertEquals("- bar.txt\n", $output->getContent()); } /** * @test */ public function visitFileWritesBlockDeviceToStream() { $output = vfsStream::newFile('foo.txt') ->at(vfsStream::setup()); $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb')); $this->assertSame($printVisitor, $printVisitor->visitBlockDevice(vfsStream::newBlock('bar')) ); $this->assertEquals("- [bar]\n", $output->getContent()); } /** * @test */ public function visitDirectoryWritesDirectoryNameToStream() { $output = vfsStream::newFile('foo.txt') ->at(vfsStream::setup()); $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb')); $this->assertSame($printVisitor, $printVisitor->visitDirectory(vfsStream::newDirectory('baz')) ); $this->assertEquals("- baz\n", $output->getContent()); } /** * @test */ public function visitRecursiveDirectoryStructure() { $root = vfsStream::setup('root', null, array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world' ), 'foo.txt' => '' ) ); $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb')); $this->assertSame($printVisitor, $printVisitor->visitDirectory($root) ); $this->assertEquals("- root\n - test\n - foo\n - test.txt\n - baz.txt\n - foo.txt\n", file_get_contents('vfs://root/foo.txt')); } } vfsStream-1.6.8/src/test/php/org/bovigo/vfs/visitor/vfsStreamStructureVisitorTestCase.php000066400000000000000000000061241355632626400320450ustar00rootroot00000000000000assertEquals(array('foo.txt' => 'test'), $structureVisitor->visitFile(vfsStream::newFile('foo.txt') ->withContent('test') ) ->getStructure() ); } /** * @test */ public function visitFileCreatesStructureForBlock() { $structureVisitor = new vfsStreamStructureVisitor(); $this->assertEquals(array('[foo]' => 'test'), $structureVisitor->visitBlockDevice(vfsStream::newBlock('foo') ->withContent('test') ) ->getStructure() ); } /** * @test */ public function visitDirectoryCreatesStructureForDirectory() { $structureVisitor = new vfsStreamStructureVisitor(); $this->assertEquals(array('baz' => array()), $structureVisitor->visitDirectory(vfsStream::newDirectory('baz')) ->getStructure() ); } /** * @test */ public function visitRecursiveDirectoryStructure() { $root = vfsStream::setup('root', null, array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world' ), 'foo.txt' => '' ) ); $structureVisitor = new vfsStreamStructureVisitor(); $this->assertEquals(array('root' => array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world' ), 'foo.txt' => '' ), ), $structureVisitor->visitDirectory($root) ->getStructure() ); } } vfsStream-1.6.8/src/test/phpt/000077500000000000000000000000001355632626400162355ustar00rootroot00000000000000vfsStream-1.6.8/src/test/phpt/bug71287.phpt000066400000000000000000000011251355632626400203170ustar00rootroot00000000000000--TEST-- Reproduce octal output from stream wrapper invocation See https://bugs.php.net/bug.php?id=71287 See https://github.com/mikey179/vfsStream/issues/120 --FILE-- --EXPECTF-- Warning: file_put_contents(): Only 7 of 9 bytes written, possibly out of free disk space in %s on line %dvfsStream-1.6.8/src/test/resources/000077500000000000000000000000001355632626400172745ustar00rootroot00000000000000vfsStream-1.6.8/src/test/resources/filesystemcopy/000077500000000000000000000000001355632626400223535ustar00rootroot00000000000000vfsStream-1.6.8/src/test/resources/filesystemcopy/emptyFolder/000077500000000000000000000000001355632626400246455ustar00rootroot00000000000000vfsStream-1.6.8/src/test/resources/filesystemcopy/emptyFolder/.gitignore000066400000000000000000000000001355632626400266230ustar00rootroot00000000000000vfsStream-1.6.8/src/test/resources/filesystemcopy/withSubfolders/000077500000000000000000000000001355632626400253575ustar00rootroot00000000000000vfsStream-1.6.8/src/test/resources/filesystemcopy/withSubfolders/aFile.txt000066400000000000000000000000031355632626400271310ustar00rootroot00000000000000foovfsStream-1.6.8/src/test/resources/filesystemcopy/withSubfolders/subfolder1/000077500000000000000000000000001355632626400274255ustar00rootroot00000000000000vfsStream-1.6.8/src/test/resources/filesystemcopy/withSubfolders/subfolder1/file1.txt000066400000000000000000000000061355632626400311620ustar00rootroot00000000000000foobarvfsStream-1.6.8/src/test/resources/filesystemcopy/withSubfolders/subfolder2/000077500000000000000000000000001355632626400274265ustar00rootroot00000000000000vfsStream-1.6.8/src/test/resources/filesystemcopy/withSubfolders/subfolder2/.gitignore000066400000000000000000000000001355632626400314040ustar00rootroot00000000000000