Mind:
public function seeException($callback, $exception = 'Exception', $message = '')
{
$function = function () use ($callback, $exception) {
try {
$callback();
return false;
}
catch (Exception $e) {
if (get_class($e) == $exception or get_parent_class($e) == $exception) {
return true;
}
return false;
}
};
$this->assertTrue($function(), $message);
}
cepts
$I->seeException('Laracasts\Validation\FormValidationException', function() use ($I){
$I->amOnPage('/users/edit/1');
$I->fillField('name', '');
$I->click('Update');
})
, assertTrue . , , . , . , , .
, . FunctionalHelper.php _beforeSuite :
public function _beforeSuite()
{
parent::_beforeSuite();
$this->assert = $this->getModule('Asserts');
}
EDIT2
, , , , php , . ,
public function assertThrows($callback, $exception = 'Exception', $message = '')
{
$function = function () use ($callback, $exception) {
$getAncestors = function($e) {
for ($classes[] = $e; $e = get_parent_class ($e); $classes[] = $e);
return $classes;
}
try {
$callback();
return false;
}
catch (Exception $e) {
if (get_class($e) == $exception or in_array($e, $getAncestors($e))) {
return true;
}
return false;
}
};
$this->assertTrue($function(), $message);
}