CiviUnitTestCase - Fix edge-case for mis-reported error
authorTim Otten <totten@civicrm.org>
Thu, 21 Jun 2018 01:16:32 +0000 (18:16 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 21 Jun 2018 01:16:32 +0000 (18:16 -0700)
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

index b1be120c16bb8a79eb03710cc583592842154576..71cd39915efe51d5b7e75091c05c49c841df2142 100644 (file)
@@ -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);