Added a test case to track an ugly bug.
This commit is contained in:
parent
4eb1060b13
commit
05a23f6a30
110
tests/CustomResultSetOrderTestCase.php
Normal file
110
tests/CustomResultSetOrderTestCase.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?PHP
|
||||
class Doctrine_CustomResultSetOrderTestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Prepares the data under test.
|
||||
*
|
||||
* 1st category: 3 Boards
|
||||
* 2nd category: 1 Board
|
||||
* 3rd category: 0 boards
|
||||
*
|
||||
*/
|
||||
public function prepareData() {
|
||||
$cat1 = new CategoryWithPosition();
|
||||
$cat1->position = 0;
|
||||
$cat1->name = "First";
|
||||
|
||||
$cat2 = new CategoryWithPosition();
|
||||
$cat2->position = 0; // same 'priority' as the first
|
||||
$cat2->name = "Second";
|
||||
|
||||
$cat3 = new CategoryWithPosition();
|
||||
$cat3->position = 1;
|
||||
$cat3->name = "Third";
|
||||
|
||||
$board1 = new BoardWithPosition();
|
||||
$board1->position = 0;
|
||||
|
||||
$board2 = new BoardWithPosition();
|
||||
$board2->position = 1;
|
||||
|
||||
$board3 = new BoardWithPosition();
|
||||
$board3->position = 2;
|
||||
|
||||
// The first category gets 3 boards!
|
||||
$cat1->Boards[0] = $board1;
|
||||
$cat1->Boards[1] = $board2;
|
||||
$cat1->Boards[2] = $board3;
|
||||
|
||||
$board4 = new BoardWithPosition();
|
||||
$board4->position = 0;
|
||||
|
||||
// The second category gets 1 board!
|
||||
$cat2->Boards[0] = $board4;
|
||||
|
||||
$this->connection->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the tables.
|
||||
*/
|
||||
public function prepareTables() {
|
||||
$this->tables[] = "CategoryWithPosition";
|
||||
$this->tables[] = "BoardWithPosition";
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the boards are correctly assigned to the categories.
|
||||
*
|
||||
* The 'evil' result set that confuses the object population is displayed below.
|
||||
*
|
||||
* catId | catPos | catName | boardPos | board.category_id
|
||||
* 1 | 0 | First | 0 | 1
|
||||
* 2 | 0 | Second | 0 | 2 <-- The split that confuses the object population
|
||||
* 1 | 0 | First | 1 | 1
|
||||
* 1 | 0 | First | 2 | 1
|
||||
* 3 | 2 | Third | NULL
|
||||
*/
|
||||
public function testQueryWithOrdering() {
|
||||
$categories = $this->connection->query("FROM CategoryWithPosition.Boards
|
||||
ORDER BY CategoryWithPosition.position ASC, CategoryWithPosition.Boards.position ASC");
|
||||
|
||||
// Check each category
|
||||
foreach ($categories as $category) {
|
||||
|
||||
switch ($category->name) {
|
||||
case "First":
|
||||
// The first category should have 3 boards, right?
|
||||
// It has only 1! The other two slipped to the 2nd category!
|
||||
$this->assertEqual(3, $category->Boards->count());
|
||||
break;
|
||||
case "Second":
|
||||
// The second category should have 1 board, but it got 3 now
|
||||
$this->assertEqual(1, $category->Boards->count());
|
||||
break;
|
||||
case "Third":
|
||||
// The third has no boards as expected.
|
||||
$this->assertEqual(0, $category->Boards->count());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
@ -522,4 +522,22 @@ class MyUserOtherThing extends Doctrine_Record {
|
||||
$this->hasColumn("other_thing_id", "integer");
|
||||
}
|
||||
}
|
||||
class CategoryWithPosition extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn("position", "integer");
|
||||
$this->hasColumn("name", "string", 255);
|
||||
}
|
||||
public function setUp() {
|
||||
$this->ownsMany("BoardWithPosition as Boards", "BoardWithPosition.category_id");
|
||||
}
|
||||
}
|
||||
class BoardWithPosition extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
$this->hasColumn("position", "integer");
|
||||
$this->hasColumn("category_id", "integer");
|
||||
}
|
||||
public function setUp() {
|
||||
$this->hasOne("CategoryWithPosition as Category", "BoardWithPosition.category_id");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -36,6 +36,7 @@ require_once("EnumTestCase.php");
|
||||
require_once("RelationAccessTestCase.php");
|
||||
require_once("RelationTestCase.php");
|
||||
require_once("DataDictSqliteTestCase.php");
|
||||
require_once("CustomResultSetOrderTestCase.php");
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
@ -105,6 +106,8 @@ $test->addTestCase(new Doctrine_QueryTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_EventListener_Chain_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user