Version 1
[yaffs-website] / vendor / mikey179 / vfsStream / src / test / php / org / bovigo / vfs / visitor / vfsStreamPrintVisitorTestCase.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 use org\bovigo\vfs\vfsStreamDirectory;
13 use org\bovigo\vfs\vfsStreamFile;
14 /**
15  * Test for org\bovigo\vfs\visitor\vfsStreamPrintVisitor.
16  *
17  * @since  0.10.0
18  * @see    https://github.com/mikey179/vfsStream/issues/10
19  * @group  issue_10
20  */
21 class vfsStreamPrintVisitorTestCase extends \PHPUnit_Framework_TestCase
22 {
23     /**
24      * @test
25      * @expectedException  \InvalidArgumentException
26      */
27     public function constructWithNonResourceThrowsInvalidArgumentException()
28     {
29         new vfsStreamPrintVisitor('invalid');
30     }
31
32     /**
33      * @test
34      * @expectedException  \InvalidArgumentException
35      */
36     public function constructWithNonStreamResourceThrowsInvalidArgumentException()
37     {
38         new vfsStreamPrintVisitor(xml_parser_create());
39     }
40
41     /**
42      * @test
43      */
44     public function visitFileWritesFileNameToStream()
45     {
46         $output       = vfsStream::newFile('foo.txt')
47                                        ->at(vfsStream::setup());
48         $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
49         $this->assertSame($printVisitor,
50                           $printVisitor->visitFile(vfsStream::newFile('bar.txt'))
51         );
52         $this->assertEquals("- bar.txt\n", $output->getContent());
53     }
54
55     /**
56      * @test
57      */
58     public function visitFileWritesBlockDeviceToStream()
59     {
60         $output       = vfsStream::newFile('foo.txt')
61                                        ->at(vfsStream::setup());
62         $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
63         $this->assertSame($printVisitor,
64                           $printVisitor->visitBlockDevice(vfsStream::newBlock('bar'))
65         );
66         $this->assertEquals("- [bar]\n", $output->getContent());
67     }
68
69     /**
70      * @test
71      */
72     public function visitDirectoryWritesDirectoryNameToStream()
73     {
74         $output       = vfsStream::newFile('foo.txt')
75                                        ->at(vfsStream::setup());
76         $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
77         $this->assertSame($printVisitor,
78                           $printVisitor->visitDirectory(vfsStream::newDirectory('baz'))
79         );
80         $this->assertEquals("- baz\n", $output->getContent());
81     }
82
83     /**
84      * @test
85      */
86     public function visitRecursiveDirectoryStructure()
87     {
88         $root         = vfsStream::setup('root',
89                                          null,
90                                          array('test' => array('foo'     => array('test.txt' => 'hello'),
91                                                                'baz.txt' => 'world'
92                                                            ),
93                                                'foo.txt' => ''
94                                          )
95                         );
96         $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
97         $this->assertSame($printVisitor,
98                           $printVisitor->visitDirectory($root)
99         );
100         $this->assertEquals("- root\n  - test\n    - foo\n      - test.txt\n    - baz.txt\n  - foo.txt\n", file_get_contents('vfs://root/foo.txt'));
101     }
102 }