|
2 | 2 |
|
3 | 3 | namespace React\Tests\Http\Message; |
4 | 4 |
|
| 5 | +use React\Http\Io\HttpBodyStream; |
5 | 6 | use React\Http\Message\Response; |
6 | 7 | use React\Stream\ThroughStream; |
7 | 8 | use React\Tests\Http\TestCase; |
8 | 9 |
|
9 | 10 | class ResponseTest extends TestCase |
10 | 11 | { |
11 | | - public function testResponseBodyWillBeHttpBodyStream() |
12 | | - { |
13 | | - $response = new Response(200, array(), new ThroughStream()); |
14 | | - $this->assertInstanceOf('React\Http\Io\HttpBodyStream', $response->getBody()); |
15 | | - } |
16 | 12 |
|
17 | 13 | public function testStringBodyWillBePsr7Stream() |
18 | 14 | { |
19 | 15 | $response = new Response(200, array(), 'hello'); |
20 | 16 | $this->assertInstanceOf('RingCentral\Psr7\Stream', $response->getBody()); |
21 | 17 | } |
| 18 | + |
| 19 | + public function testConstructWithStreamingBodyWillReturnReadableBodyStream() |
| 20 | + { |
| 21 | + $response = new Response(200, array(), new ThroughStream()); |
| 22 | + |
| 23 | + $body = $response->getBody(); |
| 24 | + $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $body); |
| 25 | + $this->assertInstanceof('React\Stream\ReadableStreamInterface', $body); |
| 26 | + $this->assertInstanceOf('React\Http\Io\HttpBodyStream', $body); |
| 27 | + $this->assertNull($body->getSize()); |
| 28 | + } |
| 29 | + |
| 30 | + public function testConstructWithHttpBodyStreamReturnsBodyAsIs() |
| 31 | + { |
| 32 | + $response = new Response( |
| 33 | + 200, |
| 34 | + array(), |
| 35 | + $body = new HttpBodyStream(new ThroughStream(), 100) |
| 36 | + ); |
| 37 | + |
| 38 | + $this->assertSame($body, $response->getBody()); |
| 39 | + } |
| 40 | + |
| 41 | + public function testFloatBodyWillThrow() |
| 42 | + { |
| 43 | + $this->setExpectedException('InvalidArgumentException'); |
| 44 | + new Response(200, array(), 1.0); |
| 45 | + } |
| 46 | + |
| 47 | + public function testResourceBodyWillThrow() |
| 48 | + { |
| 49 | + $this->setExpectedException('InvalidArgumentException'); |
| 50 | + new Response(200, array(), tmpfile()); |
| 51 | + } |
22 | 52 | } |
0 commit comments