Skip to content

Commit

Permalink
Merge pull request #21552 from eileenmcnaughton/test_clean
Browse files Browse the repository at this point in the history
Cleanup on test tear downs
  • Loading branch information
seamuslee001 authored Sep 20, 2021
2 parents 599d982 + e50378d commit 92398cb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 40 deletions.
10 changes: 5 additions & 5 deletions tests/phpunit/CRM/Batch/BAO/BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -56,7 +54,7 @@ public function tearDown(): void {
*
* @throws \CRM_Core_Exception
*/
public function testGetBatchFinancialItems() {
public function testGetBatchFinancialItems(): void {

// create two contributions: one check and one credit card

Expand Down Expand Up @@ -119,8 +117,10 @@ public function testGetBatchFinancialItems() {

/**
* 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');
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/CRM/Batch/Form/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ public function tearDown(): void {
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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -31,7 +29,7 @@ public function tearDown(): void {
/**
* 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);
Expand Down
8 changes: 3 additions & 5 deletions tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -984,7 +982,7 @@ public function testBulkCreate(): void {
/**
* 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',
Expand Down
49 changes: 25 additions & 24 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,36 +487,37 @@ protected function loadXMLDataSet($fileName) {
/**
* 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;
Expand Down

0 comments on commit 92398cb

Please sign in to comment.