testCase = $testCase; } /** * @param callable $callable * @param string|object $expected [optional] * @return $this */ public function trap(callable $callable, $expected = null) { $this->trapped = null; try { call_user_func($callable); } catch (Exception $e) { $this->trapped = $e; if ($expected !== null) { $className = is_string($expected) ? $expected : get_class($expected); $this->testCase->assertInstanceOf($className, $e); } } return $this; } /** * @param $expectedException * @return $this */ public function exception($expectedException) { $this->testCase->assertInstanceOf(Exception::class, $this->trapped); /* @see PHPUnit_Framework_TestCase::runTest */ $this->testCase->assertThat( $this->trapped, new PHPUnit_Framework_Constraint_Exception( $expectedException ) ); return $this; } /** * @param $expectedExceptionMessage * @return $this */ public function message($expectedExceptionMessage) { $this->testCase->assertInstanceOf(Exception::class, $this->trapped); /* @see PHPUnit_Framework_TestCase::runTest */ $this->testCase->assertThat( $this->trapped, new PHPUnit_Framework_Constraint_ExceptionMessage( $expectedExceptionMessage ) ); return $this; } }