FailureExampleTestCase.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\example;
  11. use org\bovigo\vfs\vfsStream;
  12. require_once 'FailureExample.php';
  13. /**
  14. * Test case for class FailureExample.
  15. */
  16. class FailureExampleTestCase extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * root directory
  20. *
  21. * @type vfsStreamDirectory
  22. */
  23. protected $root;
  24. /**
  25. * set up test environmemt
  26. */
  27. public function setUp()
  28. {
  29. $this->root = vfsStream::setup('exampleDir');
  30. }
  31. /**
  32. * @test
  33. */
  34. public function returnsOkOnNoFailure()
  35. {
  36. $example = new FailureExample(vfsStream::url('exampleDir/test.txt'));
  37. $this->assertSame('ok', $example->writeData('testdata'));
  38. $this->assertTrue($this->root->hasChild('test.txt'));
  39. $this->assertSame('testdata', $this->root->getChild('test.txt')->getContent());
  40. }
  41. /**
  42. * @test
  43. */
  44. public function returnsErrorMessageIfWritingToFileFails()
  45. {
  46. $file = vfsStream::newFile('test.txt', 0000)
  47. ->withContent('notoverwritten')
  48. ->at($this->root);
  49. $example = new FailureExample(vfsStream::url('exampleDir/test.txt'));
  50. $this->assertSame('could not write data', $example->writeData('testdata'));
  51. $this->assertTrue($this->root->hasChild('test.txt'));
  52. $this->assertSame('notoverwritten', $this->root->getChild('test.txt')->getContent());
  53. }
  54. }
  55. ?>