Ejemplo n.º 1
0
 public function testCanDetachStream()
 {
     $r = fopen('php://temp', 'w+');
     $stream = new Stream($r);
     $stream->write('foo');
     $this->assertTrue($stream->isReadable());
     $this->assertSame($r, $stream->detach());
     $stream->detach();
     $this->assertFalse($stream->isReadable());
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->isSeekable());
     $self = $this;
     $throws = function ($fn) use($stream, $self) {
         try {
             $fn($stream);
             $self->fail();
         } catch (\Exception $e) {
         }
     };
     $throws(function ($stream) {
         $stream->read(10);
     });
     $throws(function ($stream) {
         $stream->write('bar');
     });
     $throws(function ($stream) {
         $stream->seek(10);
     });
     $throws(function ($stream) {
         $stream->tell();
     });
     $throws(function ($stream) {
         $stream->eof();
     });
     $throws(function ($stream) {
         $stream->getSize();
     });
     $throws(function ($stream) {
         $stream->getContents();
     });
     $this->assertSame('', (string) $stream);
     $stream->close();
 }