Cleanup on test tear downs
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 20 Sep 2021 19:55:57 +0000 (07:55 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 20 Sep 2021 19:55:57 +0000 (07:55 +1200)
tests/phpunit/CRM/Batch/BAO/BatchTest.php
tests/phpunit/CRM/Batch/Form/EntryTest.php
tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php
tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 168c6ac3b3a03bfc1ebbf8cb87c8c356a523784e..edb435a7e5854dc7cea3aac410319d0f7adf6f4f 100644 (file)
@@ -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');
index 7f353c5c1c7d4ebb0fafe26a5cdfb6a98f356caa..d8d6fda2ca7d974db450eab338ca7452ea43cc3b 100644 (file)
@@ -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();
   }
 
   /**
index 895cc03947151bfdfb68b8e29369dcd1c7a35aec..aa9b3e373f4372c63c53a496102c20d96b83524e 100644 (file)
@@ -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);
index c92b9df4715f8d26ae76099f5f040526e9592dcf..23968d527a868ae5c3e3e0e5c12397c42da6066b 100644 (file)
@@ -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',
index 652cd3f9decda251504657cfa02e3f3461e62af8..5a0bbb29a61c494696a0ce9e6250466fa84b513a 100644 (file)
@@ -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" <info@EXAMPLE.ORG>',
-      'label' => '"FIXME" <info@EXAMPLE.ORG>',
-    ])->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" <info@EXAMPLE.ORG>',
+        'label' => '"FIXME" <info@EXAMPLE.ORG>',
+      ])->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;