View source
<?php
namespace org\bovigo\vfs;
require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php';
class vfsStreamWrapperTestCase extends vfsStreamWrapperBaseTestCase {
public function resetByRegister() {
$this
->assertSame($this->foo, vfsStreamWrapper::getRoot());
vfsStreamWrapper::register();
$this
->assertNull(vfsStreamWrapper::getRoot());
}
public function setRootReturnsRoot() {
vfsStreamWrapper::register();
$root = vfsStream::newDirectory('root');
$this
->assertSame($root, vfsStreamWrapper::setRoot($root));
}
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));
}
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')));
}
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));
}
public function unlinkRemovesFilesOnly() {
$this
->assertTrue(unlink($this->baz2URL));
$this
->assertFalse(file_exists($this->baz2URL));
$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());
}
public function unlinkReturnsFalseWhenFileDoesNotExist() {
vfsStream::setup()
->addChild(vfsStream::newFile('foo.blubb'));
$this
->assertFalse(@unlink(vfsStream::url('foo.blubb2')));
}
public function unlinkReturnsFalseWhenFileDoesNotExistAndFileWithSameNameExistsInRoot() {
vfsStream::setup()
->addChild(vfsStream::newFile('foo.blubb'));
$this
->assertFalse(@unlink(vfsStream::url('foo.blubb')));
}
public function dirname() {
$this
->assertEquals($this->fooURL, dirname($this->barURL));
$this
->assertEquals($this->barURL, dirname($this->baz1URL));
}
public function basename() {
$this
->assertEquals('bar', basename($this->barURL));
$this
->assertEquals('baz1', basename($this->baz1URL));
$this
->assertEquals('doesNotExist', basename(vfsStream::url('doesNotExist')));
}
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));
}
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));
}
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));
}
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')));
}
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)));
}
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)));
}
}
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));
}
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));
}
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));
}
}
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));
}
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));
}
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));
}
}
public function renameDirectory() {
$baz3URL = vfsStream::url('foo/baz3');
$this
->assertTrue(rename($this->barURL, $baz3URL));
$this
->assertFileExists($baz3URL);
$this
->assertFileNotExists($this->barURL);
}
public function renameDirectoryWithDots() {
$baz3URL = vfsStream::url('foo/baz3');
$this
->assertTrue(rename($this->barURL . '/.', $baz3URL));
$this
->assertFileExists($baz3URL);
$this
->assertFileNotExists($this->barURL);
}
public function renameDirectoryWithDotsInTarget() {
$baz3URL = vfsStream::url('foo/../baz3/.');
$this
->assertTrue(rename($this->barURL . '/.', $baz3URL));
$this
->assertFileExists($baz3URL);
$this
->assertFileNotExists($this->barURL);
}
public function renameDirectoryOverwritingExistingFile() {
$this
->assertTrue(rename($this->barURL, $this->baz2URL));
$this
->assertFileExists(vfsStream::url('foo/baz2/baz1'));
$this
->assertFileNotExists($this->barURL);
}
public function renameFileIntoFile() {
$baz3URL = vfsStream::url('foo/baz2/baz3');
$this
->assertTrue(rename($this->baz1URL, $baz3URL));
$this
->assertFileExists($baz3URL);
$this
->assertFileNotExists($this->baz1URL);
}
public function renameFileToDirectory() {
$baz3URL = vfsStream::url('foo/baz3');
$this
->assertTrue(rename($this->baz1URL, $baz3URL));
$this
->assertFileExists($this->barURL);
$this
->assertFileExists($baz3URL);
$this
->assertFileNotExists($this->baz1URL);
}
public function renameOnSourceFileNotFound() {
rename(vfsStream::url('notfound'), $this->baz1URL);
}
public function renameOnDestinationDirectoryFileNotFound() {
rename($this->baz1URL, vfsStream::url('foo/notfound/file2'));
}
public function statAndFstatReturnSameResult() {
$fp = fopen($this->baz2URL, 'r');
$this
->assertEquals(stat($this->baz2URL), fstat($fp));
fclose($fp);
}
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));
}
public function statReturnsFullDataForDirectories() {
$this
->assertEquals(array(
0 => 0,
1 => 0,
2 => 040777,
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' => 040777,
'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));
}
public function statReturnsFullDataForDirectoriesWithDot() {
$this
->assertEquals(array(
0 => 0,
1 => 0,
2 => 040777,
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' => 040777,
'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 . '/.'));
}
public function openFileWithoutDirectory() {
vfsStreamWrapper::register();
$this
->assertFalse(file_get_contents(vfsStream::url('file.txt')));
}
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);
}
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);
}
public function touchCreatesNonExistingFile() {
$this
->assertTrue(touch($this->fooURL . '/new.txt'));
$this
->assertTrue($this->foo
->hasChild('new.txt'));
}
public function touchChangesAccessAndModificationTimeForFile() {
$this
->assertTrue(touch($this->baz1URL, 303, 313));
$this
->assertEquals(303, $this->baz1
->filemtime());
$this
->assertEquals(313, $this->baz1
->fileatime());
}
public function touchChangesTimesToCurrentTimestampWhenNoTimesGiven() {
$this
->assertTrue(touch($this->baz1URL));
$this
->assertEquals(time(), $this->baz1
->filemtime(), '', 1);
$this
->assertEquals(time(), $this->baz1
->fileatime(), '', 1);
}
public function touchWithModifiedTimeChangesAccessAndModifiedTime() {
$this
->assertTrue(touch($this->baz1URL, 303));
$this
->assertEquals(303, $this->baz1
->filemtime());
$this
->assertEquals(303, $this->baz1
->fileatime());
}
public function touchChangesAccessAndModificationTimeForDirectory() {
$this
->assertTrue(touch($this->fooURL, 303, 313));
$this
->assertEquals(303, $this->foo
->filemtime());
$this
->assertEquals(313, $this->foo
->fileatime());
}
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());
}
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());
}
public function pathIsUpdatedAfterMove() {
$baz3URL = vfsStream::url('foo/baz3');
$this
->assertTrue(rename($this->baz1URL, $baz3URL));
$this
->assertEquals(vfsStream::path($baz3URL), $this->baz1
->path());
}
public function urlIsUpdatedAfterMove() {
$baz3URL = vfsStream::url('foo/baz3');
$this
->assertTrue(rename($this->baz1URL, $baz3URL));
$this
->assertEquals($baz3URL, $this->baz1
->url());
}
}