You are here

public function StreamTest::testCanDetachStream in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/psr7/tests/StreamTest.php \GuzzleHttp\Tests\Psr7\StreamTest::testCanDetachStream()

File

vendor/guzzlehttp/psr7/tests/StreamTest.php, line 111

Class

StreamTest
@covers GuzzleHttp\Psr7\Stream

Namespace

GuzzleHttp\Tests\Psr7

Code

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());
  $throws = function (callable $fn) use ($stream) {
    try {
      $fn($stream);
      $this
        ->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();
}