Commit ecdb0696 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #295 from deeky666/fix-modify-limit-query-functional-test

Fix ModifyLimitQueryTest
parents 7f7a425c c9048212
...@@ -43,7 +43,7 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -43,7 +43,7 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->insert('modify_limit_table', array('test_int' => 3)); $this->_conn->insert('modify_limit_table', array('test_int' => 3));
$this->_conn->insert('modify_limit_table', array('test_int' => 4)); $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, 3, 4), $sql, 10, 0);
$this->assertLimitResult(array(1, 2), $sql, 2, 0); $this->assertLimitResult(array(1, 2), $sql, 2, 0);
...@@ -61,25 +61,25 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -61,25 +61,25 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->insert('modify_limit_table2', array('test_int' => 2)); $this->_conn->insert('modify_limit_table2', array('test_int' => 2));
$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(2, 2, 1, 1, 1), $sql, 10, 0);
$this->assertLimitResult(array(1, 1, 1), $sql, 3, 0); $this->assertLimitResult(array(1, 1, 1), $sql, 3, 2);
$this->assertLimitResult(array(2, 2), $sql, 2, 3); $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' => 1));
$this->_conn->insert('modify_limit_table', array('test_int' => 2)); $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' => 3));
$this->_conn->insert('modify_limit_table', array('test_int' => 4)); $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, 2, 1), $sql, 10, 0, false);
$this->assertLimitResult(array(4, 3), $sql, 2, 0); $this->assertLimitResult(array(4, 3), $sql, 2, 0, false);
$this->assertLimitResult(array(2, 1), $sql, 2, 2); $this->assertLimitResult(array(2, 1), $sql, 2, 2, false);
} }
public function testModifyLimitQueryGroupBy() public function testModifyLimitQueryGroupBy()
...@@ -95,13 +95,14 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -95,13 +95,14 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql = "SELECT modify_limit_table.test_int FROM modify_limit_table " . $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 ". "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, 2), $sql, 10, 0);
$this->assertLimitResult(array(1), $sql, 1, 0); $this->assertLimitResult(array(1), $sql, 1, 0);
$this->assertLimitResult(array(2), $sql, 1, 1); $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(); $p = $this->_conn->getDatabasePlatform();
$data = array(); $data = array();
...@@ -109,6 +110,14 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -109,6 +110,14 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
$row = array_change_key_case($row, CASE_LOWER); $row = array_change_key_case($row, CASE_LOWER);
$data[] = $row['test_int']; $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->assertCount(count($expectedResults), $data);
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment