class Foo
{
private function bar($languageId)
{
// like http call...
// some heavy task
}
public function BarCall($languageId)
{
if (empty($languageId)) {
throw new \Exception('must not be empty');
}
try {
$this->bar($languageId);
} catch (\Exception $e) {
throw new \Exception('cannot connect');
}
}
}
Question: how to appropriatery test BarCall()
method ?
It looks like you can provoke an exception with
$languageId
. A non empty but invalid one should do the trick. If there are multiple possible exceptions inbar()
, then it's going to be hard to test them seperatly, becauseBarCall()
catches them and throws its own exception. So all you can test with the annotation @ExpectedException is the same one for every thrown exception inbar()
. I don't know any way to test an embedded previous exception (since PHP 5.3) with phpunit.How can you tell that
BarCall()
/bar()
worked? What happens after everything was correct?