recreate project
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- v1.6
|
||||
pull_request:
|
||||
branches:
|
||||
- v1.6
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: PHP ${{ matrix.php-versions }} on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php-versions:
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
- '7.3'
|
||||
- '7.4'
|
||||
- '8.0'
|
||||
- '8.1'
|
||||
- '8.2'
|
||||
- '8.3'
|
||||
- '8.4'
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up PHP ${{ matrix.php-versions }}
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
extensions: mbstring
|
||||
coverage: pcov
|
||||
|
||||
- name: Setup Problem Matchers for PHP
|
||||
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
|
||||
|
||||
- name: Setup Problem Matchers for PHPUnit
|
||||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate
|
||||
|
||||
- name: Get Composer Cache Directory
|
||||
id: composer-cache
|
||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: ${{ runner.os }}-composer-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
composer install --prefer-dist --no-progress
|
||||
|
||||
- name: Run test suite
|
||||
if: matrix.php-versions == '7.1'
|
||||
run: composer run-script test -- --no-coverage
|
||||
|
||||
- name: Run test suite
|
||||
if: matrix.php-versions > '7.1'
|
||||
run: composer run-script test -- --coverage-text
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
1.6.12 (2024-08-29)
|
||||
-------------------
|
||||
|
||||
* Drop php 5 and 7.0 support as new versions enforced a syntax change that is not compatible with the old versions.
|
||||
|
||||
1.6.11 (2022-07-26)
|
||||
-------------------
|
||||
|
||||
* Add support for PHP 8.2's `$content` property in `vfsStreamWrapper`
|
||||
|
||||
1.6.10 (2021-09-25)
|
||||
-------------------
|
||||
|
||||
* Fix more deprecation warnings for PHP 8.1 support affecting the following:
|
||||
- `vfsStreamContainerIterator::current()`
|
||||
- `vfsStreamContainerIterator::next()`
|
||||
- `vfsStreamContainerIterator::key()`
|
||||
- `vfsStreamContainerIterator::rewind()`
|
||||
- `vfsStreamDirectory::getIterator()`
|
||||
- `vfsStreamPrintVisitor::printContent()`
|
||||
* Fix PHP 8.1 support in `vfsStreamPrintVisitor`
|
||||
|
||||
1.6.9 (2021-07-16)
|
||||
------------------
|
||||
|
||||
* Fix deprecation warning on `StringBasedFileContent` for PHP 8.1 (#252)
|
||||
* Fix return type for `FileContent::write()` to fix static analysis tools
|
||||
|
||||
1.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.
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
Copyright (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.
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
You 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).
|
||||
|
||||
|
||||
[](http://travis-ci.org/mikey179/vfsStream) [](https://ci.appveyor.com/project/mikey179/vfsstream) [](https://coveralls.io/github/bovigo/vfsStream?branch=v1.x)
|
||||
|
||||
[](https://packagist.org/packages/mikey179/vfsStream) [](//packagist.org/packages/mikey179/vfsStream)
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"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": ">=7.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5||^8.5||^9.6",
|
||||
"yoast/phpunit-polyfills": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "org\\bovigo\\vfs\\": "src/main/php" }
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.6.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="src/test/bootstrap.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
forceCoversAnnotation="false"
|
||||
mapTestClassNameToCoveredClassName="false"
|
||||
processIsolation="false"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
verbose="true">
|
||||
<testsuites>
|
||||
<testsuite>
|
||||
<directory suffix=".phpt">./src/test/phpt</directory>
|
||||
<directory suffix="TestCase.php">./src/test/php</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>src/main/php</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-html" target="docs/coverage" charset="UTF-8"
|
||||
yui="true" highlight="false"
|
||||
lowUpperBound="35" highLowerBound="70"/>
|
||||
<log type="coverage-clover" target="docs/phpunit/clover.xml"/>
|
||||
<log type="junit" target="docs/phpunit/junit.xml" logIncompleteSkipped="false"/>
|
||||
<log type="testdox-html" target="docs/phpunit/testdox.html"/>
|
||||
</logging>
|
||||
|
||||
<php>
|
||||
<ini name="memory_limit" value="-1"/>
|
||||
<ini name="error_reporting" value="30719"/> <!-- E_ALL | E_STRICT -->
|
||||
</php>
|
||||
</phpunit>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Directory container.
|
||||
*/
|
||||
class DotDirectory extends vfsStreamDirectory
|
||||
{
|
||||
/**
|
||||
* returns iterator for the children
|
||||
*
|
||||
* @return vfsStreamContainerIterator
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether dir is a dot dir
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDot()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Represents a quota for disk space.
|
||||
*
|
||||
* @since 1.1.0
|
||||
* @internal
|
||||
*/
|
||||
class Quota
|
||||
{
|
||||
/**
|
||||
* unlimited quota
|
||||
*/
|
||||
const UNLIMITED = -1;
|
||||
/**
|
||||
* quota in bytes
|
||||
*
|
||||
* A value of -1 is treated as unlimited.
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param int $amount quota in bytes
|
||||
*/
|
||||
public function __construct($amount)
|
||||
{
|
||||
$this->amount = $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;
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\content;
|
||||
/**
|
||||
* Interface for actual file contents.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
interface FileContent
|
||||
{
|
||||
/**
|
||||
* returns actual content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function content();
|
||||
|
||||
/**
|
||||
* returns size of content
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function size();
|
||||
|
||||
/**
|
||||
* reads the given amount of bytes from content
|
||||
*
|
||||
* @param int $count
|
||||
* @return string
|
||||
*/
|
||||
public function read($count);
|
||||
|
||||
/**
|
||||
* seeks to the given offset
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $whence
|
||||
* @return bool
|
||||
*/
|
||||
public function seek($offset, $whence);
|
||||
|
||||
/**
|
||||
* checks whether pointer is at end of file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function eof();
|
||||
|
||||
/**
|
||||
* writes an amount of data
|
||||
*
|
||||
* @param string $data
|
||||
* @return int amount of written bytes
|
||||
*/
|
||||
public function write($data);
|
||||
|
||||
/**
|
||||
* Truncates a file to a given length
|
||||
*
|
||||
* @param int $size length to truncate file to
|
||||
* @return bool
|
||||
*/
|
||||
public function truncate($size);
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\content;
|
||||
/**
|
||||
* File content implementation to mock large files.
|
||||
*
|
||||
* When content is written via write() the data will be written into the
|
||||
* positions according to the current offset.
|
||||
* When content is read via read() it will use the already written data. If no
|
||||
* data is written at the offsets to read those offsets will be filled with
|
||||
* spaces.
|
||||
* Please note that accessing the whole content via content() will deliver a
|
||||
* string with the length of the originally defined size. It is not advisable to
|
||||
* do so with large sizes, except you have enough memory and time. :-)
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
class LargeFileContent extends SeekableFileContent implements FileContent
|
||||
{
|
||||
/**
|
||||
* byte array of written content
|
||||
*
|
||||
* @type char[]
|
||||
*/
|
||||
private $content = array();
|
||||
/**
|
||||
* file size in bytes
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param int $size file size in bytes
|
||||
*/
|
||||
public function __construct($size)
|
||||
{
|
||||
$this->size = $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;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\content;
|
||||
/**
|
||||
* Default implementation for file contents based on simple strings.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
abstract class SeekableFileContent implements FileContent
|
||||
{
|
||||
/**
|
||||
* current position within content
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
private $offset = 0;
|
||||
|
||||
/**
|
||||
* reads the given amount of bytes from content
|
||||
*
|
||||
* @param int $count
|
||||
* @return string
|
||||
*/
|
||||
public function read($count)
|
||||
{
|
||||
$data = $this->doRead($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 int 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);
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\content;
|
||||
/**
|
||||
* Default implementation for file contents based on simple strings.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
class StringBasedFileContent extends SeekableFileContent implements FileContent
|
||||
{
|
||||
/**
|
||||
* actual content
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $content
|
||||
*/
|
||||
public function __construct($content)
|
||||
{
|
||||
$this->content = $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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,479 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
use org\bovigo\vfs\content\LargeFileContent;
|
||||
use org\bovigo\vfs\content\FileContent;
|
||||
use org\bovigo\vfs\visitor\vfsStreamVisitor;
|
||||
/**
|
||||
* Some utility methods for vfsStream.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class vfsStream
|
||||
{
|
||||
/**
|
||||
* url scheme
|
||||
*/
|
||||
const SCHEME = 'vfs';
|
||||
/**
|
||||
* owner: root
|
||||
*/
|
||||
const OWNER_ROOT = 0;
|
||||
/**
|
||||
* owner: user 1
|
||||
*/
|
||||
const OWNER_USER_1 = 1;
|
||||
/**
|
||||
* owner: user 2
|
||||
*/
|
||||
const OWNER_USER_2 = 2;
|
||||
/**
|
||||
* group: root
|
||||
*/
|
||||
const GROUP_ROOT = 0;
|
||||
/**
|
||||
* group: user 1
|
||||
*/
|
||||
const GROUP_USER_1 = 1;
|
||||
/**
|
||||
* group: user 2
|
||||
*/
|
||||
const GROUP_USER_2 = 2;
|
||||
/**
|
||||
* initial umask setting
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected static $umask = 0000;
|
||||
/**
|
||||
* switch whether dotfiles are enabled in directory listings
|
||||
*
|
||||
* @type bool
|
||||
*/
|
||||
private static $dotFiles = true;
|
||||
|
||||
/**
|
||||
* prepends the scheme to the given URL
|
||||
*
|
||||
* @param string $path path to translate to vfsStream url
|
||||
* @return string
|
||||
*/
|
||||
public static function url($path)
|
||||
{
|
||||
return self::SCHEME . '://' . join(
|
||||
'/',
|
||||
array_map(
|
||||
'rawurlencode', // ensure singe path parts are correctly urlencoded
|
||||
explode(
|
||||
'/',
|
||||
str_replace('\\', '/', $path) // ensure correct directory separator
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* restores the path from the url
|
||||
*
|
||||
* @param string $url vfsStream url to translate into path
|
||||
* @return string
|
||||
*/
|
||||
public static function path($url)
|
||||
{
|
||||
// remove line feeds and trailing whitespaces and path separators
|
||||
$path = trim($url, " \t\r\n\0\x0B/\\");
|
||||
$path = substr($path, strlen(self::SCHEME . '://'));
|
||||
$path = str_replace('\\', '/', $path);
|
||||
// replace double slashes with single slashes
|
||||
$path = str_replace('//', '/', $path);
|
||||
return rawurldecode($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets new umask setting and returns previous umask setting
|
||||
*
|
||||
* If no value is given only the current umask setting is returned.
|
||||
*
|
||||
* @param int $umask new umask setting
|
||||
* @return int
|
||||
* @since 0.8.0
|
||||
*/
|
||||
public static function umask($umask = null)
|
||||
{
|
||||
$oldUmask = self::$umask;
|
||||
if (null !== $umask) {
|
||||
self::$umask = $umask;
|
||||
}
|
||||
|
||||
return $oldUmask;
|
||||
}
|
||||
|
||||
/**
|
||||
* helper method for setting up vfsStream in unit tests
|
||||
*
|
||||
* Instead of
|
||||
* vfsStreamWrapper::register();
|
||||
* vfsStreamWrapper::setRoot(vfsStream::newDirectory('root'));
|
||||
* you can simply do
|
||||
* vfsStream::setup()
|
||||
* which yields the same result. Additionally, the method returns the
|
||||
* freshly created root directory which you can use to make further
|
||||
* adjustments to it.
|
||||
*
|
||||
* Assumed $structure contains an array like this:
|
||||
* <code>
|
||||
* 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',
|
||||
* )
|
||||
* )
|
||||
* </code>
|
||||
* the resulting directory tree will look like this:
|
||||
* <pre>
|
||||
* root
|
||||
* \- Core
|
||||
* |- badlocation.php
|
||||
* |- AbstractFactory
|
||||
* | |- test.php
|
||||
* | |- other.php
|
||||
* | \- Invalid.csv
|
||||
* \- AnEmptyFolder
|
||||
* </pre>
|
||||
* 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:
|
||||
* <code>
|
||||
* 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',
|
||||
* )
|
||||
* )
|
||||
* </code>
|
||||
* the resulting directory tree will look like this:
|
||||
* <pre>
|
||||
* baseDir
|
||||
* \- Core
|
||||
* |- badlocation.php
|
||||
* |- AbstractFactory
|
||||
* | |- test.php
|
||||
* | |- other.php
|
||||
* | \- Invalid.csv
|
||||
* \- AnEmptyFolder
|
||||
* </pre>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
+418
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Base stream contents container.
|
||||
*/
|
||||
abstract class vfsStreamAbstractContent implements vfsStreamContent
|
||||
{
|
||||
/**
|
||||
* name of the container
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
protected $name;
|
||||
/**
|
||||
* type of the container
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
protected $type;
|
||||
/**
|
||||
* timestamp of last access
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected $lastAccessed;
|
||||
/**
|
||||
* timestamp of last attribute modification
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected $lastAttributeModified;
|
||||
/**
|
||||
* timestamp of last modification
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected $lastModified;
|
||||
/**
|
||||
* permissions for content
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected $permissions;
|
||||
/**
|
||||
* owner of the file
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected $user;
|
||||
/**
|
||||
* owner group of the file
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected $group;
|
||||
/**
|
||||
* path to to this content
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
private $parentPath;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $permissions optional
|
||||
*/
|
||||
public function __construct($name, $permissions = null)
|
||||
{
|
||||
$this->name = "{$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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
|
||||
/**
|
||||
* Block container.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class vfsStreamBlock extends vfsStreamFile
|
||||
{
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $permissions optional
|
||||
*/
|
||||
public function __construct($name, $permissions = null)
|
||||
{
|
||||
if (empty($name)) {
|
||||
throw new vfsStreamException('Name of Block device was empty');
|
||||
}
|
||||
parent::__construct($name, $permissions);
|
||||
|
||||
$this->type = vfsStreamContent::TYPE_BLOCK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Interface for stream contents that are able to store other stream contents.
|
||||
*/
|
||||
interface vfsStreamContainer extends \IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* adds child to the directory
|
||||
*
|
||||
* @param vfsStreamContent $child
|
||||
*/
|
||||
public function addChild(vfsStreamContent $child);
|
||||
|
||||
/**
|
||||
* removes child from the directory
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function removeChild($name);
|
||||
|
||||
/**
|
||||
* checks whether the container contains a child with the given name
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChild($name);
|
||||
|
||||
/**
|
||||
* returns the child with the given name
|
||||
*
|
||||
* @param string $name
|
||||
* @return vfsStreamContent
|
||||
*/
|
||||
public function getChild($name);
|
||||
|
||||
/**
|
||||
* checks whether directory contains any children
|
||||
*
|
||||
* @return bool
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public function hasChildren();
|
||||
|
||||
/**
|
||||
* returns a list of children for this directory
|
||||
*
|
||||
* @return vfsStreamContent[]
|
||||
*/
|
||||
public function getChildren();
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Iterator for children of a directory container.
|
||||
*/
|
||||
class vfsStreamContainerIterator implements \Iterator
|
||||
{
|
||||
/**
|
||||
* list of children from container to iterate over
|
||||
*
|
||||
* @type vfsStreamContent[]
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param vfsStreamContent[] $children
|
||||
*/
|
||||
public function __construct(array $children)
|
||||
{
|
||||
$this->children = $children;
|
||||
if (vfsStream::useDotfiles()) {
|
||||
array_unshift($this->children, new DotDirectory('.'), new DotDirectory('..'));
|
||||
}
|
||||
|
||||
reset($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* resets children pointer
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current child
|
||||
*
|
||||
* @return vfsStreamContent
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
$child = current($this->children);
|
||||
if (false === $child) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $child;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of the current child
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
$child = current($this->children);
|
||||
if (false === $child) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $child->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* iterates to next child
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function next()
|
||||
{
|
||||
next($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the current value is valid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function valid()
|
||||
{
|
||||
return (false !== current($this->children));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Interface for stream contents.
|
||||
*/
|
||||
interface vfsStreamContent
|
||||
{
|
||||
/**
|
||||
* stream content type: file
|
||||
*
|
||||
* @see getType()
|
||||
*/
|
||||
const TYPE_FILE = 0100000;
|
||||
/**
|
||||
* stream content type: directory
|
||||
*
|
||||
* @see getType()
|
||||
*/
|
||||
const TYPE_DIR = 0040000;
|
||||
/**
|
||||
* stream content type: symbolic link
|
||||
*
|
||||
* @see getType();
|
||||
*/
|
||||
#const TYPE_LINK = 0120000;
|
||||
|
||||
/**
|
||||
* stream content type: block
|
||||
*
|
||||
* @see getType()
|
||||
*/
|
||||
const TYPE_BLOCK = 0060000;
|
||||
|
||||
/**
|
||||
* returns the file name of the content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* renames the content
|
||||
*
|
||||
* @param string $newName
|
||||
*/
|
||||
public function rename($newName);
|
||||
|
||||
/**
|
||||
* checks whether the container can be applied to given name
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function appliesTo($name);
|
||||
|
||||
/**
|
||||
* returns the type of the container
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getType();
|
||||
|
||||
/**
|
||||
* returns size of content
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function size();
|
||||
|
||||
/**
|
||||
* sets the last modification time of the stream content
|
||||
*
|
||||
* @param int $filemtime
|
||||
* @return vfsStreamContent
|
||||
*/
|
||||
public function lastModified($filemtime);
|
||||
|
||||
/**
|
||||
* returns the last modification time of the stream content
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function filemtime();
|
||||
|
||||
/**
|
||||
* adds content to given container
|
||||
*
|
||||
* @param vfsStreamContainer $container
|
||||
* @return vfsStreamContent
|
||||
*/
|
||||
public function at(vfsStreamContainer $container);
|
||||
|
||||
/**
|
||||
* change file mode to given permissions
|
||||
*
|
||||
* @param int $permissions
|
||||
* @return vfsStreamContent
|
||||
*/
|
||||
public function chmod($permissions);
|
||||
|
||||
/**
|
||||
* returns permissions
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPermissions();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* change owner of file to given user
|
||||
*
|
||||
* @param int $user
|
||||
* @return vfsStreamContent
|
||||
*/
|
||||
public function chown($user);
|
||||
|
||||
/**
|
||||
* checks whether file is owned by given user
|
||||
*
|
||||
* @param int $user
|
||||
* @return bool
|
||||
*/
|
||||
public function isOwnedByUser($user);
|
||||
|
||||
/**
|
||||
* returns owner of file
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getUser();
|
||||
|
||||
/**
|
||||
* change owner group of file to given group
|
||||
*
|
||||
* @param int $group
|
||||
* @return vfsStreamContent
|
||||
*/
|
||||
public function chgrp($group);
|
||||
|
||||
/**
|
||||
* checks whether file is owned by group
|
||||
*
|
||||
* @param int $group
|
||||
* @return bool
|
||||
*/
|
||||
public function isOwnedByGroup($group);
|
||||
|
||||
/**
|
||||
* returns owner group of file
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getGroup();
|
||||
|
||||
/**
|
||||
* sets parent path
|
||||
*
|
||||
* @param string $parentPath
|
||||
* @internal only to be set by parent
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public function setParentPath($parentPath);
|
||||
|
||||
/**
|
||||
* returns path to this content
|
||||
*
|
||||
* @return string
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public function path();
|
||||
|
||||
/**
|
||||
* returns complete vfsStream url for this content
|
||||
*
|
||||
* @return string
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public function url();
|
||||
}
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Directory container.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class vfsStreamDirectory extends vfsStreamAbstractContent implements vfsStreamContainer
|
||||
{
|
||||
/**
|
||||
* list of directory children
|
||||
*
|
||||
* @type vfsStreamContent[]
|
||||
*/
|
||||
protected $children = array();
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $permissions optional
|
||||
* @throws vfsStreamException
|
||||
*/
|
||||
public function __construct($name, $permissions = null)
|
||||
{
|
||||
if (strstr($name, '/') !== false) {
|
||||
throw new vfsStreamException('Directory name can not contain /.');
|
||||
}
|
||||
|
||||
$this->type = 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
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Exception for vfsStream errors.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class vfsStreamException extends \Exception
|
||||
{
|
||||
// intentionally empty
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
use org\bovigo\vfs\content\FileContent;
|
||||
use org\bovigo\vfs\content\StringBasedFileContent;
|
||||
/**
|
||||
* File container.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class vfsStreamFile extends vfsStreamAbstractContent
|
||||
{
|
||||
/**
|
||||
* content of the file
|
||||
*
|
||||
* @type FileContent
|
||||
*/
|
||||
private $content;
|
||||
/**
|
||||
* Resource id which exclusively locked this file
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
protected $exclusiveLock;
|
||||
/**
|
||||
* Resources ids which currently holds shared lock to this file
|
||||
*
|
||||
* @type bool[string]
|
||||
*/
|
||||
protected $sharedLock = array();
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $permissions optional
|
||||
*/
|
||||
public function __construct($name, $permissions = null)
|
||||
{
|
||||
$this->content = new StringBasedFileContent('');
|
||||
$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 int 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;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\visitor;
|
||||
use org\bovigo\vfs\vfsStreamContent;
|
||||
use org\bovigo\vfs\vfsStreamBlock;
|
||||
|
||||
/**
|
||||
* Abstract base class providing an implementation for the visit() method.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/10
|
||||
*/
|
||||
abstract class vfsStreamAbstractVisitor implements vfsStreamVisitor
|
||||
{
|
||||
/**
|
||||
* visit a content and process it
|
||||
*
|
||||
* @param vfsStreamContent $content
|
||||
* @return vfsStreamVisitor
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function visit(vfsStreamContent $content)
|
||||
{
|
||||
switch ($content->getType()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\visitor;
|
||||
use org\bovigo\vfs\vfsStreamContent;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use org\bovigo\vfs\vfsStreamFile;
|
||||
use org\bovigo\vfs\vfsStreamBlock;
|
||||
|
||||
/**
|
||||
* Visitor which traverses a content structure recursively to print it to an output stream.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/10
|
||||
*/
|
||||
class vfsStreamPrintVisitor extends vfsStreamAbstractVisitor
|
||||
{
|
||||
/**
|
||||
* target to write output to
|
||||
*
|
||||
* @type resource
|
||||
*/
|
||||
protected $out;
|
||||
/**
|
||||
* current depth in directory tree
|
||||
*
|
||||
* @type int
|
||||
*/
|
||||
protected $depth;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* If no file pointer given it will fall back to STDOUT.
|
||||
*
|
||||
* @param resource $out optional
|
||||
* @throws \InvalidArgumentException
|
||||
* @api
|
||||
*/
|
||||
public function __construct($out = STDOUT)
|
||||
{
|
||||
if (is_resource($out) === false || get_resource_type($out) !== 'stream') {
|
||||
throw new \InvalidArgumentException('Given filepointer is not a resource of type stream');
|
||||
}
|
||||
|
||||
$this->out = $out;
|
||||
$this->depth = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
}
|
||||
Vendored
+111
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\visitor;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use org\bovigo\vfs\vfsStreamFile;
|
||||
use org\bovigo\vfs\vfsStreamBlock;
|
||||
|
||||
/**
|
||||
* Visitor which traverses a content structure recursively to create an array structure from it.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/10
|
||||
*/
|
||||
class vfsStreamStructureVisitor extends vfsStreamAbstractVisitor
|
||||
{
|
||||
/**
|
||||
* collected structure
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $structure = array();
|
||||
/**
|
||||
* poiting to currently iterated directory
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $current;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\visitor;
|
||||
use org\bovigo\vfs\vfsStreamContent;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use org\bovigo\vfs\vfsStreamFile;
|
||||
use org\bovigo\vfs\vfsStreamBlock;
|
||||
|
||||
/**
|
||||
* Interface for a visitor to work on a vfsStream content structure.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/10
|
||||
*/
|
||||
interface vfsStreamVisitor
|
||||
{
|
||||
/**
|
||||
* visit a content and process it
|
||||
*
|
||||
* @param vfsStreamContent $content
|
||||
* @return vfsStreamVisitor
|
||||
*/
|
||||
public function visit(vfsStreamContent $content);
|
||||
|
||||
/**
|
||||
* visit a file and process it
|
||||
*
|
||||
* @param vfsStreamFile $file
|
||||
* @return vfsStreamVisitor
|
||||
*/
|
||||
public function visitFile(vfsStreamFile $file);
|
||||
|
||||
/**
|
||||
* visit a directory and process it
|
||||
*
|
||||
* @param vfsStreamDirectory $dir
|
||||
* @return vfsStreamVisitor
|
||||
*/
|
||||
public function visitDirectory(vfsStreamDirectory $dir);
|
||||
|
||||
/**
|
||||
* visit a block device and process it
|
||||
*
|
||||
* @param vfsStreamBlock $block
|
||||
* @return vfsStreamVisitor
|
||||
*/
|
||||
public function visitBlockDevice(vfsStreamBlock $block);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . "/../../vendor/autoload.php";
|
||||
|
||||
if (!class_exists("PHPUnit_Framework_TestCase"))
|
||||
{
|
||||
class_alias('\PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
|
||||
}
|
||||
|
||||
if (!class_exists("PHPUnit_Framework_Error"))
|
||||
{
|
||||
class_alias('PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error');
|
||||
}
|
||||
|
||||
/**
|
||||
* A modified version of PHPUnit's TestCase to rid ourselves of deprecation
|
||||
* warnings since we're using two different versions of PHPUnit in this branch
|
||||
* (PHPUnit 4 and 5).
|
||||
*/
|
||||
class BC_PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
use \Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
|
||||
|
||||
public function bc_expectException($exception)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($exception);
|
||||
} elseif (method_exists($this, 'setExpectedException')) {
|
||||
$this->setExpectedException($exception);
|
||||
}
|
||||
}
|
||||
|
||||
// A BC hack to get handle the deprecation of this method in PHPUnit
|
||||
public function bc_getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null)
|
||||
{
|
||||
if (method_exists($this, "getMockBuilder")) {
|
||||
return $this
|
||||
->getMockBuilder($originalClassName)
|
||||
->setMethods($methods)
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
return parent::getMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
|
||||
}
|
||||
}
|
||||
+318
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php';
|
||||
/**
|
||||
* Test for directory iteration.
|
||||
*
|
||||
* @group dir
|
||||
* @group iteration
|
||||
*/
|
||||
class DirectoryIterationTestCase extends vfsStreamWrapperBaseTestCase
|
||||
{
|
||||
/**
|
||||
* clean up test environment
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
vfsStream::enableDotfiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function provideSwitchWithExpectations()
|
||||
{
|
||||
return array(array(function() { vfsStream::disableDotfiles(); }, array('bar', 'baz2')),
|
||||
array(function() { vfsStream::enableDotfiles(); }, array('.', '..', 'bar', 'baz2'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* assertion for directoy count
|
||||
*
|
||||
* @param int $expectedCount
|
||||
* @param int $actualCount
|
||||
*/
|
||||
private function assertDirectoryCount($expectedCount, $actualCount)
|
||||
{
|
||||
$this->assertEquals($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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for directory iteration.
|
||||
*
|
||||
* @group issue_104
|
||||
* @group issue_128
|
||||
* @since 1.6.2
|
||||
*/
|
||||
class FilenameTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $rootDir;
|
||||
private $lostAndFound;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
vfsStream::setup('root');
|
||||
$this->rootDir = 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
|
||||
*/
|
||||
public function doesNotWorkWithInvalidName()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage('ailed to open dir');
|
||||
$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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* @group issue_104
|
||||
* @group issue_128
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Issue104TestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function vfsStreamCanHandleUrlEncodedPathPassedByInternalPhpCode()
|
||||
{
|
||||
$structure = array('foo bar' => array(
|
||||
'schema.xsd' => '<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:complexType name="myType"></xs:complexType>
|
||||
</xs:schema>',
|
||||
)
|
||||
);
|
||||
vfsStream::setup('root', null, $structure);
|
||||
$doc = new \DOMDocument();
|
||||
$this->assertTrue($doc->load(vfsStream::url('root/foo bar/schema.xsd')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function vfsStreamCanHandleUrlEncodedPath()
|
||||
{
|
||||
$content = '<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:complexType name="myType"></xs:complexType>
|
||||
</xs:schema>';
|
||||
$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'))
|
||||
);
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
use PHPUnit\Framework\Error;
|
||||
|
||||
/**
|
||||
* Test for permissions related functionality.
|
||||
*
|
||||
* @group permissions
|
||||
*/
|
||||
class PermissionsTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @type vfsStreamDirectory
|
||||
*/
|
||||
private $root;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$structure = array('test_directory' => 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
|
||||
* @requires PHP 5.4
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function touchOnNonWriteableDirectoryTriggersError()
|
||||
{
|
||||
$this->expectException(Error\Warning::class);
|
||||
$this->expectExceptionMessage('Can not create new file in non-writable path root');
|
||||
|
||||
$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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\Quota.
|
||||
*
|
||||
* @group issue_35
|
||||
*/
|
||||
class QuotaTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* instance to test
|
||||
*
|
||||
* @type Quota
|
||||
*/
|
||||
private $quota;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->quota = 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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for unlink() functionality.
|
||||
*
|
||||
* @group unlink
|
||||
*/
|
||||
class UnlinkTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @group issue_51
|
||||
*/
|
||||
public function canRemoveNonWritableFileFromWritableDirectory()
|
||||
{
|
||||
$structure = array('test_directory' => 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\content;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\content\LargeFileContent.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @group issue_79
|
||||
*/
|
||||
class LargeFileContentTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* instance to test
|
||||
*
|
||||
* @type LargeFileContent
|
||||
*/
|
||||
private $largeFileContent;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->largeFileContent = 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()
|
||||
);
|
||||
}
|
||||
}
|
||||
Vendored
+232
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\content;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\content\StringBasedFileContent.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @group issue_79
|
||||
*/
|
||||
class StringBasedFileContentTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* instance to test
|
||||
*
|
||||
* @type StringBasedFileContent
|
||||
*/
|
||||
private $stringBasedFileContent;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->stringBasedFileContent = 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());
|
||||
}
|
||||
}
|
||||
Vendored
+325
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Stream wrapper to mock file system requests.
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class vfsStreamWrapperRecordingProxy extends vfsStreamWrapper
|
||||
{
|
||||
/**
|
||||
* list of called methods for a stream
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $calledMethods = array();
|
||||
/**
|
||||
* currently opened path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* records method call for given path
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
*/
|
||||
protected static function recordMethodCall($method, $path)
|
||||
{
|
||||
if (isset(self::$calledMethods[$path]) === false) {
|
||||
self::$calledMethods[$path] = array();
|
||||
}
|
||||
|
||||
self::$calledMethods[$path][] = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns recorded method calls for given path
|
||||
*
|
||||
* @param string $path
|
||||
* @return array<string>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
+1053
File diff suppressed because it is too large
Load Diff
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamBlock.
|
||||
*/
|
||||
class vfsStreamBlockTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* The block device being tested.
|
||||
*
|
||||
* @var vfsStreamBlock $block
|
||||
*/
|
||||
protected $block;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->block = 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
|
||||
*/
|
||||
public function createWithEmptyName()
|
||||
{
|
||||
$this->expectException(vfsStreamException::class);
|
||||
$structure = array(
|
||||
'topLevel' => array(
|
||||
'thisIsAFile' => 'file contents',
|
||||
'[]' => 'block contents'
|
||||
)
|
||||
);
|
||||
|
||||
$root = vfsStream::create($structure);
|
||||
}
|
||||
}
|
||||
Vendored
+111
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamContainerIterator.
|
||||
*/
|
||||
class vfsStreamContainerIteratorTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* instance to test
|
||||
*
|
||||
* @type vfsStreamDirectory
|
||||
*/
|
||||
private $dir;
|
||||
/**
|
||||
* child one
|
||||
*
|
||||
* @type \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $mockChild1;
|
||||
/**
|
||||
* child two
|
||||
*
|
||||
* @type \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $mockChild2;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->dir = 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(): void
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* Project: vfsStream
|
||||
* User: Sebastian Hopfe
|
||||
* Date: 14.07.16
|
||||
* Time: 14:07
|
||||
*/
|
||||
|
||||
namespace org\bovigo\vfs;
|
||||
|
||||
|
||||
class vfsStreamDirectoryIssue134TestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* access to root directory
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $rootDirectory;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->rootDirectory = 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'));
|
||||
}
|
||||
}
|
||||
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamDirectory.
|
||||
*
|
||||
* @group bug_18
|
||||
*/
|
||||
class vfsStreamDirectoryIssue18TestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* access to root directory
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $rootDirectory;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->rootDirectory = 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')
|
||||
);
|
||||
}
|
||||
}
|
||||
+334
@@ -0,0 +1,334 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamDirectory.
|
||||
*/
|
||||
class vfsStreamDirectoryTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* instance to test
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $dir;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->dir = new vfsStreamDirectory('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* assure that a directory seperator inside the name throws an exception
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function invalidCharacterInName()
|
||||
{
|
||||
$this->expectException(vfsStreamException::class);
|
||||
$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
|
||||
*/
|
||||
public function renameToInvalidNameThrowsvfsStreamException()
|
||||
{
|
||||
$this->expectException(vfsStreamException::class);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for LOCK_EX behaviour related to file_put_contents().
|
||||
*
|
||||
* @group lock_fpc
|
||||
* @author https://github.com/iwyg
|
||||
*/
|
||||
class vfsStreamExLockTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$root = vfsStream::setup();
|
||||
vfsStream::newFile('testfile')->at($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')));
|
||||
}
|
||||
}
|
||||
+337
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamFile.
|
||||
*/
|
||||
class vfsStreamFileTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* instance to test
|
||||
*
|
||||
* @var vfsStreamFile
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->file = 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->assertEquals('', $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
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public function withContentThrowsInvalidArgumentExceptionWhenContentIsNoStringAndNoFileContent()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->file->withContent(313);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStream.
|
||||
*
|
||||
* @since 0.9.0
|
||||
* @group issue_2
|
||||
*/
|
||||
class vfsStreamGlobTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function globDoesNotWorkWithVfsStreamUrls()
|
||||
{
|
||||
$root = vfsStream::setup('example');
|
||||
mkdir(vfsStream::url('example/test/'), 0777, true);
|
||||
$this->assertEmpty(glob(vfsStream::url('example'), GLOB_MARK));
|
||||
}
|
||||
}
|
||||
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStream.
|
||||
*
|
||||
* @since 0.9.0
|
||||
* @group issue_5
|
||||
*/
|
||||
class vfsStreamResolveIncludePathTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* include path to restore after test run
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $backupIncludePath;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->backupIncludePath = 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(): void
|
||||
{
|
||||
set_include_path($this->backupIncludePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function knownFileCanBeResolved()
|
||||
{
|
||||
file_put_contents('vfs://root/a/path/knownFile.php', '<?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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,780 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
|
||||
use org\bovigo\vfs\content\LargeFileContent;
|
||||
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStream.
|
||||
*/
|
||||
class vfsStreamTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
vfsStreamWrapper::register();
|
||||
}
|
||||
|
||||
/**
|
||||
* assure that path2url conversion works correct
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
$this->assertEquals('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
|
||||
* @since 0.11.0
|
||||
*/
|
||||
public function createThrowsExceptionIfNoBaseDirGivenAndNoRootSet()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
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
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public function inspectWithoutContentAndWithoutRootThrowsInvalidArgumentException()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$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
|
||||
* @since 0.11.0
|
||||
*/
|
||||
public function copyFromFileSystemThrowsExceptionIfNoBaseDirGivenAndNoRootSet()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
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'));
|
||||
}
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for umask settings.
|
||||
*
|
||||
* @group permissions
|
||||
* @group umask
|
||||
* @since 0.8.0
|
||||
*/
|
||||
class vfsStreamUmaskTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
vfsStream::umask(0000);
|
||||
}
|
||||
|
||||
/**
|
||||
* clean up test environment
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
vfsStream::umask(0000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function gettingUmaskSettingDoesNotChangeUmaskSetting()
|
||||
{
|
||||
$this->assertEquals(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'), 0000);
|
||||
$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());
|
||||
}
|
||||
}
|
||||
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Helper class for the test.
|
||||
*/
|
||||
class TestvfsStreamWrapper extends vfsStreamWrapper
|
||||
{
|
||||
/**
|
||||
* unregisters vfsStreamWrapper
|
||||
*/
|
||||
public static function unregister()
|
||||
{
|
||||
if (in_array(vfsStream::SCHEME, stream_get_wrappers()) === true) {
|
||||
stream_wrapper_unregister(vfsStream::SCHEME);
|
||||
}
|
||||
|
||||
self::$registered = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*/
|
||||
class vfsStreamWrapperAlreadyRegisteredTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
TestvfsStreamWrapper::unregister();
|
||||
$mock = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamWrapper');
|
||||
stream_wrapper_register(vfsStream::SCHEME, get_class($mock));
|
||||
}
|
||||
|
||||
/**
|
||||
* clean up test environment
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
TestvfsStreamWrapper::unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
* registering the stream wrapper when another stream wrapper is already
|
||||
* registered for the vfs scheme should throw an exception
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function registerOverAnotherStreamWrapper()
|
||||
{
|
||||
$this->expectException(vfsStreamException::class);
|
||||
vfsStreamWrapper::register();
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*/
|
||||
abstract class vfsStreamWrapperBaseTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* root directory
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $foo;
|
||||
/**
|
||||
* URL of root directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fooURL;
|
||||
/**
|
||||
* sub directory
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $bar;
|
||||
/**
|
||||
* URL of sub directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $barURL;
|
||||
/**
|
||||
* a file
|
||||
*
|
||||
* @var vfsStreamFile
|
||||
*/
|
||||
protected $baz1;
|
||||
/**
|
||||
* URL of file 1
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $baz1URL;
|
||||
/**
|
||||
* another file
|
||||
*
|
||||
* @var vfsStreamFile
|
||||
*/
|
||||
protected $baz2;
|
||||
/**
|
||||
* URL of file 2
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $baz2URL;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->fooURL = 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);
|
||||
}
|
||||
}
|
||||
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test that using windows directory separator works correct.
|
||||
*
|
||||
* @since 0.9.0
|
||||
* @group issue_8
|
||||
*/
|
||||
class vfsStreamWrapperDirSeparatorTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* root diretory
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $root;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->root = 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\\'));
|
||||
}
|
||||
}
|
||||
+503
@@ -0,0 +1,503 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
use PHPUnit\Framework\Error;
|
||||
|
||||
require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php';
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper around mkdir().
|
||||
*
|
||||
* @package bovigo_vfs
|
||||
* @subpackage test
|
||||
*/
|
||||
class vfsStreamWrapperMkDirTestCase extends vfsStreamWrapperBaseTestCase
|
||||
{
|
||||
/**
|
||||
* mkdir() should not overwrite existing root
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function mkdirNoNewRoot()
|
||||
{
|
||||
$this->assertFalse(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
|
||||
*/
|
||||
public function mkDirShouldNotOverwriteExistingDirectoriesAndTriggerE_USER_WARNING()
|
||||
{
|
||||
$this->expectException(Error\Warning::class);
|
||||
$this->expectExceptionMessage('mkdir(): Path vfs://root/dir exists');
|
||||
|
||||
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
|
||||
*/
|
||||
public function mkDirShouldNotOverwriteExistingFilesAndTriggerE_USER_WARNING()
|
||||
{
|
||||
$this->expectException(Error\Warning::class);
|
||||
$this->expectExceptionMessage('mkdir(): Path vfs://root/test.txt exists');
|
||||
$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'));
|
||||
}
|
||||
}
|
||||
+457
@@ -0,0 +1,457 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php';
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*/
|
||||
class vfsStreamWrapperFileTestCase extends vfsStreamWrapperBaseTestCase
|
||||
{
|
||||
/**
|
||||
* assert that file_get_contents() delivers correct file contents
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function file_get_contents()
|
||||
{
|
||||
$this->assertEquals('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));
|
||||
}
|
||||
}
|
||||
Vendored
+314
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*
|
||||
* @since 0.9.0
|
||||
*/
|
||||
class vfsStreamWrapperFileTimesTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* URL of foo.txt file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fooUrl;
|
||||
/**
|
||||
* URL of bar directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $barUrl;
|
||||
/**
|
||||
* URL of baz.txt file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bazUrl;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
vfsStream::setup()
|
||||
->lastModified(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.');
|
||||
}
|
||||
}
|
||||
+439
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for flock() implementation.
|
||||
*
|
||||
* @package bovigo_vfs
|
||||
* @subpackage test
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/6
|
||||
* @group issue_6
|
||||
*/
|
||||
class vfsStreamWrapperFlockTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* root directory
|
||||
*
|
||||
* @var vfsStreamContainer
|
||||
*/
|
||||
protected $root;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->root = 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);
|
||||
}
|
||||
}
|
||||
Vendored
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
use org\bovigo\vfs\content\LargeFileContent;
|
||||
/**
|
||||
* Test for large file mocks.
|
||||
*
|
||||
* @package bovigo_vfs
|
||||
* @subpackage test
|
||||
* @since 1.3.0
|
||||
* @group issue_79
|
||||
*/
|
||||
class vfsStreamWrapperLargeFileTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* large file to test
|
||||
*
|
||||
* @var vfsStreamFile
|
||||
*/
|
||||
private $largeFile;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$root = vfsStream::setup();
|
||||
$this->largeFile = 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for quota related functionality of org\bovigo\vfs\vfsStreamWrapper.
|
||||
*
|
||||
* @group issue_35
|
||||
*/
|
||||
class vfsStreamWrapperQuotaTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* access to root
|
||||
*
|
||||
* @type vfsStreamDirectory
|
||||
*/
|
||||
private $root;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->root = 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()
|
||||
);
|
||||
}
|
||||
}
|
||||
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for stream_set_option() implementation.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/15
|
||||
* @group issue_15
|
||||
*/
|
||||
class vfsStreamWrapperSetOptionTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* root directory
|
||||
*
|
||||
* @var vfsStreamContainer
|
||||
*/
|
||||
protected $root;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->root = 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);
|
||||
}
|
||||
}
|
||||
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*
|
||||
* @since 0.9.0
|
||||
* @group issue_3
|
||||
*/
|
||||
class vfsStreamWrapperSelectStreamTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function selectStream()
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80000)
|
||||
{
|
||||
$this->bc_expectException('\ValueError');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->bc_expectException('\PHPUnit_Framework_Error');
|
||||
}
|
||||
|
||||
$root = vfsStream::setup();
|
||||
$file = vfsStream::newFile('foo.txt')->at($root)->withContent('testContent');
|
||||
|
||||
$fp = fopen(vfsStream::url('root/foo.txt'), 'rb');
|
||||
$readarray = array($fp);
|
||||
$writearray = array();
|
||||
$exceptarray = array();
|
||||
stream_select($readarray, $writearray, $exceptarray, 1);
|
||||
}
|
||||
}
|
||||
+791
@@ -0,0 +1,791 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
use PHPUnit\Framework\Error;
|
||||
|
||||
require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php';
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*/
|
||||
class vfsStreamWrapperTestCase extends vfsStreamWrapperBaseTestCase
|
||||
{
|
||||
/**
|
||||
* ensure that a call to vfsStreamWrapper::register() resets the stream
|
||||
*
|
||||
* Implemented after a request by David Zülke.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function resetByRegister()
|
||||
{
|
||||
$this->assertSame($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->assertFileDoesNotExist($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->assertFileDoesNotExist($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->assertFileDoesNotExist($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->assertFileDoesNotExist($this->barURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function renameFileIntoFile()
|
||||
{
|
||||
$this->expectException(Error\Warning::class);
|
||||
// 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->assertFileDoesNotExist($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->assertFileDoesNotExist($this->baz1URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* assert that trying to rename from a non existing file trigger a warning
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function renameOnSourceFileNotFound()
|
||||
{
|
||||
$this->expectException(Error\Warning::class);
|
||||
rename(vfsStream::url('notfound'), $this->baz1URL);
|
||||
}
|
||||
/**
|
||||
* assert that trying to rename to a directory that is not found trigger a warning
|
||||
|
||||
* @test
|
||||
*/
|
||||
public function renameOnDestinationDirectoryFileNotFound()
|
||||
{
|
||||
$this->expectException(Error\Warning::class);
|
||||
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
|
||||
*/
|
||||
public function openFileWithoutDirectory()
|
||||
{
|
||||
$this->expectException(Error\Warning::class);
|
||||
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));
|
||||
}
|
||||
}
|
||||
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*/
|
||||
class vfsStreamWrapperUnregisterTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Unregistering a registered URL wrapper.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function unregisterRegisteredUrlWrapper()
|
||||
{
|
||||
vfsStreamWrapper::register();
|
||||
vfsStreamWrapper::unregister();
|
||||
$this->assertNotContains(vfsStream::SCHEME, stream_get_wrappers());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregistering a third party wrapper for vfs:// fails.
|
||||
*
|
||||
* @test
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function unregisterThirdPartyVfsScheme()
|
||||
{
|
||||
$this->expectException(vfsStreamException::class);
|
||||
// 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
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function unregisterWhenNotInRegisteredState()
|
||||
{
|
||||
$this->expectException(vfsStreamException::class);
|
||||
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();
|
||||
}
|
||||
}
|
||||
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper.
|
||||
*/
|
||||
class vfsStreamWrapperWithoutRootTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
vfsStreamWrapper::register();
|
||||
}
|
||||
|
||||
/**
|
||||
* no root > 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')));
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\vfsStreamWrapper in conjunction with ext/zip.
|
||||
*
|
||||
* @group zip
|
||||
*/
|
||||
class vfsStreamZipTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
if (extension_loaded('zip') === false) {
|
||||
$this->markTestSkipped('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')));
|
||||
}
|
||||
}
|
||||
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\visitor;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use org\bovigo\vfs\vfsStreamFile;
|
||||
use org\bovigo\vfs\vfsStreamBlock;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\visitor\vfsStreamAbstractVisitor.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/10
|
||||
* @group issue_10
|
||||
*/
|
||||
class vfsStreamAbstractVisitorTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* instance to test
|
||||
*
|
||||
* @var vfsStreamAbstractVisitor
|
||||
*/
|
||||
protected $abstractVisitor;
|
||||
|
||||
/**
|
||||
* set up test environment
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->abstractVisitor = $this->bc_getMock('org\\bovigo\\vfs\\visitor\\vfsStreamAbstractVisitor',
|
||||
array('visitFile', 'visitDirectory')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function visitThrowsInvalidArgumentExceptionOnUnknownContentType()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$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)
|
||||
);
|
||||
}
|
||||
}
|
||||
Vendored
+102
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\visitor;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use org\bovigo\vfs\vfsStreamFile;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\visitor\vfsStreamPrintVisitor.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/10
|
||||
* @group issue_10
|
||||
*/
|
||||
class vfsStreamPrintVisitorTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructWithNonResourceThrowsInvalidArgumentException()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
new vfsStreamPrintVisitor('invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructWithNonStreamResourceThrowsInvalidArgumentException()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
new vfsStreamPrintVisitor(xml_parser_create());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function visitFileWritesFileNameToStream()
|
||||
{
|
||||
$output = vfsStream::newFile('foo.txt')
|
||||
->at(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'));
|
||||
}
|
||||
}
|
||||
Vendored
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of vfsStream.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package org\bovigo\vfs
|
||||
*/
|
||||
namespace org\bovigo\vfs\visitor;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
/**
|
||||
* Test for org\bovigo\vfs\visitor\vfsStreamStructureVisitor.
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @see https://github.com/mikey179/vfsStream/issues/10
|
||||
* @group issue_10
|
||||
*/
|
||||
class vfsStreamStructureVisitorTestCase extends \BC_PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function visitFileCreatesStructureForFile()
|
||||
{
|
||||
$structureVisitor = new vfsStreamStructureVisitor();
|
||||
$this->assertEquals(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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
--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--
|
||||
<?php
|
||||
class Stream {
|
||||
/**
|
||||
* The current context or null if none passed.
|
||||
*
|
||||
* @var resource|null
|
||||
*/
|
||||
public $context;
|
||||
public function stream_open($path, $mode, $options, $opened_path) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function stream_write($data) {
|
||||
return (int) (strlen($data) - 2);
|
||||
}
|
||||
}
|
||||
|
||||
stream_wrapper_register('test', 'Stream');
|
||||
file_put_contents('test://file.txt', 'foobarbaz');
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: file_put_contents(): Only 7 of 9 bytes written, possibly out of free disk space in %s on line %d
|
||||
+1
@@ -0,0 +1 @@
|
||||
foo
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
foobar
|
||||
Reference in New Issue
Block a user