From e50378d477b73139051a2f2f6c93ea4103660c1c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 21 Sep 2021 07:55:57 +1200 Subject: [PATCH] Cleanup on test tear downs --- tests/phpunit/CRM/Batch/BAO/BatchTest.php | 10 ++-- tests/phpunit/CRM/Batch/Form/EntryTest.php | 4 +- .../Form/Contribution/ThankYouTest.php | 4 +- .../phpunit/CRM/Core/BAO/CustomFieldTest.php | 8 ++- tests/phpunit/CiviTest/CiviUnitTestCase.php | 49 ++++++++++--------- 5 files changed, 35 insertions(+), 40 deletions(-) diff --git a/tests/phpunit/CRM/Batch/BAO/BatchTest.php b/tests/phpunit/CRM/Batch/BAO/BatchTest.php index 168c6ac3b3..edb435a7e5 100644 --- a/tests/phpunit/CRM/Batch/BAO/BatchTest.php +++ b/tests/phpunit/CRM/Batch/BAO/BatchTest.php @@ -34,11 +34,9 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { /** * Cleanup after test. * - * @throws \CRM_Core_Exception - * @throws \API_Exception */ public function tearDown(): void { - $this->quickCleanup(['civicrm_batch']); + $this->quickCleanup(['civicrm_batch', 'civicrm_file', 'civicrm_entity_file']); parent::tearDown(); } @@ -56,7 +54,7 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception */ - public function testGetBatchFinancialItems() { + public function testGetBatchFinancialItems(): void { // create two contributions: one check and one credit card @@ -119,8 +117,10 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { /** * Test testExportFinancialBatch. + * + * @throws \CRM_Core_Exception */ - public function testExportFinancialBatch() { + public function testExportFinancialBatch(): void { $this->createLoggedInUser(); $batchParams = ['title' => 'Test Batch']; $batchParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Exported'); diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php index 7f353c5c1c..d8d6fda2ca 100644 --- a/tests/phpunit/CRM/Batch/Form/EntryTest.php +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -165,12 +165,10 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { if ($this->callAPISuccessGetCount('membership', ['id' => $this->_membershipTypeID])) { $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); } - if ($this->callAPISuccessGetCount('MembershipStatus', ['id' => $this->_membershipStatusID])) { - $this->membershipStatusDelete($this->_membershipStatusID); - } $this->contactDelete($this->_contactID); $this->contactDelete($this->_contactID2); $this->contactDelete($this->_orgContactID); + parent::tearDown(); } /** diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php index 895cc03947..aa9b3e373f 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php @@ -20,8 +20,6 @@ class CRM_Contribute_Form_Contribution_ThankYouTest extends CiviUnitTestCase { /** * Clean up DB. - * - * @throws \CRM_Core_Exception|\API_Exception */ public function tearDown(): void { $this->quickCleanUpFinancialEntities(); @@ -31,7 +29,7 @@ class CRM_Contribute_Form_Contribution_ThankYouTest extends CiviUnitTestCase { /** * Test that correct contribution status is fetched for both live and test contributions. */ - public function testLiveAndTestContributionStatus() { + public function testLiveAndTestContributionStatus(): void { $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']); $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE); diff --git a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php index c92b9df471..23968d527a 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php @@ -15,18 +15,16 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { /** * Clean up after test. - * - * @throws \Exception */ public function tearDown(): void { - $this->quickCleanup([], TRUE); + $this->quickCleanup(['civicrm_file', 'civicrm_entity_file'], TRUE); parent::tearDown(); } /** * Test creating a custom field. */ - public function testCreateCustomField() { + public function testCreateCustomField(): void { $customGroup = $this->createCustomField(); $customFieldID = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id', 'Database check for created CustomField.' @@ -984,7 +982,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { /** * Check that outputting the display value for a file field with No description doesn't generate error */ - public function testFileDisplayValueNoDescription() { + public function testFileDisplayValueNoDescription(): void { $customGroup = $this->customGroupCreate([ 'extends' => 'Individual', 'title' => 'Test Contact File Custom Group', diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 652cd3f9de..5a0bbb29a6 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -487,36 +487,37 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { /** * Create default domain contacts for the two domains added during test class. * database population. - * - * @throws \API_Exception */ public function createDomainContacts(): void { - $this->organizationCreate(['api.Email.create' => ['email' => 'fixme.domainemail@example.org']]); - $this->organizationCreate([ - 'organization_name' => 'Second Domain', - 'api.Email.create' => ['email' => 'domainemail2@example.org'], - 'api.Address.create' => [ - 'street_address' => '15 Main St', - 'location_type_id' => 1, - 'city' => 'Collinsville', - 'country_id' => 1228, - 'state_province_id' => 1003, - 'postal_code' => 6022, - ], - ]); - OptionValue::replace(FALSE)->addWhere( - 'option_group_id:name', '=', 'from_email_address' - )->setDefaults([ - 'is_default' => 1, - 'name' => '"FIXME" ', - 'label' => '"FIXME" ', - ])->setRecords([['domain_id' => 1], ['domain_id' => 2]])->execute(); + try { + $this->organizationCreate(['api.Email.create' => ['email' => 'fixme.domainemail@example.org']]); + $this->organizationCreate([ + 'organization_name' => 'Second Domain', + 'api.Email.create' => ['email' => 'domainemail2@example.org'], + 'api.Address.create' => [ + 'street_address' => '15 Main St', + 'location_type_id' => 1, + 'city' => 'Collinsville', + 'country_id' => 1228, + 'state_province_id' => 1003, + 'postal_code' => 6022, + ], + ]); + OptionValue::replace(FALSE)->addWhere( + 'option_group_id:name', '=', 'from_email_address' + )->setDefaults([ + 'is_default' => 1, + 'name' => '"FIXME" ', + 'label' => '"FIXME" ', + ])->setRecords([['domain_id' => 1], ['domain_id' => 2]])->execute(); + } + catch (API_Exception $e) { + $this->fail('failed to re-instate domain contacts ' . $e->getMessage()); + } } /** * Common teardown functions for all unit tests. - * - * @throws \API_Exception */ protected function tearDown(): void { $this->_apiversion = 3; -- 2.25.1