Issue #2493913 by iMiksu: Update mikey179/vfsstream to the latest stable release

8.0.x
webchick 2015-05-24 20:32:28 -07:00
parent e6ea417035
commit 4ec324ef9c
62 changed files with 153 additions and 8551 deletions

40
core/composer.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "ba1a97bf2c0bcef4fb771231a4c1fbdb", "hash": "ba1a97bf2c0bcef4fb771231a4c1fbdb",
@ -1007,28 +1007,28 @@
}, },
{ {
"name": "mikey179/vfsStream", "name": "mikey179/vfsStream",
"version": "v1.4.0", "version": "v1.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/mikey179/vfsStream.git", "url": "https://github.com/mikey179/vfsStream.git",
"reference": "61b12172292cf539685507aa65b076c1530e83c1" "reference": "4dc0d2f622412f561f5b242b19b98068bbbc883a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/61b12172292cf539685507aa65b076c1530e83c1", "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/4dc0d2f622412f561f5b242b19b98068bbbc883a",
"reference": "61b12172292cf539685507aa65b076c1530e83c1", "reference": "4dc0d2f622412f561f5b242b19b98068bbbc883a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.3.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.2" "phpunit/phpunit": "~4.5"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.4.x-dev" "dev-master": "1.5.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -1038,10 +1038,18 @@
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
"license": [ "license": [
"BSD" "BSD-3-Clause"
], ],
"authors": [
{
"name": "Frank Kleine",
"homepage": "http://frankkleine.de/",
"role": "Developer"
}
],
"description": "Virtual file system to mock the real file system in unit tests.",
"homepage": "http://vfs.bovigo.org/", "homepage": "http://vfs.bovigo.org/",
"time": "2014-09-14 10:18:53" "time": "2015-03-29 11:19:49"
}, },
{ {
"name": "phpdocumentor/reflection-docblock", "name": "phpdocumentor/reflection-docblock",
@ -2900,7 +2908,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/Validator/zipball/6bb1b474d25cb80617d8da6cb14c955ba914e495", "url": "https://api.github.com/repos/symfony/Validator/zipball/d667b6a563e233b24ae1599a9fde7a53ddd1c055",
"reference": "6bb1b474d25cb80617d8da6cb14c955ba914e495", "reference": "6bb1b474d25cb80617d8da6cb14c955ba914e495",
"shasum": "" "shasum": ""
}, },
@ -3073,12 +3081,12 @@
"version": "2.4.0", "version": "2.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/Component_ZendEscaper.git", "url": "https://github.com/zendframework/zend-escaper.git",
"reference": "65b3328627362b0be1d5e9067bc846511d1fbc96" "reference": "65b3328627362b0be1d5e9067bc846511d1fbc96"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/Component_ZendEscaper/zipball/65b3328627362b0be1d5e9067bc846511d1fbc96", "url": "https://api.github.com/repos/zendframework/zend-escaper/zipball/15e5769e4fcdb4bf07ebd76500810e7070e23a97",
"reference": "65b3328627362b0be1d5e9067bc846511d1fbc96", "reference": "65b3328627362b0be1d5e9067bc846511d1fbc96",
"shasum": "" "shasum": ""
}, },
@ -3113,12 +3121,12 @@
"version": "2.4.0", "version": "2.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/Component_ZendFeed.git", "url": "https://github.com/zendframework/zend-feed.git",
"reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5" "reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/Component_ZendFeed/zipball/aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5", "url": "https://api.github.com/repos/zendframework/zend-feed/zipball/0f59e560364f1f1fcb09a96874328ae3ff690db2",
"reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5", "reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5",
"shasum": "" "shasum": ""
}, },
@ -3170,12 +3178,12 @@
"version": "2.4.0", "version": "2.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/Component_ZendStdlib.git", "url": "https://github.com/zendframework/zend-stdlib.git",
"reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030" "reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/Component_ZendStdlib/zipball/eab586f4c18af3fa63c977611939f1f4a3cf1030", "url": "https://api.github.com/repos/zendframework/zend-stdlib/zipball/cf05c5ba75606e47ffee91cedc72778da46f74c3",
"reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030", "reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030",
"shasum": "" "shasum": ""
}, },

View File

@ -381,46 +381,6 @@
"stream" "stream"
] ]
}, },
{
"name": "mikey179/vfsStream",
"version": "v1.4.0",
"version_normalized": "1.4.0.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "61b12172292cf539685507aa65b076c1530e83c1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/61b12172292cf539685507aa65b076c1530e83c1",
"reference": "61b12172292cf539685507aa65b076c1530e83c1",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"time": "2014-09-14 10:18:53",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"homepage": "http://vfs.bovigo.org/"
},
{ {
"name": "phpunit/php-text-template", "name": "phpunit/php-text-template",
"version": "1.2.0", "version": "1.2.0",
@ -2304,12 +2264,12 @@
"version_normalized": "2.4.0.0", "version_normalized": "2.4.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/Component_ZendStdlib.git", "url": "https://github.com/zendframework/zend-stdlib.git",
"reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030" "reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/Component_ZendStdlib/zipball/eab586f4c18af3fa63c977611939f1f4a3cf1030", "url": "https://api.github.com/repos/zendframework/zend-stdlib/zipball/cf05c5ba75606e47ffee91cedc72778da46f74c3",
"reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030", "reference": "eab586f4c18af3fa63c977611939f1f4a3cf1030",
"shasum": "" "shasum": ""
}, },
@ -2358,12 +2318,12 @@
"version_normalized": "2.4.0.0", "version_normalized": "2.4.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/Component_ZendEscaper.git", "url": "https://github.com/zendframework/zend-escaper.git",
"reference": "65b3328627362b0be1d5e9067bc846511d1fbc96" "reference": "65b3328627362b0be1d5e9067bc846511d1fbc96"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/Component_ZendEscaper/zipball/65b3328627362b0be1d5e9067bc846511d1fbc96", "url": "https://api.github.com/repos/zendframework/zend-escaper/zipball/15e5769e4fcdb4bf07ebd76500810e7070e23a97",
"reference": "65b3328627362b0be1d5e9067bc846511d1fbc96", "reference": "65b3328627362b0be1d5e9067bc846511d1fbc96",
"shasum": "" "shasum": ""
}, },
@ -2400,12 +2360,12 @@
"version_normalized": "2.4.0.0", "version_normalized": "2.4.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/Component_ZendFeed.git", "url": "https://github.com/zendframework/zend-feed.git",
"reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5" "reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/Component_ZendFeed/zipball/aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5", "url": "https://api.github.com/repos/zendframework/zend-feed/zipball/0f59e560364f1f1fcb09a96874328ae3ff690db2",
"reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5", "reference": "aca2b42ecf06d94c621e3c3be8e95d61d3a79bf5",
"shasum": "" "shasum": ""
}, },
@ -3264,7 +3224,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/Validator/zipball/6bb1b474d25cb80617d8da6cb14c955ba914e495", "url": "https://api.github.com/repos/symfony/Validator/zipball/d667b6a563e233b24ae1599a9fde7a53ddd1c055",
"reference": "6bb1b474d25cb80617d8da6cb14c955ba914e495", "reference": "6bb1b474d25cb80617d8da6cb14c955ba914e495",
"shasum": "" "shasum": ""
}, },
@ -3325,5 +3285,53 @@
], ],
"description": "Symfony Validator Component", "description": "Symfony Validator Component",
"homepage": "https://symfony.com" "homepage": "https://symfony.com"
},
{
"name": "mikey179/vfsStream",
"version": "v1.5.0",
"version_normalized": "1.5.0.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "4dc0d2f622412f561f5b242b19b98068bbbc883a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/4dc0d2f622412f561f5b242b19b98068bbbc883a",
"reference": "4dc0d2f622412f561f5b242b19b98068bbbc883a",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.5"
},
"time": "2015-03-29 11:19:49",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Frank Kleine",
"homepage": "http://frankkleine.de/",
"role": "Developer"
}
],
"description": "Virtual file system to mock the real file system in unit tests.",
"homepage": "http://vfs.bovigo.org/"
} }
] ]

View File

@ -1,3 +0,0 @@
src_dir: src/main/php
coverage_clover: docs/phpunit/clover.xml
json_path: docs/phpunit/coveralls-upload.json

View File

@ -1,4 +0,0 @@
/composer.lock
/docs
/nbproject
/vendor

View File

@ -1,24 +0,0 @@
language: php
php:
- hhvm
- hhvm-nightly
- 5.6
- 5.3
- 5.4
- 5.5
matrix:
allow_failures:
- php: hhvm
- php: hhvm-nightly
install:
- composer install
- composer require satooshi/php-coveralls:dev-master
script:
- vendor/bin/phpunit --coverage-text
after_script:
- vendor/bin/coveralls

View File

@ -1,3 +1,13 @@
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) 1.4.0 (2014-09-14)
------------------ ------------------

View File

@ -1,4 +1,4 @@
Copyright (c) 2007-2014, Frank Kleine Copyright (c) 2007-2015, Frank Kleine
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -2,19 +2,32 @@
"name": "mikey179/vfsStream", "name": "mikey179/vfsStream",
"type": "library", "type": "library",
"homepage": "http://vfs.bovigo.org/", "homepage": "http://vfs.bovigo.org/",
"license": "BSD", "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/mikey179/vfsStream/issues",
"source": "https://github.com/mikey179/vfsStream/tree/master",
"wiki": "https://github.com/mikey179/vfsStream/wiki"
},
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.3.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.2" "phpunit/phpunit": "~4.5"
}, },
"autoload": { "autoload": {
"psr-0": { "org\\bovigo\\vfs\\": "src/main/php" } "psr-0": { "org\\bovigo\\vfs\\": "src/main/php" }
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.4.x-dev" "dev-master": "1.5.x-dev"
} }
} }
} }

View File

@ -1,54 +0,0 @@
<?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\example;
/**
* Example class.
*/
class Example
{
/**
* id of the example
*
* @type string
*/
protected $id;
/**
* a directory where we do something..
*
* @type string
*/
protected $directory;
/**
* constructor
*
* @param string $id
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* sets the directory
*
* @param string $directory
*/
public function setDirectory($directory)
{
$this->directory = $directory . DIRECTORY_SEPARATOR . $this->id;
if (file_exists($this->directory) === false) {
mkdir($this->directory, 0700, true);
}
}
// more source code here...
}
?>

View File

@ -1,48 +0,0 @@
<?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\example;
require_once 'Example.php';
/**
* Test case for class Example.
*/
class ExampleTestCaseOldWay extends \PHPUnit_Framework_TestCase
{
/**
* set up test environmemt
*/
public function setUp()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* clear up test environment
*/
public function tearDown()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* @test
*/
public function directoryIsCreated()
{
$example = new Example('id');
$this->assertFalse(file_exists(__DIR__ . '/id'));
$example->setDirectory(__DIR__);
$this->assertTrue(file_exists(__DIR__ . '/id'));
}
}
?>

View File

@ -1,47 +0,0 @@
<?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\example;
use org\bovigo\vfs\vfsStream;
require_once 'Example.php';
/**
* Test case for class Example.
*
* @package bovigo_vfs
* @subpackage examples
*/
class ExampleTestCaseWithVfsStream extends \PHPUnit_Framework_TestCase
{
/**
* root directory
*
* @type vfsStreamDirectory
*/
protected $root;
/**
* set up test environmemt
*/
public function setUp()
{
$this->root = vfsStream::setup('exampleDir');
}
/**
* @test
*/
public function directoryIsCreated()
{
$example = new Example('id');
$this->assertFalse($this->root->hasChild('id'));
$example->setDirectory(vfsStream::url('exampleDir'));
$this->assertTrue($this->root->hasChild('id'));
}
}
?>

View File

@ -1,50 +0,0 @@
<?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\example;
/**
* Example class to demonstrate testing of failure behaviour with vfsStream.
*/
class FailureExample
{
/**
* filename to write data
*
* @type string
*/
protected $filename;
/**
* constructor
*
* @param string $id
*/
public function __construct($filename)
{
$this->filename = $filename;
}
/**
* sets the directory
*
* @param string $directory
*/
public function writeData($data)
{
$bytes = @file_put_contents($this->filename, $data);
if (false === $bytes) {
return 'could not write data';
}
return 'ok';
}
// more source code here...
}
?>

View File

@ -1,58 +0,0 @@
<?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\example;
use org\bovigo\vfs\vfsStream;
require_once 'FailureExample.php';
/**
* Test case for class FailureExample.
*/
class FailureExampleTestCase extends \PHPUnit_Framework_TestCase
{
/**
* root directory
*
* @type vfsStreamDirectory
*/
protected $root;
/**
* set up test environmemt
*/
public function setUp()
{
$this->root = vfsStream::setup('exampleDir');
}
/**
* @test
*/
public function returnsOkOnNoFailure()
{
$example = new FailureExample(vfsStream::url('exampleDir/test.txt'));
$this->assertSame('ok', $example->writeData('testdata'));
$this->assertTrue($this->root->hasChild('test.txt'));
$this->assertSame('testdata', $this->root->getChild('test.txt')->getContent());
}
/**
* @test
*/
public function returnsErrorMessageIfWritingToFileFails()
{
$file = vfsStream::newFile('test.txt', 0000)
->withContent('notoverwritten')
->at($this->root);
$example = new FailureExample(vfsStream::url('exampleDir/test.txt'));
$this->assertSame('could not write data', $example->writeData('testdata'));
$this->assertTrue($this->root->hasChild('test.txt'));
$this->assertSame('notoverwritten', $this->root->getChild('test.txt')->getContent());
}
}
?>

View File

@ -1,67 +0,0 @@
<?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\example;
require_once 'FilemodeExample.php';
/**
* Test case for class FilemodeExample.
*/
class FilemodeExampleTestCaseOldWay extends \PHPUnit_Framework_TestCase
{
/**
* set up test environmemt
*/
public function setUp()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* clear up test environment
*/
public function tearDown()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* test correct file mode for created directory
*/
public function testDirectoryHasCorrectDefaultFilePermissions()
{
$example = new FilemodeExample('id');
$example->setDirectory(__DIR__);
if (DIRECTORY_SEPARATOR === '\\') {
// can not really test on windows, filemode from mkdir() is ignored
$this->assertEquals(40777, decoct(fileperms(__DIR__ . '/id')));
} else {
$this->assertEquals(40700, decoct(fileperms(__DIR__ . '/id')));
}
}
/**
* test correct file mode for created directory
*/
public function testDirectoryHasCorrectDifferentFilePermissions()
{
$example = new FilemodeExample('id', 0755);
$example->setDirectory(__DIR__);
if (DIRECTORY_SEPARATOR === '\\') {
// can not really test on windows, filemode from mkdir() is ignored
$this->assertEquals(40777, decoct(fileperms(__DIR__ . '/id')));
} else {
$this->assertEquals(40755, decoct(fileperms(__DIR__ . '/id')));
}
}
}
?>

View File

@ -1,29 +0,0 @@
<?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\example;
/**
* Example showing correct file permission support introduced with 0.7.0.
*/
class FilePermissionsExample
{
/**
* reads configuration from given config file
*
* @param mixed $config
* @param string $configFile
*/
public function writeConfig($config, $configFile)
{
@file_put_contents($configFile, serialize($config));
}
// more methods here
}
?>

View File

@ -1,44 +0,0 @@
<?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\example;
use org\bovigo\vfs\vfsStream;
require_once 'FilePermissionsExample.php';
/**
* Test for FilePermissionsExample.
*/
class FilePermissionsExampleTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function directoryWritable()
{
vfsStream::setup('exampleDir');
$example = new FilePermissionsExample();
$example->writeConfig(array('foo' => 'bar'),
vfsStream::url('exampleDir/writable.ini')
);
// assertions here
}
/**
* @test
*/
public function directoryNotWritable()
{
vfsStream::setup('exampleDir', 0444);
$example = new FilePermissionsExample();
$example->writeConfig(array('foo' => 'bar'),
vfsStream::url('exampleDir/notWritable.ini')
);
}
}
?>

View File

@ -1,62 +0,0 @@
<?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\example;
/**
* Example class.
*/
class FilemodeExample
{
/**
* id of the example
*
* @type string
*/
protected $id;
/**
* a directory where we do something..
*
* @type string
*/
protected $directory;
/**
* file mode for newly created directories
*
* @type int
*/
protected $fileMode;
/**
* constructor
*
* @param string $id
* @param int $fileMode optional
*/
public function __construct($id, $fileMode = 0700)
{
$this->id = $id;
$this->fileMode = $fileMode;
}
/**
* sets the directory
*
* @param string $directory
*/
public function setDirectory($directory)
{
$this->directory = $directory . DIRECTORY_SEPARATOR . $this->id;
if (file_exists($this->directory) === false) {
mkdir($this->directory, $this->fileMode, true);
}
}
// more source code here...
}
?>

View File

@ -1,53 +0,0 @@
<?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\example;
use org\bovigo\vfs\vfsStream;
require_once 'FilemodeExample.php';
/**
* Test case for class FilemodeExample.
*/
class FilemodeExampleTestCaseWithVfsStream extends \PHPUnit_Framework_TestCase
{
/**
* root directory
*
* @type vfsStreamDirectory
*/
protected $root;
/**
* set up test environmemt
*/
public function setUp()
{
$this->root = vfsStream::setup('exampleDir');
}
/**
* test that the directory is created
*/
public function testDirectoryIsCreatedWithDefaultPermissions()
{
$example = new FilemodeExample('id');
$example->setDirectory(vfsStream::url('exampleDir'));
$this->assertEquals(0700, $this->root->getChild('id')->getPermissions());
}
/**
* test that the directory is created
*/
public function testDirectoryIsCreatedWithGivenPermissions()
{
$example = new FilemodeExample('id', 0755);
$example->setDirectory(vfsStream::url('exampleDir'));
$this->assertEquals(0755, $this->root->getChild('id')->getPermissions());
}
}
?>

View File

@ -1,3 +0,0 @@
<?php
require __DIR__ . '/../vendor/.composer/autoload.php';
?>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdoc>
<title>vfsStream API Doc</title>
<parser>
<target>docs/api</target>
<default-package-name>org\bovigo\vfs</default-package-name>
</parser>
<transformer>
<target>docs/api</target>
</transformer>
<files>
<directory>src/main/php</directory>
</files>
</phpdoc>

View File

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="true">
<testsuites>
<testsuite>
<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"/>
</php>
</phpunit>

View File

@ -8,6 +8,7 @@
* @package org\bovigo\vfs * @package org\bovigo\vfs
*/ */
namespace org\bovigo\vfs; namespace org\bovigo\vfs;
use org\bovigo\vfs\content\LargeFileContent;
use org\bovigo\vfs\visitor\vfsStreamVisitor; use org\bovigo\vfs\visitor\vfsStreamVisitor;
/** /**
* Some utility methods for vfsStream. * Some utility methods for vfsStream.
@ -82,7 +83,7 @@ class vfsStream
$path = str_replace('\\', '/', $path); $path = str_replace('\\', '/', $path);
// replace double slashes with single slashes // replace double slashes with single slashes
$path = str_replace('//', '/', $path); $path = str_replace('//', '/', $path);
return $path; return urldecode($path);
} }
/** /**
@ -245,7 +246,9 @@ class vfsStream
* names. * names.
* File permissions are copied as well. * File permissions are copied as well.
* Please note that file contents will only be copied if their file size * Please note that file contents will only be copied if their file size
* does not exceed the given $maxFileSize which is 1024 KB. * 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 string $path path to copy the structure from
* @param vfsStreamDirectory $baseDir directory to add the structure to * @param vfsStreamDirectory $baseDir directory to add the structure to
@ -267,26 +270,42 @@ class vfsStream
$dir = new \DirectoryIterator($path); $dir = new \DirectoryIterator($path);
foreach ($dir as $fileinfo) { foreach ($dir as $fileinfo) {
if ($fileinfo->isFile() === true) { switch (filetype($fileinfo->getPathname())) {
if ($fileinfo->getSize() <= $maxFileSize) { case 'file':
$content = file_get_contents($fileinfo->getPathname()); if ($fileinfo->getSize() <= $maxFileSize) {
} else { $content = file_get_contents($fileinfo->getPathname());
$content = ''; } else {
} $content = new LargeFileContent($fileinfo->getSize());
}
self::newFile($fileinfo->getFilename(), self::newFile(
octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)) $fileinfo->getFilename(),
) octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4))
->withContent($content) )
->at($baseDir); ->withContent($content)
} elseif ($fileinfo->isDir() === true && $fileinfo->isDot() === false) { ->at($baseDir);
self::copyFromFileSystem($fileinfo->getPathname(), break;
self::newDirectory($fileinfo->getFilename(),
octdec(substr(sprintf('%o', $fileinfo->getPerms()), -4)) case 'dir':
) if (!$fileinfo->isDot()) {
->at($baseDir), self::copyFromFileSystem(
$maxFileSize $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;
} }
} }
@ -441,4 +460,3 @@ class vfsStream
self::$dotFiles = true; self::$dotFiles = true;
} }
} }
?>

View File

@ -124,6 +124,7 @@ class vfsStreamWrapper
public static function setRoot(vfsStreamContainer $root) public static function setRoot(vfsStreamContainer $root)
{ {
self::$root = $root; self::$root = $root;
clearstatcache();
return self::$root; return self::$root;
} }
@ -481,7 +482,11 @@ class vfsStreamWrapper
switch ($option) { switch ($option) {
case STREAM_META_TOUCH: case STREAM_META_TOUCH:
if (null === $content) { if (null === $content) {
$content = $this->createFile($path); $content = $this->createFile($path, null, STREAM_REPORT_ERRORS);
// file creation may not be allowed at provided path
if (false === $content) {
return false;
}
} }
$currentTime = time(); $currentTime = time();

View File

@ -1,318 +0,0 @@
<?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()
{
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
);
}
}

View File

@ -1,92 +0,0 @@
<?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 permissions related functionality.
*
* @group permissions
*/
class PermissionsTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @type vfsStreamDirectory
*/
private $root;
/**
* set up test environment
*/
public function setup()
{
$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));
}
}
?>

View File

@ -1,81 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* instance to test
*
* @type Quota
*/
private $quota;
/**
* set up test environment
*/
public function setUp()
{
$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));
}
}
?>

View File

@ -1,58 +0,0 @@
<?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 \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());
}
}
}

View File

@ -1,225 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* instance to test
*
* @type LargeFileContent
*/
private $largeFileContent;
/**
* set up test environment
*/
public function setUp()
{
$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()
);
}
}

View File

@ -1,230 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* instance to test
*
* @type StringBasedFileContent
*/
private $stringBasedFileContent;
/**
* set up test environment
*/
public function setUp()
{
$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()
{
$this->stringBasedFileContent->read(9);
$this->assertEquals('', $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());
}
}

View File

@ -1,326 +0,0 @@
<?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);
}
}
?>

View File

@ -1,89 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* The block device being tested.
*
* @var vfsStreamBlock $block
*/
protected $block;
public function setUp()
{
$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
* @expectedException org\bovigo\vfs\vfsStreamException
*/
public function createWithEmptyName()
{
$structure = array(
'topLevel' => array(
'thisIsAFile' => 'file contents',
'[]' => 'block contents'
)
);
$root = vfsStream::create($structure);
}
}

View File

@ -1,112 +0,0 @@
<?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 \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()
{
$this->dir = new vfsStreamDirectory('foo');
$this->mockChild1 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
$this->mockChild1->expects($this->any())
->method('getName')
->will($this->returnValue('bar'));
$this->dir->addChild($this->mockChild1);
$this->mockChild2 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
$this->mockChild2->expects($this->any())
->method('getName')
->will($this->returnValue('baz'));
$this->dir->addChild($this->mockChild2);
}
/**
* clean up test environment
*/
public function tearDown()
{
vfsStream::enableDotfiles();
}
/**
* @return array
*/
public function provideSwitchWithExpectations()
{
return array(array(function() { vfsStream::disableDotfiles(); },
array()
),
array(function() { vfsStream::enableDotfiles(); },
array('.', '..')
)
);
}
private function getDirName($dir)
{
if (is_string($dir)) {
return $dir;
}
return $dir->getName();
}
/**
* @param \Closure $dotFilesSwitch
* @param array $dirNames
* @test
* @dataProvider provideSwitchWithExpectations
*/
public function iteration(\Closure $dotFilesSwitch, array $dirs)
{
$dirs[] = $this->mockChild1;
$dirs[] = $this->mockChild2;
$dotFilesSwitch();
$dirIterator = $this->dir->getIterator();
foreach ($dirs as $dir) {
$this->assertEquals($this->getDirName($dir), $dirIterator->key());
$this->assertTrue($dirIterator->valid());
if (!is_string($dir)) {
$this->assertSame($dir, $dirIterator->current());
}
$dirIterator->next();
}
$this->assertFalse($dirIterator->valid());
$this->assertNull($dirIterator->key());
$this->assertNull($dirIterator->current());
}
}
?>

View File

@ -1,81 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* access to root directory
*
* @var vfsStreamDirectory
*/
protected $rootDirectory;
/**
* set up test environment
*/
public function setUp()
{
$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')
);
}
}
?>

View File

@ -1,335 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* instance to test
*
* @var vfsStreamDirectory
*/
protected $dir;
/**
* set up test environment
*/
public function setUp()
{
$this->dir = new vfsStreamDirectory('foo');
}
/**
* assure that a directory seperator inside the name throws an exception
*
* @test
* @expectedException org\bovigo\vfs\vfsStreamException
*/
public function invalidCharacterInName()
{
$dir = new vfsStreamDirectory('foo/bar');
}
/**
* test default values and methods
*
* @test
*/
public function defaultValues()
{
$this->assertEquals(vfsStreamContent::TYPE_DIR, $this->dir->getType());
$this->assertEquals('foo', $this->dir->getName());
$this->assertTrue($this->dir->appliesTo('foo'));
$this->assertTrue($this->dir->appliesTo('foo/bar'));
$this->assertFalse($this->dir->appliesTo('bar'));
$this->assertEquals(array(), $this->dir->getChildren());
}
/**
* test renaming the directory
*
* @test
*/
public function rename()
{
$this->dir->rename('bar');
$this->assertEquals('bar', $this->dir->getName());
$this->assertFalse($this->dir->appliesTo('foo'));
$this->assertFalse($this->dir->appliesTo('foo/bar'));
$this->assertTrue($this->dir->appliesTo('bar'));
}
/**
* renaming the directory to an invalid name throws a vfsStreamException
*
* @test
* @expectedException org\bovigo\vfs\vfsStreamException
*/
public function renameToInvalidNameThrowsvfsStreamException()
{
$this->dir->rename('foo/baz');
}
/**
* @test
* @since 0.10.0
*/
public function hasNoChildrenByDefault()
{
$this->assertFalse($this->dir->hasChildren());
}
/**
* @test
* @since 0.10.0
*/
public function hasChildrenReturnsTrueIfAtLeastOneChildPresent()
{
$mockChild = $this->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->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->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->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->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->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->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));
}
}
?>

View File

@ -1,56 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* set up test environment
*/
protected function setUp()
{
$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')));
}
}

View File

@ -1,306 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* instance to test
*
* @var vfsStreamFile
*/
protected $file;
/**
* set up test environment
*/
public function setUp()
{
$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->assertNull($this->file->getContent());
$this->assertSame($this->file, $this->file->setContent('bar'));
$this->assertEquals('bar', $this->file->getContent());
$this->assertSame($this->file, $this->file->withContent('baz'));
$this->assertEquals('baz', $this->file->getContent());
}
/**
* test renaming the directory
*
* @test
*/
public function rename()
{
$this->file->rename('bar');
$this->assertEquals('bar', $this->file->getName());
$this->assertFalse($this->file->appliesTo('foo'));
$this->assertFalse($this->file->appliesTo('foo/bar'));
$this->assertTrue($this->file->appliesTo('bar'));
}
/**
* test reading contents from the file
*
* @test
*/
public function readEmptyFile()
{
$this->assertTrue($this->file->eof());
$this->assertEquals(0, $this->file->size());
$this->assertEquals('', $this->file->read(5));
$this->assertEquals(5, $this->file->getBytesRead());
$this->assertTrue($this->file->eof());
}
/**
* test reading contents from the file
*
* @test
*/
public function read()
{
$this->file->setContent('foobarbaz');
$this->assertFalse($this->file->eof());
$this->assertEquals(9, $this->file->size());
$this->assertEquals('foo', $this->file->read(3));
$this->assertEquals(3, $this->file->getBytesRead());
$this->assertFalse($this->file->eof());
$this->assertEquals(9, $this->file->size());
$this->assertEquals('bar', $this->file->read(3));
$this->assertEquals(6, $this->file->getBytesRead());
$this->assertFalse($this->file->eof());
$this->assertEquals(9, $this->file->size());
$this->assertEquals('baz', $this->file->read(3));
$this->assertEquals(9, $this->file->getBytesRead());
$this->assertEquals(9, $this->file->size());
$this->assertTrue($this->file->eof());
$this->assertEquals('', $this->file->read(3));
}
/**
* test seeking to offset
*
* @test
*/
public function seekEmptyFile()
{
$this->assertFalse($this->file->seek(0, 55));
$this->assertTrue($this->file->seek(0, SEEK_SET));
$this->assertEquals(0, $this->file->getBytesRead());
$this->assertTrue($this->file->seek(5, SEEK_SET));
$this->assertEquals(5, $this->file->getBytesRead());
$this->assertTrue($this->file->seek(0, SEEK_CUR));
$this->assertEquals(5, $this->file->getBytesRead());
$this->assertTrue($this->file->seek(2, SEEK_CUR));
$this->assertEquals(7, $this->file->getBytesRead());
$this->assertTrue($this->file->seek(0, SEEK_END));
$this->assertEquals(0, $this->file->getBytesRead());
$this->assertTrue($this->file->seek(2, SEEK_END));
$this->assertEquals(2, $this->file->getBytesRead());
}
/**
* test 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 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->getMock('org\bovigo\vfs\content\FileContent');
$mockFileContent->expects($this->once())
->method('content')
->will($this->returnValue('foobarbaz'));
$this->assertEquals(
'foobarbaz',
$this->file->withContent($mockFileContent)
->getContent()
);
}
/**
* @test
* @group issue_79
* @expectedException \InvalidArgumentException
* @since 1.3.0
*/
public function withContentThrowsInvalidArgumentExceptionWhenContentIsNoStringAndNoFileContent()
{
$this->file->withContent(313);
}
}

View File

@ -1,29 +0,0 @@
<?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 \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));
}
}
?>

View File

@ -1,66 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* include path to restore after test run
*
* @var string
*/
protected $backupIncludePath;
/**
* set up test environment
*/
public function setUp()
{
if (defined('HPHP_VERSION')) {
$this->markTestSkipped('Requires https://github.com/facebook/hhvm/issues/1476 to be fixed');
}
$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()
{
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'));
}
}
?>

View File

@ -1,707 +0,0 @@
<?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.
*/
class vfsStreamTestCase extends \PHPUnit_Framework_TestCase
{
/**
* set up test environment
*/
public function setUp()
{
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
* @expectedException \InvalidArgumentException
* @since 0.11.0
*/
public function createThrowsExceptionIfNoBaseDirGivenAndNoRootSet()
{
vfsStream::create(array('test' => array()));
}
/**
* @test
* @group issue_20
* @since 0.11.0
*/
public function createWorksRecursively()
{
$baseDir = vfsStream::create(array('test' => array('foo' => array('test.txt' => 'hello'),
'baz.txt' => 'world'
)
),
new vfsStreamDirectory('baseDir')
);
$this->assertTrue($baseDir->hasChildren());
$this->assertTrue($baseDir->hasChild('test'));
$test = $baseDir->getChild('test');
$this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $test);
$this->assertTrue($test->hasChildren());
$this->assertTrue($test->hasChild('baz.txt'));
$this->assertVfsFile($test->getChild('baz.txt'), 'world');
$this->assertTrue($test->hasChild('foo'));
$foo = $test->getChild('foo');
$this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $foo);
$this->assertTrue($foo->hasChildren());
$this->assertTrue($foo->hasChild('test.txt'));
$this->assertVfsFile($foo->getChild('test.txt'), 'hello');
}
/**
* @test
* @group issue_20
* @since 0.11.0
*/
public function createWorksRecursivelyWithRoot()
{
$root = vfsStream::setup();
$this->assertSame($root,
vfsStream::create(array('test' => array('foo' => array('test.txt' => 'hello'),
'baz.txt' => 'world'
)
)
)
);
$this->assertTrue($root->hasChildren());
$this->assertTrue($root->hasChild('test'));
$test = $root->getChild('test');
$this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $test);
$this->assertTrue($test->hasChildren());
$this->assertTrue($test->hasChild('baz.txt'));
$this->assertVfsFile($test->getChild('baz.txt'), 'world');
$this->assertTrue($test->hasChild('foo'));
$foo = $test->getChild('foo');
$this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $foo);
$this->assertTrue($foo->hasChildren());
$this->assertTrue($foo->hasChild('test.txt'));
$this->assertVfsFile($foo->getChild('test.txt'), 'hello');
}
/**
* @test
* @group issue_20
* @since 0.10.0
*/
public function createStringsAreTurnedIntoFilesWithContent()
{
$baseDir = vfsStream::create(array('test.txt' => 'some content'), new vfsStreamDirectory('baseDir'));
$this->assertTrue($baseDir->hasChildren());
$this->assertTrue($baseDir->hasChild('test.txt'));
$this->assertVfsFile($baseDir->getChild('test.txt'), 'some content');
}
/**
* @test
* @group issue_20
* @since 0.11.0
*/
public function createStringsAreTurnedIntoFilesWithContentWithRoot()
{
$root = vfsStream::setup();
$this->assertSame($root,
vfsStream::create(array('test.txt' => 'some content'))
);
$this->assertTrue($root->hasChildren());
$this->assertTrue($root->hasChild('test.txt'));
$this->assertVfsFile($root->getChild('test.txt'), 'some content');
}
/**
* @test
* @group issue_20
* @since 0.11.0
*/
public function createCastsNumericDirectoriesToStrings()
{
$baseDir = vfsStream::create(array(2011 => array ('test.txt' => 'some content')), new vfsStreamDirectory('baseDir'));
$this->assertTrue($baseDir->hasChild('2011'));
$directory = $baseDir->getChild('2011');
$this->assertVfsFile($directory->getChild('test.txt'), 'some content');
}
/**
* @test
* @group issue_20
* @since 0.11.0
*/
public function createCastsNumericDirectoriesToStringsWithRoot()
{
$root = vfsStream::setup();
$this->assertSame($root,
vfsStream::create(array(2011 => array ('test.txt' => 'some content')))
);
$this->assertTrue($root->hasChild('2011'));
$directory = $root->getChild('2011');
$this->assertVfsFile($directory->getChild('test.txt'), 'some content');
}
/**
* helper function for assertions on vfsStreamFile
*
* @param vfsStreamFile $file
* @param string $content
*/
protected function assertVfsFile(vfsStreamFile $file, $content)
{
$this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamFile',
$file
);
$this->assertEquals($content,
$file->getContent()
);
}
/**
* @test
* @group issue_10
* @since 0.10.0
*/
public function inspectWithContentGivesContentToVisitor()
{
$mockContent = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
$mockVisitor = $this->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->getMock('org\\bovigo\\vfs\\visitor\\vfsStreamVisitor');
$mockVisitor->expects($this->once())
->method('visitDirectory')
->with($this->equalTo($root))
->will($this->returnValue($mockVisitor));
$this->assertSame($mockVisitor, vfsStream::inspect($mockVisitor));
}
/**
* @test
* @group issue_10
* @expectedException \InvalidArgumentException
* @since 0.10.0
*/
public function inspectWithoutContentAndWithoutRootThrowsInvalidArgumentException()
{
$mockVisitor = $this->getMock('org\\bovigo\\vfs\\visitor\\vfsStreamVisitor');
$mockVisitor->expects($this->never())
->method('visit');
$mockVisitor->expects($this->never())
->method('visitDirectory');
vfsStream::inspect($mockVisitor);
}
/**
* returns path to file system copy resource directory
*
* @return string
*/
protected function getFileSystemCopyDir()
{
return realpath(dirname(__FILE__) . '/../../../../resources/filesystemcopy');
}
/**
* @test
* @group issue_4
* @expectedException \InvalidArgumentException
* @since 0.11.0
*/
public function copyFromFileSystemThrowsExceptionIfNoBaseDirGivenAndNoRootSet()
{
vfsStream::copyFromFileSystem($this->getFileSystemCopyDir());
}
/**
* @test
* @group issue_4
* @since 0.11.0
*/
public function copyFromEmptyFolder()
{
$baseDir = vfsStream::copyFromFileSystem($this->getFileSystemCopyDir() . '/emptyFolder',
vfsStream::newDirectory('test')
);
$baseDir->removeChild('.gitignore');
$this->assertFalse($baseDir->hasChildren());
}
/**
* @test
* @group issue_4
* @since 0.11.0
*/
public function copyFromEmptyFolderWithRoot()
{
$root = vfsStream::setup();
$this->assertEquals($root,
vfsStream::copyFromFileSystem($this->getFileSystemCopyDir() . '/emptyFolder')
);
$root->removeChild('.gitignore');
$this->assertFalse($root->hasChildren());
}
/**
* @test
* @group issue_4
* @since 0.11.0
*/
public function copyFromWithSubFolders()
{
$baseDir = vfsStream::copyFromFileSystem($this->getFileSystemCopyDir(),
vfsStream::newDirectory('test'),
3
);
$this->assertTrue($baseDir->hasChildren());
$this->assertTrue($baseDir->hasChild('emptyFolder'));
$this->assertTrue($baseDir->hasChild('withSubfolders'));
$subfolderDir = $baseDir->getChild('withSubfolders');
$this->assertTrue($subfolderDir->hasChild('subfolder1'));
$this->assertTrue($subfolderDir->getChild('subfolder1')->hasChild('file1.txt'));
$this->assertVfsFile($subfolderDir->getChild('subfolder1/file1.txt'), '');
$this->assertTrue($subfolderDir->hasChild('subfolder2'));
$this->assertTrue($subfolderDir->hasChild('aFile.txt'));
$this->assertVfsFile($subfolderDir->getChild('aFile.txt'), 'foo');
}
/**
* @test
* @group issue_4
* @since 0.11.0
*/
public function copyFromWithSubFoldersWithRoot()
{
$root = vfsStream::setup();
$this->assertEquals($root,
vfsStream::copyFromFileSystem($this->getFileSystemCopyDir(),
null,
3
)
);
$this->assertTrue($root->hasChildren());
$this->assertTrue($root->hasChild('emptyFolder'));
$this->assertTrue($root->hasChild('withSubfolders'));
$subfolderDir = $root->getChild('withSubfolders');
$this->assertTrue($subfolderDir->hasChild('subfolder1'));
$this->assertTrue($subfolderDir->getChild('subfolder1')->hasChild('file1.txt'));
$this->assertVfsFile($subfolderDir->getChild('subfolder1/file1.txt'), '');
$this->assertTrue($subfolderDir->hasChild('subfolder2'));
$this->assertTrue($subfolderDir->hasChild('aFile.txt'));
$this->assertVfsFile($subfolderDir->getChild('aFile.txt'), 'foo');
}
/**
* @test
* @group issue_4
* @group issue_29
* @since 0.11.2
*/
public function copyFromPreservesFilePermissions()
{
if (DIRECTORY_SEPARATOR !== '/') {
$this->markTestSkipped('Only applicable on Linux style systems.');
}
$copyDir = $this->getFileSystemCopyDir();
$root = vfsStream::setup();
$this->assertEquals($root,
vfsStream::copyFromFileSystem($copyDir,
null
)
);
$this->assertEquals(fileperms($copyDir . '/withSubfolders') - vfsStreamContent::TYPE_DIR,
$root->getChild('withSubfolders')
->getPermissions()
);
$this->assertEquals(fileperms($copyDir . '/withSubfolders/aFile.txt') - vfsStreamContent::TYPE_FILE,
$root->getChild('withSubfolders/aFile.txt')
->getPermissions()
);
}
}
?>

View File

@ -1,195 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* set up test environment
*/
public function setUp()
{
vfsStream::umask(0000);
}
/**
* clean up test environment
*/
public function tearDown()
{
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'), null);
$this->assertEquals(0000, $root->getChild('newdir')->getPermissions());
}
/**
* @test
*
*/
public function createDirectoryUsingStreamWithDifferentUmaskSettingButExplicit0777()
{
$root = vfsStream::setup();
vfsStream::umask(0022);
mkdir(vfsStream::url('root/newdir'), 0777);
$this->assertEquals(0755, $root->getChild('newdir')->getPermissions());
}
/**
* @test
*/
public function createDirectoryUsingStreamWithDifferentUmaskSettingButExplicitModeRequestedByCall()
{
$root = vfsStream::setup();
vfsStream::umask(0022);
mkdir(vfsStream::url('root/newdir'), 0700);
$this->assertEquals(0700, $root->getChild('newdir')->getPermissions());
}
/**
* @test
*/
public function defaultUmaskSettingDoesNotInfluenceSetup()
{
$root = vfsStream::setup();
$this->assertEquals(0777, $root->getPermissions());
}
/**
* @test
*/
public function umaskSettingShouldBeRespectedBySetup()
{
vfsStream::umask(0022);
$root = vfsStream::setup();
$this->assertEquals(0755, $root->getPermissions());
}
}
?>

View File

@ -1,63 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* set up test environment
*/
public function setUp()
{
TestvfsStreamWrapper::unregister();
$mock = $this->getMock('org\\bovigo\\vfs\\vfsStreamWrapper');
stream_wrapper_register(vfsStream::SCHEME, get_class($mock));
}
/**
* clean up test environment
*/
public function tearDown()
{
TestvfsStreamWrapper::unregister();
}
/**
* registering the stream wrapper when another stream wrapper is already
* registered for the vfs scheme should throw an exception
*
* @test
* @expectedException org\bovigo\vfs\vfsStreamException
*/
public function registerOverAnotherStreamWrapper()
{
vfsStreamWrapper::register();
}
}
?>

View File

@ -1,99 +0,0 @@
<?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 \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()
{
$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);
}
}
?>

View File

@ -1,73 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* root diretory
*
* @var vfsStreamDirectory
*/
protected $root;
/**
* set up test environment
*/
public function setUp()
{
$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\\'));
}
}
?>

View File

@ -1,460 +0,0 @@
<?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 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
* @expectedException PHPUnit_Framework_Error
* @expectedExceptionMessage mkdir(): Path vfs://root/dir exists
*/
public function mkDirShouldNotOverwriteExistingDirectoriesAndTriggerE_USER_WARNING()
{
vfsStream::setup('root');
$dir = vfsStream::url('root/dir');
$this->assertTrue(mkdir($dir));
$this->assertFalse(mkdir($dir));
}
/**
* @test
* @group issue_28
*/
public function mkDirShouldNotOverwriteExistingFiles()
{
$root = vfsStream::setup('root');
vfsStream::newFile('test.txt')->at($root);
$this->assertFalse(@mkdir(vfsStream::url('root/test.txt')));
}
/**
* @test
* @group issue_28
* @expectedException PHPUnit_Framework_Error
* @expectedExceptionMessage mkdir(): Path vfs://root/test.txt exists
*/
public function mkDirShouldNotOverwriteExistingFilesAndTriggerE_USER_WARNING()
{
$root = vfsStream::setup('root');
vfsStream::newFile('test.txt')->at($root);
$this->assertFalse(mkdir(vfsStream::url('root/test.txt')));
}
/**
* @test
* @group 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
* @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'));
}
}
?>

View File

@ -1,458 +0,0 @@
<?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));
}
}
?>

View File

@ -1,315 +0,0 @@
<?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 \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()
{
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(3);
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(3);
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.');
}
}
?>

View File

@ -1,440 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* root directory
*
* @var vfsStreamContainer
*/
protected $root;
/**
* set up test environment
*/
public function setUp()
{
$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);
}
}
?>

View File

@ -1,77 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* large file to test
*
* @var vfsStreamFile
*/
private $largeFile;
/**
* set up test environment
*/
public function setUp()
{
$root = vfsStream::setup();
$this->largeFile = vfsStream::newFile('large.txt')
->withContent(LargeFileContent::withGigabytes(100))
->at($root);
}
/**
* @test
*/
public function hasLargeFileSize()
{
$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)
);
}
}

View File

@ -1,224 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* access to root
*
* @type vfsStreamDirectory
*/
private $root;
/**
* set up test environment
*/
public function setUp()
{
$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()
);
}
}
?>

View File

@ -1,76 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* root directory
*
* @var vfsStreamContainer
*/
protected $root;
/**
* set up test environment
*/
public function setUp()
{
$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);
}
}
?>

View File

@ -1,35 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* @test
* @expectedException \PHPUnit_Framework_Error
*/
public function selectStream()
{
$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);
}
}
?>

View File

@ -1,770 +0,0 @@
<?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 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 directoriesAndNonExistingFilesAreNeverExecutable()
{
$this->assertFalse(is_executable($this->fooURL));
$this->assertFalse(is_executable($this->fooURL . '/.'));
$this->assertFalse(is_executable($this->barURL));
$this->assertFalse(is_executable($this->barURL . '/.'));
$this->assertFalse(is_executable($this->fooURL . '/another'));
$this->assertFalse(is_executable(vfsStream::url('another')));
}
/**
* file permissions
*
* @test
* @group permissions
*/
public function chmod()
{
$this->assertEquals(40777, decoct(fileperms($this->fooURL)));
$this->assertEquals(40777, decoct(fileperms($this->fooURL . '/.')));
$this->assertEquals(40777, decoct(fileperms($this->barURL)));
$this->assertEquals(40777, decoct(fileperms($this->barURL . '/.')));
$this->assertEquals(100666, decoct(fileperms($this->baz1URL)));
$this->assertEquals(100666, decoct(fileperms($this->baz2URL)));
$this->foo->chmod(0755);
$this->bar->chmod(0700);
$this->baz1->chmod(0644);
$this->baz2->chmod(0600);
$this->assertEquals(40755, decoct(fileperms($this->fooURL)));
$this->assertEquals(40755, decoct(fileperms($this->fooURL . '/.')));
$this->assertEquals(40700, decoct(fileperms($this->barURL)));
$this->assertEquals(40700, decoct(fileperms($this->barURL . '/.')));
$this->assertEquals(100644, decoct(fileperms($this->baz1URL)));
$this->assertEquals(100600, decoct(fileperms($this->baz2URL)));
}
/**
* @test
* @group issue_11
* @group permissions
*/
public function chmodModifiesPermissions()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
$this->assertFalse(@chmod($this->fooURL, 0755));
$this->assertFalse(@chmod($this->barURL, 0711));
$this->assertFalse(@chmod($this->baz1URL, 0644));
$this->assertFalse(@chmod($this->baz2URL, 0664));
$this->assertEquals(40777, decoct(fileperms($this->fooURL)));
$this->assertEquals(40777, decoct(fileperms($this->barURL)));
$this->assertEquals(100666, decoct(fileperms($this->baz1URL)));
$this->assertEquals(100666, decoct(fileperms($this->baz2URL)));
} else {
$this->assertTrue(chmod($this->fooURL, 0755));
$this->assertTrue(chmod($this->barURL, 0711));
$this->assertTrue(chmod($this->baz1URL, 0644));
$this->assertTrue(chmod($this->baz2URL, 0664));
$this->assertEquals(40755, decoct(fileperms($this->fooURL)));
$this->assertEquals(40711, decoct(fileperms($this->barURL)));
$this->assertEquals(100644, decoct(fileperms($this->baz1URL)));
$this->assertEquals(100664, decoct(fileperms($this->baz2URL)));
}
}
/**
* @test
* @group permissions
*/
public function fileownerIsCurrentUserByDefault()
{
$this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL));
$this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL . '/.'));
$this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->barURL));
$this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->barURL . '/.'));
$this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->baz1URL));
$this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->baz2URL));
}
/**
* @test
* @group issue_11
* @group permissions
*/
public function chownChangesUser()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
$this->foo->chown(vfsStream::OWNER_USER_1);
$this->bar->chown(vfsStream::OWNER_USER_1);
$this->baz1->chown(vfsStream::OWNER_USER_2);
$this->baz2->chown(vfsStream::OWNER_USER_2);
} else {
chown($this->fooURL, vfsStream::OWNER_USER_1);
chown($this->barURL, vfsStream::OWNER_USER_1);
chown($this->baz1URL, vfsStream::OWNER_USER_2);
chown($this->baz2URL, vfsStream::OWNER_USER_2);
}
$this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->fooURL));
$this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->fooURL . '/.'));
$this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->barURL));
$this->assertEquals(vfsStream::OWNER_USER_1, fileowner($this->barURL . '/.'));
$this->assertEquals(vfsStream::OWNER_USER_2, fileowner($this->baz1URL));
$this->assertEquals(vfsStream::OWNER_USER_2, fileowner($this->baz2URL));
}
/**
* @test
* @group issue_11
* @group permissions
*/
public function chownDoesNotWorkOnVfsStreamUrls()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
$this->assertFalse(@chown($this->fooURL, vfsStream::OWNER_USER_2));
$this->assertEquals(vfsStream::getCurrentUser(), fileowner($this->fooURL));
}
}
/**
* @test
* @group issue_11
* @group permissions
*/
public function groupIsCurrentGroupByDefault()
{
$this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL));
$this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL . '/.'));
$this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->barURL));
$this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->barURL . '/.'));
$this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->baz1URL));
$this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->baz2URL));
}
/**
* @test
* @group issue_11
* @group permissions
*/
public function chgrp()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
$this->foo->chgrp(vfsStream::GROUP_USER_1);
$this->bar->chgrp(vfsStream::GROUP_USER_1);
$this->baz1->chgrp(vfsStream::GROUP_USER_2);
$this->baz2->chgrp(vfsStream::GROUP_USER_2);
} else {
chgrp($this->fooURL, vfsStream::GROUP_USER_1);
chgrp($this->barURL, vfsStream::GROUP_USER_1);
chgrp($this->baz1URL, vfsStream::GROUP_USER_2);
chgrp($this->baz2URL, vfsStream::GROUP_USER_2);
}
$this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->fooURL));
$this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->fooURL . '/.'));
$this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->barURL));
$this->assertEquals(vfsStream::GROUP_USER_1, filegroup($this->barURL . '/.'));
$this->assertEquals(vfsStream::GROUP_USER_2, filegroup($this->baz1URL));
$this->assertEquals(vfsStream::GROUP_USER_2, filegroup($this->baz2URL));
}
/**
* @test
* @group issue_11
* @group permissions
*/
public function chgrpDoesNotWorkOnVfsStreamUrls()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
$this->assertFalse(@chgrp($this->fooURL, vfsStream::GROUP_USER_2));
$this->assertEquals(vfsStream::getCurrentGroup(), filegroup($this->fooURL));
}
}
/**
* @test
* @author Benoit Aubuchon
*/
public function renameDirectory()
{
// move foo/bar to foo/baz3
$baz3URL = vfsStream::url('foo/baz3');
$this->assertTrue(rename($this->barURL, $baz3URL));
$this->assertFileExists($baz3URL);
$this->assertFileNotExists($this->barURL);
}
/**
* @test
*/
public function renameDirectoryWithDots()
{
// move foo/bar to foo/baz3
$baz3URL = vfsStream::url('foo/baz3');
$this->assertTrue(rename($this->barURL . '/.', $baz3URL));
$this->assertFileExists($baz3URL);
$this->assertFileNotExists($this->barURL);
}
/**
* @test
* @group issue_9
* @since 0.9.0
*/
public function renameDirectoryWithDotsInTarget()
{
// move foo/bar to foo/baz3
$baz3URL = vfsStream::url('foo/../foo/baz3/.');
$this->assertTrue(rename($this->barURL . '/.', $baz3URL));
$this->assertFileExists($baz3URL);
$this->assertFileNotExists($this->barURL);
}
/**
* @test
* @author Benoit Aubuchon
*/
public function renameDirectoryOverwritingExistingFile()
{
// move foo/bar to foo/baz2
$this->assertTrue(rename($this->barURL, $this->baz2URL));
$this->assertFileExists(vfsStream::url('foo/baz2/baz1'));
$this->assertFileNotExists($this->barURL);
}
/**
* @test
* @expectedException PHPUnit_Framework_Error
*/
public function renameFileIntoFile()
{
// foo/baz2 is a file, so it can not be turned into a directory
$baz3URL = vfsStream::url('foo/baz2/baz3');
$this->assertTrue(rename($this->baz1URL, $baz3URL));
$this->assertFileExists($baz3URL);
$this->assertFileNotExists($this->baz1URL);
}
/**
* @test
* @author Benoit Aubuchon
*/
public function renameFileToDirectory()
{
// move foo/bar/baz1 to foo/baz3
$baz3URL = vfsStream::url('foo/baz3');
$this->assertTrue(rename($this->baz1URL, $baz3URL));
$this->assertFileExists($this->barURL);
$this->assertFileExists($baz3URL);
$this->assertFileNotExists($this->baz1URL);
}
/**
* assert that trying to rename from a non existing file trigger a warning
*
* @expectedException PHPUnit_Framework_Error
* @test
*/
public function renameOnSourceFileNotFound()
{
rename(vfsStream::url('notfound'), $this->baz1URL);
}
/**
* assert that trying to rename to a directory that is not found trigger a warning
* @expectedException PHPUnit_Framework_Error
* @test
*/
public function renameOnDestinationDirectoryFileNotFound()
{
rename($this->baz1URL, vfsStream::url('foo/notfound/file2'));
}
/**
* stat() and fstat() should return the same result
*
* @test
*/
public function statAndFstatReturnSameResult()
{
$fp = fopen($this->baz2URL, 'r');
$this->assertEquals(stat($this->baz2URL),
fstat($fp)
);
fclose($fp);
}
/**
* stat() returns full data
*
* @test
*/
public function statReturnsFullDataForFiles()
{
$this->assertEquals(array(0 => 0,
1 => 0,
2 => 0100666,
3 => 0,
4 => vfsStream::getCurrentUser(),
5 => vfsStream::getCurrentGroup(),
6 => 0,
7 => 4,
8 => 400,
9 => 400,
10 => 400,
11 => -1,
12 => -1,
'dev' => 0,
'ino' => 0,
'mode' => 0100666,
'nlink' => 0,
'uid' => vfsStream::getCurrentUser(),
'gid' => vfsStream::getCurrentGroup(),
'rdev' => 0,
'size' => 4,
'atime' => 400,
'mtime' => 400,
'ctime' => 400,
'blksize' => -1,
'blocks' => -1
),
stat($this->baz2URL)
);
}
/**
* @test
*/
public function statReturnsFullDataForDirectories()
{
$this->assertEquals(array(0 => 0,
1 => 0,
2 => 0040777,
3 => 0,
4 => vfsStream::getCurrentUser(),
5 => vfsStream::getCurrentGroup(),
6 => 0,
7 => 0,
8 => 100,
9 => 100,
10 => 100,
11 => -1,
12 => -1,
'dev' => 0,
'ino' => 0,
'mode' => 0040777,
'nlink' => 0,
'uid' => vfsStream::getCurrentUser(),
'gid' => vfsStream::getCurrentGroup(),
'rdev' => 0,
'size' => 0,
'atime' => 100,
'mtime' => 100,
'ctime' => 100,
'blksize' => -1,
'blocks' => -1
),
stat($this->fooURL)
);
}
/**
* @test
*/
public function statReturnsFullDataForDirectoriesWithDot()
{
$this->assertEquals(array(0 => 0,
1 => 0,
2 => 0040777,
3 => 0,
4 => vfsStream::getCurrentUser(),
5 => vfsStream::getCurrentGroup(),
6 => 0,
7 => 0,
8 => 100,
9 => 100,
10 => 100,
11 => -1,
12 => -1,
'dev' => 0,
'ino' => 0,
'mode' => 0040777,
'nlink' => 0,
'uid' => vfsStream::getCurrentUser(),
'gid' => vfsStream::getCurrentGroup(),
'rdev' => 0,
'size' => 0,
'atime' => 100,
'mtime' => 100,
'ctime' => 100,
'blksize' => -1,
'blocks' => -1
),
stat($this->fooURL . '/.')
);
}
/**
* @test
* @expectedException PHPUnit_Framework_Error
*/
public function openFileWithoutDirectory()
{
vfsStreamWrapper::register();
$this->assertFalse(file_get_contents(vfsStream::url('file.txt')));
}
/**
* @test
* @group issue_33
* @since 1.1.0
* @requires PHP 5.4.0
*/
public function truncateRemovesSuperflouosContent()
{
if (strstr(PHP_VERSION, 'hiphop') !== false) {
$this->markTestSkipped('Not supported on hhvm');
}
$handle = fopen($this->baz1URL, "r+");
$this->assertTrue(ftruncate($handle, 0));
$this->assertEquals(0, filesize($this->baz1URL));
$this->assertEquals('', file_get_contents($this->baz1URL));
fclose($handle);
}
/**
* @test
* @group issue_33
* @since 1.1.0
* @requires PHP 5.4.0
*/
public function truncateToGreaterSizeAddsZeroBytes()
{
if (strstr(PHP_VERSION, 'hiphop') !== false) {
$this->markTestSkipped('Not supported on hhvm');
}
$handle = fopen($this->baz1URL, "r+");
$this->assertTrue(ftruncate($handle, 25));
$this->assertEquals(25, filesize($this->baz1URL));
$this->assertEquals("baz 1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
file_get_contents($this->baz1URL));
fclose($handle);
}
/**
* @test
* @group issue_11
* @requires PHP 5.4.0
*/
public function touchCreatesNonExistingFile()
{
$this->assertTrue(touch($this->fooURL . '/new.txt'));
$this->assertTrue($this->foo->hasChild('new.txt'));
}
/**
* @test
* @group issue_11
* @requires PHP 5.4.0
*/
public function touchChangesAccessAndModificationTimeForFile()
{
$this->assertTrue(touch($this->baz1URL, 303, 313));
$this->assertEquals(303, $this->baz1->filemtime());
$this->assertEquals(313, $this->baz1->fileatime());
}
/**
* @test
* @group issue_11
* @group issue_80
* @requires PHP 5.4.0
*/
public function touchChangesTimesToCurrentTimestampWhenNoTimesGiven()
{
$this->assertTrue(touch($this->baz1URL));
$this->assertEquals(time(), $this->baz1->filemtime(), '', 1);
$this->assertEquals(time(), $this->baz1->fileatime(), '', 1);
}
/**
* @test
* @group issue_11
* @requires PHP 5.4.0
*/
public function touchWithModifiedTimeChangesAccessAndModifiedTime()
{
$this->assertTrue(touch($this->baz1URL, 303));
$this->assertEquals(303, $this->baz1->filemtime());
$this->assertEquals(303, $this->baz1->fileatime());
}
/**
* @test
* @group issue_11
* @requires PHP 5.4.0
*/
public function touchChangesAccessAndModificationTimeForDirectory()
{
$this->assertTrue(touch($this->fooURL, 303, 313));
$this->assertEquals(303, $this->foo->filemtime());
$this->assertEquals(313, $this->foo->fileatime());
}
/**
* @test
* @group issue_34
* @since 1.2.0
*/
public function pathesAreCorrectlySet()
{
$this->assertEquals(vfsStream::path($this->fooURL), $this->foo->path());
$this->assertEquals(vfsStream::path($this->barURL), $this->bar->path());
$this->assertEquals(vfsStream::path($this->baz1URL), $this->baz1->path());
$this->assertEquals(vfsStream::path($this->baz2URL), $this->baz2->path());
}
/**
* @test
* @group issue_34
* @since 1.2.0
*/
public function urlsAreCorrectlySet()
{
$this->assertEquals($this->fooURL, $this->foo->url());
$this->assertEquals($this->barURL, $this->bar->url());
$this->assertEquals($this->baz1URL, $this->baz1->url());
$this->assertEquals($this->baz2URL, $this->baz2->url());
}
/**
* @test
* @group issue_34
* @since 1.2.0
*/
public function pathIsUpdatedAfterMove()
{
// move foo/bar/baz1 to foo/baz3
$baz3URL = vfsStream::url('foo/baz3');
$this->assertTrue(rename($this->baz1URL, $baz3URL));
$this->assertEquals(vfsStream::path($baz3URL), $this->baz1->path());
}
/**
* @test
* @group issue_34
* @since 1.2.0
*/
public function urlIsUpdatedAfterMove()
{
// move foo/bar/baz1 to foo/baz3
$baz3URL = vfsStream::url('foo/baz3');
$this->assertTrue(rename($this->baz1URL, $baz3URL));
$this->assertEquals($baz3URL, $this->baz1->url());
}
}

View File

@ -1,64 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* set up test environment
*/
public function setUp()
{
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')));
}
/**
* can not rename a file without root
*
* @test
*/
public function canNotRename()
{
$this->assertFalse(@rename(vfsStream::url('foo'), vfsStream::url('bar')));
}
}
?>

View File

@ -1,53 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* set up test environment
*/
public function setUp()
{
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')));
}
}
?>

View File

@ -1,99 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* instance to test
*
* @var vfsStreamAbstractVisitor
*/
protected $abstractVisitor;
/**
* set up test environment
*/
public function setUp()
{
$this->abstractVisitor = $this->getMock('org\\bovigo\\vfs\\visitor\\vfsStreamAbstractVisitor',
array('visitFile', 'visitDirectory')
);
}
/**
* @test
* @expectedException \InvalidArgumentException
*/
public function visitThrowsInvalidArgumentExceptionOnUnknownContentType()
{
$mockContent = $this->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)
);
}
}
?>

View File

@ -1,103 +0,0 @@
<?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 \PHPUnit_Framework_TestCase
{
/**
* @test
* @expectedException \InvalidArgumentException
*/
public function constructWithNonResourceThrowsInvalidArgumentException()
{
new vfsStreamPrintVisitor('invalid');
}
/**
* @test
* @expectedException \InvalidArgumentException
*/
public function constructWithNonStreamResourceThrowsInvalidArgumentException()
{
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'));
}
}
?>

View File

@ -1,86 +0,0 @@
<?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 \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()
);
}
}
?>