You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 29, 2023. It is now read-only.
edsonmedina edited this page Dec 16, 2014
·
8 revisions
#Exit (or die)
class foo
{
public function bar ()
{
// ...
exit();
}
}
##Why is this a testing issue?
Pretty self-explanatory. If a method calls exit() or die() the execution stops immediately and the test doesn't run.
##Possible refactorings
####Don't use it
Use conditionals instead. If the conditions are not met, nothing happens and the script ends normally.
####Use exceptions instead
throw new Exception ('Fatal error');
####If you really need to use exit()
Write a wrapper method.
class foo
{
public function bar ()
{
// ...
$this->exitApp();
}
public function exitApp ($code);
{
// this method will be untestable, but
// it can be mocked to test other methods
// that depend on it
exit ($code);
}
}