WritableStreamTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace React\Tests\Stream;
  3. use React\Stream\ReadableStream;
  4. use React\Stream\WritableStream;
  5. /**
  6. * @covers React\Stream\WritableStream
  7. */
  8. class WritableStreamTest extends TestCase
  9. {
  10. /** @test */
  11. public function pipingStuffIntoItShouldWorkButDoNothing()
  12. {
  13. $readable = new ReadableStream();
  14. $through = new WritableStream();
  15. $readable->pipe($through);
  16. $readable->emit('data', array('foo'));
  17. }
  18. /** @test */
  19. public function endShouldCloseTheStream()
  20. {
  21. $through = new WritableStream();
  22. $through->on('data', $this->expectCallableNever());
  23. $through->end();
  24. $this->assertFalse($through->isWritable());
  25. }
  26. /** @test */
  27. public function endShouldWriteDataBeforeClosing()
  28. {
  29. $through = $this->getMock('React\Stream\WritableStream', array('write'));
  30. $through
  31. ->expects($this->once())
  32. ->method('write')
  33. ->with('foo');
  34. $through->end('foo');
  35. $this->assertFalse($through->isWritable());
  36. }
  37. /** @test */
  38. public function itShouldBeWritableByDefault()
  39. {
  40. $through = new WritableStream();
  41. $this->assertTrue($through->isWritable());
  42. }
  43. /** @test */
  44. public function closeShouldClose()
  45. {
  46. $through = new WritableStream();
  47. $through->close();
  48. $this->assertFalse($through->isWritable());
  49. }
  50. /** @test */
  51. public function doubleCloseShouldWork()
  52. {
  53. $through = new WritableStream();
  54. $through->close();
  55. $through->close();
  56. $this->assertFalse($through->isWritable());
  57. }
  58. }