a0d7f7467720e02da5dbcd6f9663ef888206eeaa
[yaffs-website] / vendor / mikey179 / vfsStream / src / test / php / org / bovigo / vfs / vfsStreamContainerIteratorTestCase.php
1 <?php
2 /**
3  * This file is part of vfsStream.
4  *
5  * For the full copyright and license information, please view the LICENSE
6  * file that was distributed with this source code.
7  *
8  * @package  org\bovigo\vfs
9  */
10 namespace org\bovigo\vfs;
11 /**
12  * Test for org\bovigo\vfs\vfsStreamContainerIterator.
13  */
14 class vfsStreamContainerIteratorTestCase extends \PHPUnit_Framework_TestCase
15 {
16     /**
17      * instance to test
18      *
19      * @type  vfsStreamDirectory
20      */
21     private $dir;
22     /**
23      * child one
24      *
25      * @type  \PHPUnit_Framework_MockObject_MockObject
26      */
27     private $mockChild1;
28     /**
29      * child two
30      *
31      * @type  \PHPUnit_Framework_MockObject_MockObject
32      */
33     private $mockChild2;
34
35     /**
36      * set up test environment
37      */
38     public function setUp()
39     {
40         $this->dir = new vfsStreamDirectory('foo');
41         $this->mockChild1 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
42         $this->mockChild1->expects($this->any())
43                          ->method('getName')
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())
48                          ->method('getName')
49                          ->will($this->returnValue('baz'));
50         $this->dir->addChild($this->mockChild2);
51     }
52
53     /**
54      * clean up test environment
55      */
56     public function tearDown()
57     {
58         vfsStream::enableDotfiles();
59     }
60
61     /**
62      * @return  array
63      */
64     public function provideSwitchWithExpectations()
65     {
66         return array(array(function() { vfsStream::disableDotfiles(); },
67                            array()
68                      ),
69                      array(function() { vfsStream::enableDotfiles(); },
70                            array('.', '..')
71                      )
72         );
73     }
74
75     private function getDirName($dir)
76     {
77         if (is_string($dir)) {
78             return $dir;
79         }
80
81
82         return $dir->getName();
83     }
84
85     /**
86      * @param  \Closure  $dotFilesSwitch
87      * @param  array     $dirNames
88      * @test
89      * @dataProvider  provideSwitchWithExpectations
90      */
91     public function iteration(\Closure $dotFilesSwitch, array $dirs)
92     {
93         $dirs[] = $this->mockChild1;
94         $dirs[] = $this->mockChild2;
95         $dotFilesSwitch();
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());
102             }
103
104             $dirIterator->next();
105         }
106
107         $this->assertFalse($dirIterator->valid());
108         $this->assertNull($dirIterator->key());
109         $this->assertNull($dirIterator->current());
110     }
111 }