From 8ce8f300bb8443f1c91a15e4df4086dceafded48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Sat, 30 Mar 2013 17:24:11 +0100 Subject: [PATCH 1/2] fix ModifyLimitQueryTest to correctly assert deterministic and non-deterministic results --- .../DBAL/Functional/ModifyLimitQueryTest.php | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php index 69ba6ac290a..11844421475 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php @@ -43,7 +43,7 @@ public function testModifyLimitQuerySimpleQuery() $this->_conn->insert('modify_limit_table', array('test_int' => 3)); $this->_conn->insert('modify_limit_table', array('test_int' => 4)); - $sql = "SELECT * FROM modify_limit_table"; + $sql = "SELECT * FROM modify_limit_table ORDER BY test_int ASC"; $this->assertLimitResult(array(1, 2, 3, 4), $sql, 10, 0); $this->assertLimitResult(array(1, 2), $sql, 2, 0); @@ -61,25 +61,25 @@ public function testModifyLimitQueryJoinQuery() $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); - $sql = "SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int"; + $sql = "SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ORDER BY modify_limit_table.test_int DESC"; - $this->assertLimitResult(array(1, 1, 1, 2, 2), $sql, 10, 0); - $this->assertLimitResult(array(1, 1, 1), $sql, 3, 0); - $this->assertLimitResult(array(2, 2), $sql, 2, 3); + $this->assertLimitResult(array(2, 2, 1, 1, 1), $sql, 10, 0); + $this->assertLimitResult(array(1, 1, 1), $sql, 3, 2); + $this->assertLimitResult(array(2, 2), $sql, 2, 0); } - public function testModifyLimitQueryOrderBy() + public function testModifyLimitQueryNonDeterministic() { $this->_conn->insert('modify_limit_table', array('test_int' => 1)); $this->_conn->insert('modify_limit_table', array('test_int' => 2)); $this->_conn->insert('modify_limit_table', array('test_int' => 3)); $this->_conn->insert('modify_limit_table', array('test_int' => 4)); - $sql = "SELECT * FROM modify_limit_table ORDER BY test_int DESC"; + $sql = "SELECT * FROM modify_limit_table"; - $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0); - $this->assertLimitResult(array(4, 3), $sql, 2, 0); - $this->assertLimitResult(array(2, 1), $sql, 2, 2); + $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0, false); + $this->assertLimitResult(array(4, 3), $sql, 2, 0, false); + $this->assertLimitResult(array(2, 1), $sql, 2, 2, false); } public function testModifyLimitQueryGroupBy() @@ -95,13 +95,14 @@ public function testModifyLimitQueryGroupBy() $sql = "SELECT modify_limit_table.test_int FROM modify_limit_table " . "INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ". - "GROUP BY modify_limit_table.test_int"; + "GROUP BY modify_limit_table.test_int " . + "ORDER BY modify_limit_table.test_int ASC"; $this->assertLimitResult(array(1, 2), $sql, 10, 0); $this->assertLimitResult(array(1), $sql, 1, 0); $this->assertLimitResult(array(2), $sql, 1, 1); } - public function assertLimitResult($expectedResults, $sql, $limit, $offset) + public function assertLimitResult($expectedResults, $sql, $limit, $offset, $deterministic = true) { $p = $this->_conn->getDatabasePlatform(); $data = array(); @@ -109,6 +110,14 @@ public function assertLimitResult($expectedResults, $sql, $limit, $offset) $row = array_change_key_case($row, CASE_LOWER); $data[] = $row['test_int']; } - $this->assertEquals($expectedResults, $data); + + /** + * Do not assert the order of results when results are non-deterministic + */ + if ($deterministic) { + $this->assertEquals($expectedResults, $data); + } else { + $this->assertEquals(count($expectedResults), count($data)); + } } } \ No newline at end of file From c9048212fbd3c94d0a953ef636456478e9bc45a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Sat, 30 Mar 2013 17:51:35 +0100 Subject: [PATCH 2/2] fix assertion method for non-deterministic query results --- tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php index 11844421475..f6d4749e889 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php @@ -117,7 +117,7 @@ public function assertLimitResult($expectedResults, $sql, $limit, $offset, $dete if ($deterministic) { $this->assertEquals($expectedResults, $data); } else { - $this->assertEquals(count($expectedResults), count($data)); + $this->assertCount(count($expectedResults), $data); } } } \ No newline at end of file