MultipleStreamOutputTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup\Model\Cron;
  7. class MultipleStreamOutputTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var MultipleStreamOutput
  11. */
  12. private $multipleStreamOutput;
  13. public function setUp()
  14. {
  15. $this->multipleStreamOutput = new MultipleStreamOutput(
  16. [
  17. fopen(__DIR__ . '/_files/a.txt', 'a+'),
  18. fopen(__DIR__ . '/_files/b.txt', 'a+')
  19. ]
  20. );
  21. }
  22. public function tearDown()
  23. {
  24. file_put_contents(__DIR__ . '/_files/a.txt', '');
  25. file_put_contents(__DIR__ . '/_files/b.txt', '');
  26. }
  27. /**
  28. * @expectedException \InvalidArgumentException
  29. * @expectedExceptionMessage The StreamOutput class needs a stream as its first argument
  30. */
  31. public function testCreateException()
  32. {
  33. $this->multipleStreamOutput = new MultipleStreamOutput(['a', 'b']);
  34. }
  35. public function testWriteln()
  36. {
  37. $this->multipleStreamOutput->writeln('Hello world');
  38. $this->assertEquals('Hello world' . PHP_EOL, file_get_contents(__DIR__ . '/_files/a.txt'));
  39. $this->assertEquals('Hello world' . PHP_EOL, file_get_contents(__DIR__ . '/_files/b.txt'));
  40. }
  41. public function testWrite()
  42. {
  43. $this->multipleStreamOutput->write('Hello world');
  44. $this->assertEquals('Hello world', file_get_contents(__DIR__ . '/_files/a.txt'));
  45. $this->assertEquals('Hello world', file_get_contents(__DIR__ . '/_files/b.txt'));
  46. }
  47. }