public function testConstructorDoesNotReadStreamBody() { $streamIsRead = false; $body = FnStream::decorate(new Stream(fopen('php://temp', 'r+')), ['__toString' => function () use(&$streamIsRead) { $streamIsRead = true; return ''; }]); $response = new Response(200, [], $body); $this->assertFalse($streamIsRead); $this->assertSame($body, $response->getBody()); }
public function testDecoratesWithCustomizations() { $called = false; $body = 'foo'; $stream = fopen('php://temp', 'r+'); fwrite($stream, $body); fseek($stream, 0); $stream1 = new Stream($stream); $stream2 = FnStream::decorate($stream1, ['read' => function ($len) use(&$called, $stream1) { $called = true; return $stream1->read($len); }]); $this->assertEquals('foo', $stream2->read(3)); $this->assertTrue($called); }
public function testStopsCopyToSteamWhenReadFailsWithMaxLen() { $body = 'foobaz'; $stream = fopen('php://temp', 'r+'); fwrite($stream, $body); fseek($stream, 0); $s1 = new Stream($stream); $s1 = FnStream::decorate($s1, ['read' => function () { return ''; }]); $s2 = new Stream(fopen('php://temp', 'r+')); Util::copyToStream($s1, $s2, 10); $this->assertEquals('', (string) $s2); }