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\visitor;
11 use org\bovigo\vfs\vfsStream;
12 use org\bovigo\vfs\vfsStreamDirectory;
13 use org\bovigo\vfs\vfsStreamFile;
15 * Test for org\bovigo\vfs\visitor\vfsStreamPrintVisitor.
18 * @see https://github.com/mikey179/vfsStream/issues/10
21 class vfsStreamPrintVisitorTestCase extends \PHPUnit_Framework_TestCase
25 * @expectedException \InvalidArgumentException
27 public function constructWithNonResourceThrowsInvalidArgumentException()
29 new vfsStreamPrintVisitor('invalid');
34 * @expectedException \InvalidArgumentException
36 public function constructWithNonStreamResourceThrowsInvalidArgumentException()
38 new vfsStreamPrintVisitor(xml_parser_create());
44 public function visitFileWritesFileNameToStream()
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'))
52 $this->assertEquals("- bar.txt\n", $output->getContent());
58 public function visitFileWritesBlockDeviceToStream()
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'))
66 $this->assertEquals("- [bar]\n", $output->getContent());
72 public function visitDirectoryWritesDirectoryNameToStream()
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'))
80 $this->assertEquals("- baz\n", $output->getContent());
86 public function visitRecursiveDirectoryStructure()
88 $root = vfsStream::setup('root',
90 array('test' => array('foo' => array('test.txt' => 'hello'),
96 $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
97 $this->assertSame($printVisitor,
98 $printVisitor->visitDirectory($root)
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'));