3 * This file is part of vfsStream.
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
8 * @package org\bovigo\vfs
10 namespace org\bovigo\vfs;
12 * Test for org\bovigo\vfs\vfsStreamContainerIterator.
14 class vfsStreamContainerIteratorTestCase extends \PHPUnit_Framework_TestCase
19 * @type vfsStreamDirectory
25 * @type \PHPUnit_Framework_MockObject_MockObject
31 * @type \PHPUnit_Framework_MockObject_MockObject
36 * set up test environment
38 public function setUp()
40 $this->dir = new vfsStreamDirectory('foo');
41 $this->mockChild1 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
42 $this->mockChild1->expects($this->any())
44 ->will($this->returnValue('bar'));
45 $this->dir->addChild($this->mockChild1);
46 $this->mockChild2 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
47 $this->mockChild2->expects($this->any())
49 ->will($this->returnValue('baz'));
50 $this->dir->addChild($this->mockChild2);
54 * clean up test environment
56 public function tearDown()
58 vfsStream::enableDotfiles();
64 public function provideSwitchWithExpectations()
66 return array(array(function() { vfsStream::disableDotfiles(); },
69 array(function() { vfsStream::enableDotfiles(); },
75 private function getDirName($dir)
77 if (is_string($dir)) {
82 return $dir->getName();
86 * @param \Closure $dotFilesSwitch
87 * @param array $dirNames
89 * @dataProvider provideSwitchWithExpectations
91 public function iteration(\Closure $dotFilesSwitch, array $dirs)
93 $dirs[] = $this->mockChild1;
94 $dirs[] = $this->mockChild2;
96 $dirIterator = $this->dir->getIterator();
97 foreach ($dirs as $dir) {
98 $this->assertEquals($this->getDirName($dir), $dirIterator->key());
99 $this->assertTrue($dirIterator->valid());
100 if (!is_string($dir)) {
101 $this->assertSame($dir, $dirIterator->current());
104 $dirIterator->next();
107 $this->assertFalse($dirIterator->valid());
108 $this->assertNull($dirIterator->key());
109 $this->assertNull($dirIterator->current());