FileReaderTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests;
  12. use org\bovigo\vfs\vfsStream;
  13. use PhpCsFixer\FileReader;
  14. /**
  15. * @author ntzm
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\FileReader
  20. */
  21. final class FileReaderTest extends TestCase
  22. {
  23. public static function tearDownAfterClass()
  24. {
  25. parent::tearDownAfterClass();
  26. // testReadStdinCaches registers a stream wrapper for php so we can mock
  27. // php://stdin. Restore the original stream wrapper after this class so
  28. // we don't affect other tests running after it
  29. stream_wrapper_restore('php');
  30. }
  31. public function testCreateSingleton()
  32. {
  33. $instance = FileReader::createSingleton();
  34. $this->assertInstanceOf('PhpCsFixer\FileReader', $instance);
  35. $this->assertSame($instance, FileReader::createSingleton());
  36. }
  37. public function testRead()
  38. {
  39. $fs = vfsStream::setup('root', null, [
  40. 'foo.php' => '<?php echo "hi";',
  41. ]);
  42. $reader = new FileReader();
  43. $this->assertSame('<?php echo "hi";', $reader->read($fs->url().'/foo.php'));
  44. }
  45. public function testReadStdinCaches()
  46. {
  47. $reader = new FileReader();
  48. stream_wrapper_unregister('php');
  49. stream_wrapper_register('php', 'PhpCsFixer\Tests\Fixtures\Test\FileReaderTest\StdinFakeStream');
  50. $this->assertSame('<?php echo "foo";', $reader->read('php://stdin'));
  51. $this->assertSame('<?php echo "foo";', $reader->read('php://stdin'));
  52. }
  53. }