public function testStopsCopyToSteamWhenReadFailsWithMaxLen() { $s1 = Stream::factory('foobaz'); $s1 = FnStream::decorate($s1, ['read' => function () { return ''; }]); $s2 = Stream::factory(''); Utils::copyToStream($s1, $s2, 10); $this->assertEquals('', (string) $s2); }
public function testDecoratesWithCustomizations() { $called = false; $a = Stream::factory('foo'); $b = FnStream::decorate($a, ['read' => function ($len) use(&$called, $a) { $called = true; return $a->read($len); }]); $this->assertEquals('foo', $b->read(3)); $this->assertTrue($called); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Buffer must be readable and writable */ public function testValidatesWritableBuffer() { new AsyncReadStream(FnStream::decorate(Stream::factory(), ['isWritable' => function () { return false; }])); }
public function testRetriesWhenBodyCanBeRewound() { $callHandler = $called = false; $res = CurlFactory::createResponse(function () use(&$callHandler) { $callHandler = true; return ['status' => 200]; }, ['body' => FnStream::decorate(Stream::factory('test'), ['seek' => function () use(&$called) { $called = true; return true; }])], [], [], null); $this->assertTrue($callHandler); $this->assertTrue($called); $this->assertEquals('200', $res['status']); }