From 72475b30e96d28308436a7cf47da2a9a66808343 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 26 Sep 2016 19:32:35 -0400 Subject: [PATCH] CRM-18006 - CRM_Dedupe_MergerTest - Fix regression InnoDB and MyISAM may have different edge-cases in how the default orderings. However, for deduping, the order is arbitrary. This patch makes the test order-insensitive. --- tests/phpunit/CRM/Dedupe/MergerTest.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Dedupe/MergerTest.php b/tests/phpunit/CRM/Dedupe/MergerTest.php index 9b120d08a9..97dd6d5a65 100644 --- a/tests/phpunit/CRM/Dedupe/MergerTest.php +++ b/tests/phpunit/CRM/Dedupe/MergerTest.php @@ -319,7 +319,7 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase { FALSE ); - $this->assertEquals(array( + $expectedPairs = array( 0 => array( 'srcID' => $this->contacts[5]['id'], 'srcName' => 'Walt Disney Ltd', @@ -352,7 +352,26 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase { 'weight' => 10, 'canMerge' => TRUE, ), - ), $pairs); + ); + usort($pairs, array(__CLASS__, 'compareDupes')); + usort($expectedPairs, array(__CLASS__, 'compareDupes')); + $this->assertEquals($expectedPairs, $pairs); + } + + /** + * Function to sort $duplicate records in a stable way. + * + * @param array $a + * @param array $b + * @return int + */ + public static function compareDupes($a, $b) { + foreach (array('srcName', 'dstName', 'srcID', 'dstID') as $field) { + if ($a[$field] != $b[$field]) { + return ($a[$field] < $b[$field]) ? 1 : -1; + } + } + return 0; } /** -- 2.25.1