From 4b51393e014fc4c0cc8e192c74eb4594acaca605 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 14 Feb 2014 11:32:20 +1300 Subject: [PATCH] Don't rely on MySQL ordering of index->getAdded() MySQL is more reliable in its output ordering of elements where the order doesn't matter. PostgreSQL is not. This meant that this test "accidentally passed" on MySQL and failed on PostgreSQL. The sort function resolves this. --- tests/SearchUpdaterTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/SearchUpdaterTest.php b/tests/SearchUpdaterTest.php index 52ab987..2ee7d02 100644 --- a/tests/SearchUpdaterTest.php +++ b/tests/SearchUpdaterTest.php @@ -107,7 +107,13 @@ class SearchUpdaterTest extends SapphireTest { // Check the default "writing a document updates the document" SearchUpdater::flush_dirty_indexes(); - $this->assertEquals(self::$index->getAdded(array('ID')), array( + + + $added = self::$index->getAdded(array('ID')); + // Some databases don't output $added in a consistent order; that's okay + usort($added, function($a,$b) {return $a['ID']-$b['ID']; }); + + $this->assertEquals($added, array( array('ID' => $container1->ID), array('ID' => $container2->ID), array('ID' => $container3->ID) @@ -121,7 +127,11 @@ class SearchUpdaterTest extends SapphireTest { $hasOne->write(); SearchUpdater::flush_dirty_indexes(); - $this->assertEquals(self::$index->getAdded(array('ID')), array( + $added = self::$index->getAdded(array('ID')); + // Some databases don't output $added in a consistent order; that's okay + usort($added, function($a,$b) {return $a['ID']-$b['ID']; }); + + $this->assertEquals($added, array( array('ID' => $container1->ID), array('ID' => $container2->ID) ));