What you should use is set_error_handler() ( link ) and restore_error_handler() , which allows you to set a function to handle this type of error. It also has an added bonus, giving you a place to check for alerts at the same time.
So something like this:
class SimpleTest extends PHPUnit_Framework_TestCase { function testSimpleMethod() { set_error_handler(array($this, '_handleWarnedMethod'), E_USER_WARNING); $toBeTestedObject = new ToBeTested(); $this->assertFalse($toBeTestedObject->simpleMethod(0)); restore_error_handler(); } private function _handleWarnedMethod($errno, $errstr) { $this->assertEquals(E_USER_WARNING, $errno); $this->assertEquals('Param is 0!', $errstr); } }
As always, suppressing errors is not a good idea :)
pivotal
source share