I am trying to use my first functions with Behat, and I ran into a problem, I do not know how to implement the expected exceptions.
I found the problem https://github.com/Behat/Behat/issues/140 , and robocoder talks about one possible way that Behat also uses. But it seems like they can't handle exceptions.
My goal is to force the handling of exceptions. I do not want any design to catch all exceptions and forget them.
One possible way:
When <player> transfers <transfer> from his account it should fail with <error>
Implementation
try {
...
} catch (\Exception $ex) {
assertEquals($error, $ex->getMessage());
}
I do not like the description of the script. I want to use the then keyword , for example
When <player> transfers <transfer> from his account
Then it should fail with error <error>
This description has a drawback. I need two methods:
method1($arg1, $arg2) {
}
method2($arg1, $arg2) {
}
2, .
, , - try/catch .
- . .
?
- ?
.
:
playerTransfer($player, $amount) {
$player->transfer($amount);
}
:
transfer($amount) {
if ($this->getWealth() < $amount) {
throw NotEnoughMoney();
}
...
}