Example #1
0
 public function testCanDetachAndAttachStream()
 {
     $r = fopen('php://temp', 'w+');
     $stream = new Stream($r);
     $stream->write('foo');
     $this->assertTrue($stream->isReadable());
     $this->assertSame($r, $stream->detach());
     $this->assertNull($stream->detach());
     $this->assertFalse($stream->isReadable());
     $this->assertFalse($stream->read(10));
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->write('bar'));
     $this->assertFalse($stream->isSeekable());
     $this->assertFalse($stream->seek(10));
     $this->assertFalse($stream->tell());
     $this->assertTrue($stream->eof());
     $this->assertNull($stream->getSize());
     $this->assertSame('', (string) $stream);
     $this->assertSame('', $stream->getContents());
     $stream->attach($r);
     $stream->seek(0);
     $this->assertEquals('foo', $stream->getContents());
     $this->assertTrue($stream->isReadable());
     $this->assertTrue($stream->isWritable());
     $this->assertTrue($stream->isSeekable());
     $stream->close();
 }
 public function testProvidesStreamPosition()
 {
     $handle = fopen('php://temp', 'w+');
     $stream = new Stream($handle);
     $this->assertEquals(0, $stream->tell());
     $stream->write('foo');
     $this->assertEquals(3, $stream->tell());
     $stream->seek(1);
     $this->assertEquals(1, $stream->tell());
     $this->assertSame(ftell($handle), $stream->tell());
     $stream->close();
 }