PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/php/sdk/third_party/vfsstream/vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php

https://github.com/theosp/google_appengine
PHP | 89 lines | 53 code | 4 blank | 32 comment | 0 complexity | c18d7b8a781fcc5374b5447c47dc7754 MD5 | raw file
  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. * @test
  33. * @expectedException \InvalidArgumentException
  34. */
  35. public function constructWithNonStreamResourceThrowsInvalidArgumentException()
  36. {
  37. new vfsStreamPrintVisitor(xml_parser_create());
  38. }
  39. /**
  40. * @test
  41. */
  42. public function visitFileWritesFileNameToStream()
  43. {
  44. $output = vfsStream::newFile('foo.txt')
  45. ->at(vfsStream::setup());
  46. $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
  47. $this->assertSame($printVisitor,
  48. $printVisitor->visitFile(vfsStream::newFile('bar.txt'))
  49. );
  50. $this->assertEquals("- bar.txt\n", $output->getContent());
  51. }
  52. /**
  53. * @test
  54. */
  55. public function visitDirectoryWritesDirectoryNameToStream()
  56. {
  57. $output = vfsStream::newFile('foo.txt')
  58. ->at(vfsStream::setup());
  59. $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
  60. $this->assertSame($printVisitor,
  61. $printVisitor->visitDirectory(vfsStream::newDirectory('baz'))
  62. );
  63. $this->assertEquals("- baz\n", $output->getContent());
  64. }
  65. /**
  66. * @test
  67. */
  68. public function visitRecursiveDirectoryStructure()
  69. {
  70. $root = vfsStream::setup('root',
  71. null,
  72. array('test' => array('foo' => array('test.txt' => 'hello'),
  73. 'baz.txt' => 'world'
  74. ),
  75. 'foo.txt' => ''
  76. )
  77. );
  78. $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
  79. $this->assertSame($printVisitor,
  80. $printVisitor->visitDirectory($root)
  81. );
  82. $this->assertEquals("- root\n - test\n - foo\n - test.txt\n - baz.txt\n - foo.txt\n", file_get_contents('vfs://root/foo.txt'));
  83. }
  84. }
  85. ?>