3

I have a method like this:

public function xy()
{
 die('script was terminated.')
}

If it possible to test this method with phpUnit?

John Conde
  • 217,595
  • 99
  • 455
  • 496

1 Answers1

2

This is possible by overloading the die() function. How you do this is described here: Intercepting the Exit Statement

Simply calling it is not possible as there is only one PHPUnit process and you will kill it by calling die() or exit().

Also have look at the answers to this question: How do you use PHPUnit to test a function if that function is supposed to kill PHP?

Community
  • 1
  • 1
RobDil
  • 4,036
  • 43
  • 52