public function testEnsuresSizeIsConsistent()
 {
     $h = fopen('php://temp', 'w+');
     $this->assertEquals(3, fwrite($h, 'foo'));
     $stream = new Stream($h);
     $this->assertEquals(3, $stream->getSize());
     $this->assertEquals(4, $stream->write('test'));
     $this->assertEquals(7, $stream->getSize());
     $this->assertEquals(7, $stream->getSize());
     $stream->close();
 }
Esempio n. 2
0
 public function testCloseClearProperties()
 {
     $handle = fopen('php://temp', 'r+');
     $stream = new Stream($handle);
     $stream->close();
     $this->assertEmpty($stream->getMetadata());
     $this->assertFalse($stream->isSeekable());
     $this->assertFalse($stream->isReadable());
     $this->assertFalse($stream->isWritable());
     $this->assertNull($stream->getSize());
 }
Esempio n. 3
0
 public function testCanDetachStream()
 {
     $r = fopen('php://temp', 'w+');
     $stream = new Stream($r);
     $this->assertTrue($stream->isReadable());
     $this->assertSame($r, $stream->detach());
     $this->assertNull($stream->detach());
     $this->assertFalse($stream->isReadable());
     $this->assertSame('', $stream->read(10));
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->write('foo'));
     $this->assertFalse($stream->isSeekable());
     $this->assertFalse($stream->seek(10));
     $this->assertFalse($stream->tell());
     $this->assertFalse($stream->eof());
     $this->assertNull($stream->getSize());
     $this->assertSame('', (string) $stream);
     $this->assertSame('', $stream->getContents());
     $stream->close();
 }