From 36a29dc00163034d14b968bc285404a004bf2a3d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 20 Jun 2018 18:16:32 -0700 Subject: [PATCH] CiviUnitTestCase - Fix edge-case for mis-reported error Suppose you run a test and it encounters an error very early in process -- e.g. while processing `setUp()`, before constructing the instance of `$this->hookClass`. It then proceeds to `tearDown()`. Later, the test runner will give you a report on the rrors. Before ------------ The `tearDown` fails because the missing instance of `$this->hookClass` raises another error, and test-report shows this misleading reference. After ------------ The `tearDown` proceeds, and the test-report shows the real cause of the failure. --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index b1be120c16..71cd39915e 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -405,7 +405,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { protected function tearDown() { error_reporting(E_ALL & ~E_NOTICE); CRM_Utils_Hook::singleton()->reset(); - $this->hookClass->reset(); + if ($this->hookClass) { + $this->hookClass->reset(); + } $session = CRM_Core_Session::singleton(); $session->set('userID', NULL); -- 2.25.1