Skip to content

Commit

Permalink
do not merge
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 2, 2025
1 parent badcb0f commit 777868b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class CiviUnitTestCaseCommon extends PHPUnit\Framework\TestCase {
*/
protected $isLocationTypesOnPostAssert = TRUE;

private array $entityTracking = [];

/**
* Has the test class been verified as 'getsafe'.
*
Expand Down Expand Up @@ -378,6 +380,9 @@ protected function setUp(): void {
// something changed it and then inadvertently didn't restore it.
$this->errorHandlerAtStartOfTest = set_error_handler(function($errno, $errstr, $errfile, $errline) {});
restore_error_handler();
foreach (['civicrm_option_value', 'civicrm_campaign', 'civicrm_line_item', 'civicrm_im', 'civicrm_address'] as $entity) {
$this->entityTracking[$entity] = \CRM_Core_DAO::singleValueQuery('SELECT count(*) FROM ' . $entity);
}
}

/**
Expand Down Expand Up @@ -553,6 +558,9 @@ protected function tearDown(): void {
OptionValue::delete(FALSE)->addWhere('id', 'IN', $this->ids['OptionValue'])->execute();
}
unset(CRM_Core_Config::singleton()->userPermissionClass->permissions);
foreach ($this->entityTracking as $entity => $count) {
$this->assertEquals($count, \CRM_Core_DAO::singleValueQuery('SELECT count(*) FROM ' . $entity), $entity . ' has not cleaned up well ' . CRM_Core_DAO::singleValueQuery('SELECT name FROM ' . $entity . ' ORDER BY id DESC LIMIT 1'));
}
parent::tearDown();
}

Expand Down

0 comments on commit 777868b

Please sign in to comment.