From: eileen Date: Thu, 28 Jul 2016 02:14:16 +0000 (+1200) Subject: Fix for intermittent test failure X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=204beda391cba7d2c182eb0c5568affc5530e195;p=civicrm-core.git Fix for intermittent test failure --- diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index fa83348512..f89c36ea1c 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -132,6 +132,15 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { */ protected $origExtensionSystem; + /** + * Array of IDs created during test setup routine. + * + * The cleanUpSetUpIds method can be used to clear these at the end of the test. + * + * @var array + */ + public $setupIDs = array(); + /** * Constructor. * @@ -1137,7 +1146,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { public function membershipTypeCreate($params = array()) { CRM_Member_PseudoConstant::flush('membershipType'); CRM_Core_Config::clearDBCache(); - $memberOfOrganization = $this->organizationCreate(); + $this->setupIDs['contact'] = $memberOfOrganization = $this->organizationCreate(); $params = array_merge(array( 'name' => 'General', 'duration_unit' => 'year', @@ -3590,4 +3599,23 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0); } + /** + * Cleanup function for contents of $this->ids. + * + * This is a best effort cleanup to use in tear downs etc. + * + * It will not fail if the data has already been removed (some tests may do + * their own cleanup). + */ + protected function cleanUpSetUpIDs() { + foreach ($this->setupIDs as $entity => $id) { + try { + civicrm_api3($entity, 'delete', array('id' => $id, 'skip_undelete' => 1)); + } + catch (CiviCRM_API3_Exception $e) { + // This is a best-effort cleanup function, ignore. + } + } + } + } diff --git a/tests/phpunit/api/v3/JobTest.php b/tests/phpunit/api/v3/JobTest.php index b5c964d4bd..ec1a2b5a85 100644 --- a/tests/phpunit/api/v3/JobTest.php +++ b/tests/phpunit/api/v3/JobTest.php @@ -73,7 +73,9 @@ class api_v3_JobTest extends CiviUnitTestCase { public function tearDown() { parent::tearDown(); + // The membershipType create breaks transactions so this extra cleanup is needed. $this->membershipTypeDelete(array('id' => $this->membershipTypeID)); + $this->cleanUpIDs(); } /**