class MyTest extends PHPUnit_Framework_TestCase { protected function onNotSuccessfulTest(Exception $e) { error_log("Test failed: " . $e->getMessage()); } public function testSomething() { $this->assertTrue(false); } }
class MyTest extends PHPUnit_Framework_TestCase { protected function onNotSuccessfulTest(Exception $e) { $message = "Test failed: " . $e->getMessage(); mail("admin@example.com", "Test failed", $message); } public function testSomething() { $this->assertTrue(false); } }In this example, the onNotSuccessfulTest method sends an email to the administrator when a test fails. The testSomething method intentionally fails to trigger this method. The PHPUnit_Framework_TestCase class is part of the PHPUnit library, which is a widely used PHP testing framework.