Version 1
[yaffs-website] / vendor / mikey179 / vfsStream / src / test / php / org / bovigo / vfs / visitor / vfsStreamStructureVisitorTestCase.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\visitor;
11 use org\bovigo\vfs\vfsStream;
12 /**
13  * Test for org\bovigo\vfs\visitor\vfsStreamStructureVisitor.
14  *
15  * @since  0.10.0
16  * @see    https://github.com/mikey179/vfsStream/issues/10
17  * @group  issue_10
18  */
19 class vfsStreamStructureVisitorTestCase extends \PHPUnit_Framework_TestCase
20 {
21     /**
22      * @test
23      */
24     public function visitFileCreatesStructureForFile()
25     {
26         $structureVisitor = new vfsStreamStructureVisitor();
27         $this->assertEquals(array('foo.txt' => 'test'),
28                             $structureVisitor->visitFile(vfsStream::newFile('foo.txt')
29                                                                   ->withContent('test')
30                                                )
31                                              ->getStructure()
32         );
33     }
34
35     /**
36      * @test
37      */
38     public function visitFileCreatesStructureForBlock()
39     {
40         $structureVisitor = new vfsStreamStructureVisitor();
41         $this->assertEquals(array('[foo]' => 'test'),
42                             $structureVisitor->visitBlockDevice(vfsStream::newBlock('foo')
43                                                                   ->withContent('test')
44                                                )
45                                              ->getStructure()
46         );
47     }
48
49     /**
50      * @test
51      */
52     public function visitDirectoryCreatesStructureForDirectory()
53     {
54         $structureVisitor = new vfsStreamStructureVisitor();
55         $this->assertEquals(array('baz' => array()),
56                             $structureVisitor->visitDirectory(vfsStream::newDirectory('baz'))
57                                              ->getStructure()
58         );
59     }
60
61     /**
62      * @test
63      */
64     public function visitRecursiveDirectoryStructure()
65     {
66         $root         = vfsStream::setup('root',
67                                          null,
68                                          array('test' => array('foo'     => array('test.txt' => 'hello'),
69                                                                'baz.txt' => 'world'
70                                                          ),
71                                                'foo.txt' => ''
72                                          )
73                         );
74         $structureVisitor = new vfsStreamStructureVisitor();
75         $this->assertEquals(array('root' => array('test' => array('foo'     => array('test.txt' => 'hello'),
76                                                                   'baz.txt' => 'world'
77                                                                                ),
78                                                                   'foo.txt' => ''
79                                             ),
80                             ),
81                             $structureVisitor->visitDirectory($root)
82                                              ->getStructure()
83         );
84     }
85 }