X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fmikey179%2FvfsStream%2Fsrc%2Ftest%2Fphp%2Forg%2Fbovigo%2Fvfs%2FDirectoryIterationTestCase.php;fp=vendor%2Fmikey179%2FvfsStream%2Fsrc%2Ftest%2Fphp%2Forg%2Fbovigo%2Fvfs%2FDirectoryIterationTestCase.php;h=4f30b038b6b0fd840260bd974d249dc7c95ebc90;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php b/vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php new file mode 100644 index 000000000..4f30b038b --- /dev/null +++ b/vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php @@ -0,0 +1,318 @@ +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 + ); + } +} \ No newline at end of file