Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ModifyLimitQueryTest #295

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand All @@ -95,20 +95,29 @@ 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();
foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) AS $row) {
$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->assertCount(count($expectedResults), $data);
}
}
}