You are here

class vfsStreamPrintVisitorTestCase in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php \org\bovigo\vfs\visitor\vfsStreamPrintVisitorTestCase

Test for org\bovigo\vfs\visitor\vfsStreamPrintVisitor.

@since 0.10.0 @group issue_10

Hierarchy

Expanded class hierarchy of vfsStreamPrintVisitorTestCase

See also

https://github.com/mikey179/vfsStream/issues/10

File

vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php, line 21

Namespace

org\bovigo\vfs\visitor
View source
class vfsStreamPrintVisitorTestCase extends \PHPUnit_Framework_TestCase {

  /**
   * @test
   * @expectedException  \InvalidArgumentException
   */
  public function constructWithNonResourceThrowsInvalidArgumentException() {
    new vfsStreamPrintVisitor('invalid');
  }

  /**
   * @test
   * @expectedException  \InvalidArgumentException
   */
  public function constructWithNonStreamResourceThrowsInvalidArgumentException() {
    new vfsStreamPrintVisitor(xml_parser_create());
  }

  /**
   * @test
   */
  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());
  }

  /**
   * @test
   */
  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());
  }

  /**
   * @test
   */
  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());
  }

  /**
   * @test
   */
  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'));
  }

}

Members