I noticed that PHPUnit ignores exceptions thrown in the setUp() method, and simply runs tests even when the setup function throws an exception.
In the below code the exception will be ignored, the code below it will not run, and the test_method will fail because it is using an undefined variable.
protected $a;
public function setUp() {
parent:setUp();
throw new Exception(); // setup now exits silently.
$this->a = new A(); // will never run
}
public function testA() {
$this->assertTrue($this->a->something()); // will exit tests with PHP error, because $this->a === null
}
I’m running phpunit through the CLI with an phpunit.xml configuration file.
Does anyone know a way to make PHPunit report on the exception, and then stop the execution of the testCase?
Can’t repoduce
Running the script (full example below) produces an error output with the exception.
I’d assume you have a problem elsewhere or maybe a old phpunit version? Even so I’m not aware of any changes in that piece of code.
You might also be running phpunit from trunk? (“3.6”) In that case the handling of the
"Exception"class its self changed, can’t test that case right now but if that applies to you try using a InvalidArgumentException() (just for testing) and see if that changes things.Your Code made runable: