You are here

public function StreamDecoratorTraitTest::testCatchesExceptionsWhenCastingToString in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/guzzlehttp/psr7/tests/StreamDecoratorTraitTest.php \GuzzleHttp\Tests\Psr7\StreamDecoratorTraitTest::testCatchesExceptionsWhenCastingToString()

File

vendor/guzzlehttp/psr7/tests/StreamDecoratorTraitTest.php, line 31

Class

StreamDecoratorTraitTest
@covers GuzzleHttp\Psr7\StreamDecoratorTrait

Namespace

GuzzleHttp\Tests\Psr7

Code

public function testCatchesExceptionsWhenCastingToString() {
  $s = $this
    ->getMockBuilder('Psr\\Http\\Message\\StreamInterface')
    ->setMethods([
    'read',
  ])
    ->getMockForAbstractClass();
  $s
    ->expects($this
    ->once())
    ->method('read')
    ->will($this
    ->throwException(new \Exception('foo')));
  $msg = '';
  set_error_handler(function ($errNo, $str) use (&$msg) {
    $msg = $str;
  });
  echo new Str($s);
  restore_error_handler();
  $this
    ->assertContains('foo', $msg);
}