Commit 62047d88 authored by alexpott's avatar alexpott

Issue #2294439 by dawehner, sun | neclimdul: Add vfsStream library for...

Issue #2294439 by dawehner, sun | neclimdul: Add vfsStream library for filesystem mocking in unit tests.
parent 7d0c5795
......@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "d89a37ea785ca09523298ff00ade2eca",
"hash": "e1a7eeed7d09f5c76f642f07b7a0a579",
"packages": [
{
"name": "doctrine/annotations",
......@@ -646,6 +646,36 @@
],
"time": "2013-06-01 22:13:43"
},
{
"name": "mikey179/vfsStream",
"version": "v1.2.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "063fb10633f10c5ccbcac26227e94f46d9336f90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/063fb10633f10c5ccbcac26227e94f46d9336f90",
"reference": "063fb10633f10c5ccbcac26227e94f46d9336f90",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"homepage": "http://vfs.bovigo.org/",
"time": "2013-04-01 10:41:02"
},
{
"name": "phpunit/php-code-coverage",
"version": "2.0.8",
......@@ -2393,8 +2423,12 @@
"time": "2013-06-12 19:46:58"
}
],
"packages-dev": [],
"aliases": [],
"packages-dev": [
],
"aliases": [
],
"minimum-stability": "stable",
"stability-flags": {
"symfony/yaml": 20,
......@@ -2407,5 +2441,7 @@
"platform": {
"php": ">=5.4.2"
},
"platform-dev": []
"platform-dev": [
]
}
......@@ -6,6 +6,7 @@
$baseDir = dirname(dirname($vendorDir));
return array(
'org\\bovigo\\vfs\\' => array($vendorDir . '/mikey179/vfsStream/src/main/php'),
'Zend\\Stdlib\\' => array($vendorDir . '/zendframework/zend-stdlib'),
'Zend\\Feed\\' => array($vendorDir . '/zendframework/zend-feed'),
'Zend\\Escaper\\' => array($vendorDir . '/zendframework/zend-escaper'),
......
......@@ -2470,5 +2470,37 @@
"rest",
"web service"
]
},
{
"name": "mikey179/vfsStream",
"version": "v1.2.0",
"version_normalized": "1.2.0.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "063fb10633f10c5ccbcac26227e94f46d9336f90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/063fb10633f10c5ccbcac26227e94f46d9336f90",
"reference": "063fb10633f10c5ccbcac26227e94f46d9336f90",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2013-04-01 10:41:02",
"type": "library",
"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/"
}
]
language: php
php:
- 5.3
- 5.4
- 5.5
before_script:
- composer install --dev
script: phpunit --coverage-text
1.2.0, 2013-04-01
==================
- implemented issue #34: provide url() method on all vfsStreamContent instances
- added org\bovigo\vfs\vfsStreamContent::url()
- added org\bovigo\vfs\vfsStreamContent::path()
- fixed issue #40: flock implementation doesn't work correctly, patch provided
by Kamil Dziedzic
- fixed issue #49: call to member function on a non-object when trying to delete
a file one above root where a file with same name in root exists
- fixed issue #51: unlink() must consider permissions of directory where file is
inside, not of the file to unlink itself
- fixed issue #52: chmod(), chown() and chgrp() must consider permissions of
directory where file/directory is inside
- fixed issue #53: chmod(), chown() and chgrp() must consider current user and
current owner of file/directoy to change
1.1.0, 2012-08-25
==================
- implemented issue #11: add support for streamWrapper::stream_metadata()
vfsStream now supports touch(), chown(), chgrp() and chmod()
- implemented issue #33: add support for stream_truncate
(provided by https://github.com/nikcorg)
- implemented issue #35: size limit (quota) for VFS
1.0.0, 2012-05-15
==================
- raised requirement for PHP version to 5.3.0
- migrated codebase to use namespaces
- changed distribution from PEAR to Composer
- implemented issue #30: support "c" mode for fopen()
- fixed issue #31: prohibit aquiring locks when already locked / release lock on
fclose()
- fixed issue #32: problems when subfolder has same name as folder
- fixed issue #36: vfsStreamWrapper::stream_open should return false while
trying to open existing non-writable file, patch provided by Alexander Peresypkin
0.11.2, 2012-01-14
==================
- fixed issue #29: set permissions properly when using
vfsStream::copyFromFileSystem(), patch provided by predakanga
- fixed failing tests under PHP > 5.3.2
0.11.1, 2011-12-04
==================
- fixed issue #28: mkdir overwrites existing directories/files
0.11.0, 2011-11-29
==================
- implemented issue #20: vfsStream::create() removes old structure
- implemented issue #4: possibility to copy structure from existing file system
- fixed issue #23: unlink should not remove any directory
- fixed issue #25: vfsStreamDirectory::hasChild() gives false positives for
nested paths, patch provided by Andrew Coulton
- fixed issue #26: opening a file for reading only should not update its
modification time, reported and initial patch provided by Ludovic Chabant
0.10.1, 2011-08-22
==================
- fixed issue #16: replace vfsStreamContent to vfsStreamContainer for
autocompletion
- fixed issue #17: vfsStream::create() has issues with numeric directories,
patch provided by mathieuk
0.10.0, 2011-07-22
==================
- added new method vfsStreamContainer::hasChildren() and
vfsStreamDirectory::hasChildren()
- implemented issue #14: less verbose way to initialize vfsStream
- implemented issue #13: remove deprecated method vfsStreamContent::setFilemtime()
- implemented issue #6: locking meachanism for files
- ensured that stream_set_blocking(), stream_set_timeout() and
stream_set_write_buffer() on vfsStream urls have the same behaviour
with PHP 5.2 and 5.3
- implemented issue #10: method to print directory structure
0.9.0, 2011-07-13
=================
- implemented feature request issue #7: add support for fileatime() and filectime()
- fixed issue #3: add support for streamWrapper::stream_cast()
- fixed issue #9: resolve path not called everywhere its needed
- deprecated vfsStreamAbstractContent::setFilemtime(), use
vfsStreamAbstractContent::lastModified() instead, will be removed with 0.10.0
0.8.0, 2010-10-08
=================
- implemented enhancement #6: use vfsStream::umask() to influence initial file
mode for files and directories
- implemented enhancement #19: support of .. in the url, patch provided by
Guislain Duthieuw
- fixed issue #18: getChild() returns NULL when child's name contains parent name
- fixed bug with incomplete error message when accessing non-existing files on
root level
0.7.0, 2010-06-08
=================
- added new vfsStream::setup() method to simplify vfsStream usage
- fixed issue #15: mkdir creates a subfolder in a folder without permissions
0.6.0, 2010-02-15
=================
- added support for $mode param when opening files, implements enhancement #7
and fixes issue #13
- vfsStreamWrapper::stream_open() now evaluates $options for STREAM_REPORT_ERRORS
0.5.0, 2010-01-25
=================
- added support for rename(), patch provided by Benoit Aubuchon
- added support for . as directory alias so that vfs://foo/. resolves to
vfs://foo, can be used as workaround for bug #8
0.4.0, 2009-07-13
=================
- added support for file modes, users and groups (with restrictions, see
http://code.google.com/p/bovigo/wiki/vfsStreamDocsKnownIssues)
- fixed bug #5: vfsStreamDirectory::addChild() does not replace child with same
name
- fixed bug with is_writable() because of missing stat() fields, patch provided
by Sergey Galkin
0.3.2, 2009-02-16
=================
- support trailing slashes on directories in vfsStream urls, patch provided by
Gabriel Birke
- fixed bug #4: vfsstream can only be read once, reported by Christoph Bloemer
- enabled multiple iterations at the same time over the same directory
0.3.1, 2008-02-18
=================
- fixed path/directory separator issues under linux systems
- fixed uid/gid issues under linux systems
0.3.0, 2008-01-02
=================
- added support for rmdir()
- added vfsStream::newDirectory(), dropped vfsStreamDirectory::ceate()
- added new interface vfsStreamContainer
- added vfsStreamContent::at() which allows code like
$file = vfsStream::newFile('file.txt.')->withContent('foo')->at($otherDir);
- added vfsStreamContent::lastModified(), made vfsStreamContent::setFilemtime()
an alias for this
- moved from Stubbles development environment to bovigo
- refactorings to reduce crap index of various methods
0.2.0, 2007-12-29
=================
- moved vfsStreamWrapper::PROTOCOL to vfsStream::SCHEME
- added new vfsStream::url() method to assist in creating correct vfsStream urls
- added vfsStream::path() method as opposite to vfsStream::url()
- a call to vfsStreamWrapper::register() will now reset the root to null,
implemented on request from David Zuelke
- added support for is_readable(), is_dir(), is_file()
- added vfsStream::newFile() to be able to do
$file = vfsStream::newFile("foo.txt")->withContent("bar");
0.1.0, 2007-12-14
=================
Initial release.
Copyright (c) 2007-2013, Frank Kleine
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Stubbles nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{
"name": "mikey179/vfsStream",
"type": "library",
"homepage": "http://vfs.bovigo.org/",
"license": "BSD",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": { "org\\bovigo\\vfs\\": "src/main/php" }
}
}
\ No newline at end of file
<?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...
}
?>
\ No newline at end of file
<?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'));
}
}
?>
\ No newline at end of file
<?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'));
}
}
?>
\ No newline at end of file
<?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...
}
?>
\ No newline at end of file
<?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());
}
}
?>
\ No newline at end of file
<?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')));
}
}
}
?>
\ No newline at end of file
<?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
{