vfsStreamPrintVisitorTestCase.php in Zircon Profile 8.0
File
vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php
View source
<?php
namespace org\bovigo\vfs\visitor;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use org\bovigo\vfs\vfsStreamFile;
class vfsStreamPrintVisitorTestCase extends \PHPUnit_Framework_TestCase {
public function constructWithNonResourceThrowsInvalidArgumentException() {
new vfsStreamPrintVisitor('invalid');
}
public function constructWithNonStreamResourceThrowsInvalidArgumentException() {
new vfsStreamPrintVisitor(xml_parser_create());
}
public function visitFileWritesFileNameToStream() {
$output = vfsStream::newFile('foo.txt')
->at(vfsStream::setup());
$printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
$this
->assertSame($printVisitor, $printVisitor
->visitFile(vfsStream::newFile('bar.txt')));
$this
->assertEquals("- bar.txt\n", $output
->getContent());
}
public function visitFileWritesBlockDeviceToStream() {
$output = vfsStream::newFile('foo.txt')
->at(vfsStream::setup());
$printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
$this
->assertSame($printVisitor, $printVisitor
->visitBlockDevice(vfsStream::newBlock('bar')));
$this
->assertEquals("- [bar]\n", $output
->getContent());
}
public function visitDirectoryWritesDirectoryNameToStream() {
$output = vfsStream::newFile('foo.txt')
->at(vfsStream::setup());
$printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
$this
->assertSame($printVisitor, $printVisitor
->visitDirectory(vfsStream::newDirectory('baz')));
$this
->assertEquals("- baz\n", $output
->getContent());
}
public function visitRecursiveDirectoryStructure() {
$root = vfsStream::setup('root', null, array(
'test' => array(
'foo' => array(
'test.txt' => 'hello',
),
'baz.txt' => 'world',
),
'foo.txt' => '',
));
$printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
$this
->assertSame($printVisitor, $printVisitor
->visitDirectory($root));
$this
->assertEquals("- root\n - test\n - foo\n - test.txt\n - baz.txt\n - foo.txt\n", file_get_contents('vfs://root/foo.txt'));
}
}