public function testDetach() { $handle = $this->stream->detach(); $this->assertTrue(is_resource($handle)); $meta = stream_get_meta_data($handle); if ($meta['mode'] != 'w') { $this->assertEquals('foobar', stream_get_contents($handle, -1, 0)); } // after detatching the stream object is in an unusable state but this // should not produce any error on further method calls $this->assertEquals('', $this->stream->__toString()); $this->assertEquals(null, $this->stream->close()); $this->assertEquals(null, $this->stream->detach()); $this->assertEquals(null, $this->stream->getSize()); $this->assertEquals(false, $this->stream->tell()); // after detaching eof returns always true to not enter any while(!eof) $this->assertEquals(true, $this->stream->eof()); $this->assertEquals(false, $this->stream->isSeekable()); $this->assertEquals(false, $this->stream->seek(0)); $this->assertEquals(false, $this->stream->isWritable()); $this->assertEquals(false, $this->stream->write('foo')); $this->assertEquals(false, $this->stream->isReadable()); $this->assertEquals(false, $this->stream->read(2)); $this->assertEquals(null, $this->stream->getContents()); }
public function __construct(StreamInterface $stream) { $this->data = ''; $this->length = $stream->getSize(); $this->source = $stream; }