From 06b84fc8d5761184489e64488c75edddfad03574 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 16 Jul 2021 10:44:34 +1200 Subject: [PATCH] Fix v4 api to do custom field delete in tearDown This existing efforts are wrong because 1) the delete has to go in the tearDown not the clean up 2) it is rigid about the custom group table name - which will get us into problems as the name can be set and we should be ensuring that it can in our tests --- .../api/v4/Action/BaseCustomValueTest.php | 20 ++++++++++--------- .../api/v4/Action/BasicCustomFieldTest.php | 6 ++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/api/v4/Action/BaseCustomValueTest.php b/tests/phpunit/api/v4/Action/BaseCustomValueTest.php index 29adc87e37..9064c9e143 100644 --- a/tests/phpunit/api/v4/Action/BaseCustomValueTest.php +++ b/tests/phpunit/api/v4/Action/BaseCustomValueTest.php @@ -21,6 +21,7 @@ namespace api\v4\Action; use api\v4\UnitTestCase; use api\v4\Traits\TableDropperTrait; +use Civi\Api4\CustomGroup; abstract class BaseCustomValueTest extends UnitTestCase { @@ -34,15 +35,16 @@ abstract class BaseCustomValueTest extends UnitTestCase { */ public function setUp(): void { $this->setUpOptionCleanup(); - $cleanup_params = [ - 'tablesToTruncate' => [ - 'civicrm_custom_group', - 'civicrm_custom_field', - ], - ]; - - $this->dropByPrefix('civicrm_value_my'); - $this->cleanup($cleanup_params); + } + + /** + * Delete all created options groups. + * + * @throws \API_Exception + */ + public function tearDown(): void { + CustomGroup::delete(FALSE)->addWhere('id', '>', 0)->execute(); + parent::tearDown(); } } diff --git a/tests/phpunit/api/v4/Action/BasicCustomFieldTest.php b/tests/phpunit/api/v4/Action/BasicCustomFieldTest.php index e85f816758..28565d4d08 100644 --- a/tests/phpunit/api/v4/Action/BasicCustomFieldTest.php +++ b/tests/phpunit/api/v4/Action/BasicCustomFieldTest.php @@ -30,8 +30,10 @@ use Civi\Api4\RelationshipCache; */ class BasicCustomFieldTest extends BaseCustomValueTest { - public function testWithSingleField() { - + /** + * @throws \API_Exception + */ + public function testWithSingleField(): void { $customGroup = CustomGroup::create(FALSE) ->addValue('name', 'MyIndividualFields') ->addValue('extends', 'Individual') -- 2.25.1