Esempio n. 1
0
 public function testCanSeekToReadBytes()
 {
     $this->assertEquals('te', $this->body->read(2));
     $this->body->seek(0);
     $this->assertEquals('test', $this->body->read(4));
     $this->assertEquals(4, $this->body->tell());
     $this->body->seek(2);
     $this->assertEquals(2, $this->body->tell());
     $this->body->seek(2, SEEK_CUR);
     $this->assertEquals(4, $this->body->tell());
     $this->assertEquals('ing', $this->body->read(3));
 }
 public function testCanSeekToReadBytesWithPartialBodyReturned()
 {
     $stream = fopen('php://temp', 'r+');
     fwrite($stream, 'testing');
     fseek($stream, 0);
     $this->decorated = $this->getMockBuilder('\\GuzzleHttp\\Psr7\\Stream')->setConstructorArgs([$stream])->setMethods(['read'])->getMock();
     $this->decorated->expects($this->exactly(2))->method('read')->willReturnCallback(function ($length) use($stream) {
         return fread($stream, 2);
     });
     $this->body = new CachingStream($this->decorated);
     $this->assertEquals(0, $this->body->tell());
     $this->body->seek(4, SEEK_SET);
     $this->assertEquals(4, $this->body->tell());
     $this->body->seek(0);
     $this->assertEquals('test', $this->body->read(4));
 }