From cc4c8d1dbc3461894a81b21104fc464ec29aa3d2 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 10 Mar 2021 11:54:17 +1300 Subject: [PATCH] Fix test to teardown it's own mess This business of doing cleanup in the setup is an anti-pattern and it actually adds some internal dependency - if you run JUST the one test (conditions probably apply) it falls over with a 'cannot find DSN'. Rather than track that down that weirdness we should fix the tests to tearDown in the teardown --- tests/phpunit/api/v4/Action/ComplexQueryTest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/api/v4/Action/ComplexQueryTest.php b/tests/phpunit/api/v4/Action/ComplexQueryTest.php index dccd6db90a..7f957f7b1a 100644 --- a/tests/phpunit/api/v4/Action/ComplexQueryTest.php +++ b/tests/phpunit/api/v4/Action/ComplexQueryTest.php @@ -22,6 +22,7 @@ namespace api\v4\Action; use api\v4\UnitTestCase; use Civi\Api4\Activity; use Civi\Api4\Contact; +use Civi\Test\CiviEnvBuilder; /** * @group headless @@ -31,22 +32,27 @@ use Civi\Api4\Contact; */ class ComplexQueryTest extends UnitTestCase { - public function setUpHeadless() { + public function setUpHeadless(): CiviEnvBuilder { + $this->loadDataSet('DefaultDataSet'); + return parent::setUpHeadless(); + } + + public function tearDown(): void { $relatedTables = [ 'civicrm_activity', 'civicrm_activity_contact', ]; $this->cleanup(['tablesToTruncate' => $relatedTables]); - $this->loadDataSet('DefaultDataSet'); - - return parent::setUpHeadless(); + parent::tearDown(); } /** * Fetch all phone call activities * Expects at least one activity loaded from the data set. + * + * @throws \API_Exception */ - public function testGetAllHousingSupportActivities() { + public function testGetAllHousingSupportActivities(): void { $results = Activity::get(FALSE) ->addWhere('activity_type_id:name', '=', 'Phone Call') ->execute(); -- 2.25.1