|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace React\Tests\Http\Io; |
| 4 | + |
| 5 | +use React\Http\Io\EmptyBodyStream; |
| 6 | +use React\Tests\Http\TestCase; |
| 7 | + |
| 8 | +class EmptyBodyStreamTest extends TestCase |
| 9 | +{ |
| 10 | + private $input; |
| 11 | + private $bodyStream; |
| 12 | + |
| 13 | + public function setUp() |
| 14 | + { |
| 15 | + $this->bodyStream = new EmptyBodyStream(); |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * @doesNotPerformAssertions |
| 20 | + */ |
| 21 | + public function testPauseIsNoop() |
| 22 | + { |
| 23 | + $this->bodyStream->pause(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @doesNotPerformAssertions |
| 28 | + */ |
| 29 | + public function testResumeIsNoop() |
| 30 | + { |
| 31 | + $this->bodyStream->resume(); |
| 32 | + } |
| 33 | + |
| 34 | + public function testPipeStreamReturnsDestinationStream() |
| 35 | + { |
| 36 | + $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); |
| 37 | + |
| 38 | + $ret = $this->bodyStream->pipe($dest); |
| 39 | + |
| 40 | + $this->assertSame($dest, $ret); |
| 41 | + } |
| 42 | + |
| 43 | + public function testToStringReturnsEmptyString() |
| 44 | + { |
| 45 | + $this->assertEquals('', $this->bodyStream->__toString()); |
| 46 | + } |
| 47 | + |
| 48 | + public function testDetachReturnsNull() |
| 49 | + { |
| 50 | + $this->assertNull($this->bodyStream->detach()); |
| 51 | + } |
| 52 | + |
| 53 | + public function testGetSizeReturnsZero() |
| 54 | + { |
| 55 | + $this->assertSame(0, $this->bodyStream->getSize()); |
| 56 | + } |
| 57 | + |
| 58 | + public function testCloseTwiceEmitsCloseEventAndClearsListeners() |
| 59 | + { |
| 60 | + $this->bodyStream->on('close', $this->expectCallableOnce()); |
| 61 | + |
| 62 | + $this->bodyStream->close(); |
| 63 | + $this->bodyStream->close(); |
| 64 | + |
| 65 | + $this->assertEquals(array(), $this->bodyStream->listeners('close')); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @expectedException BadMethodCallException |
| 70 | + */ |
| 71 | + public function testTell() |
| 72 | + { |
| 73 | + $this->bodyStream->tell(); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @expectedException BadMethodCallException |
| 78 | + */ |
| 79 | + public function testEof() |
| 80 | + { |
| 81 | + $this->bodyStream->eof(); |
| 82 | + } |
| 83 | + |
| 84 | + public function testIsSeekable() |
| 85 | + { |
| 86 | + $this->assertFalse($this->bodyStream->isSeekable()); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @expectedException BadMethodCallException |
| 91 | + */ |
| 92 | + public function testWrite() |
| 93 | + { |
| 94 | + $this->bodyStream->write(''); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * @expectedException BadMethodCallException |
| 99 | + */ |
| 100 | + public function testRead() |
| 101 | + { |
| 102 | + $this->bodyStream->read(1); |
| 103 | + } |
| 104 | + |
| 105 | + public function testGetContentsReturnsEmpy() |
| 106 | + { |
| 107 | + $this->assertEquals('', $this->bodyStream->getContents()); |
| 108 | + } |
| 109 | + |
| 110 | + public function testGetMetaDataWithoutKeyReturnsEmptyArray() |
| 111 | + { |
| 112 | + $this->assertSame(array(), $this->bodyStream->getMetadata()); |
| 113 | + } |
| 114 | + |
| 115 | + public function testGetMetaDataWithKeyReturnsNull() |
| 116 | + { |
| 117 | + $this->assertNull($this->bodyStream->getMetadata('anything')); |
| 118 | + } |
| 119 | + |
| 120 | + public function testIsReadableReturnsTrueWhenNotClosed() |
| 121 | + { |
| 122 | + $this->assertTrue($this->bodyStream->isReadable()); |
| 123 | + } |
| 124 | + |
| 125 | + public function testIsReadableReturnsFalseWhenAlreadyClosed() |
| 126 | + { |
| 127 | + $this->bodyStream->close(); |
| 128 | + |
| 129 | + $this->assertFalse($this->bodyStream->isReadable()); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * @expectedException BadMethodCallException |
| 134 | + */ |
| 135 | + public function testSeek() |
| 136 | + { |
| 137 | + $this->bodyStream->seek(''); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * @expectedException BadMethodCallException |
| 142 | + */ |
| 143 | + public function testRewind() |
| 144 | + { |
| 145 | + $this->bodyStream->rewind(); |
| 146 | + } |
| 147 | + |
| 148 | + public function testIsWriteable() |
| 149 | + { |
| 150 | + $this->assertFalse($this->bodyStream->isWritable()); |
| 151 | + } |
| 152 | +} |
0 commit comments