CRM-18006 - CRM_Dedupe_MergerTest - Fix regression
authorTim Otten <totten@civicrm.org>
Mon, 26 Sep 2016 23:32:35 +0000 (19:32 -0400)
committerTim Otten <totten@civicrm.org>
Mon, 26 Sep 2016 23:32:35 +0000 (19:32 -0400)
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

index 9b120d08a91c6b461d42794824f08418573e5d8b..97dd6d5a65c0a66b2b0db0c13a92506ecc6f8866 100644 (file)
@@ -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;
   }
 
   /**