Skip to content

Instantly share code, notes, and snippets.

@polyfractal
Last active December 16, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polyfractal/5506185 to your computer and use it in GitHub Desktop.
Save polyfractal/5506185 to your computer and use it in GitHub Desktop.
public function assertThrowsException($exception, $code)
{
$raisedException = null;
try {
$code();
} catch (\Exception $raisedException) {
// No more code, we only want to catch the exception in $raisedException.
}
$this->assertInstanceOf($exception, $raisedException);
}
public function testGizmo()
{
$widget = 'something';
// Some more code
$this->assertThrowsException('\Package\Specific\Exception', function () use ($widget) {
$blah = new \Package\Gizmo($widget);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment