Skip to content

Commit

Permalink
Add a unit test reproducing the commit order regression
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Sep 20, 2018
1 parent 145f1f5 commit 722005f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@ public function testCommitOrdering2()

$this->assertSame($correctOrder, $sorted);
}

public function testCommitOrdering3()
{
$class1 = new ClassMetadata(NodeClass1::class); // File
$class2 = new ClassMetadata(NodeClass2::class); // FileVersion
$class3 = new ClassMetadata(NodeClass3::class); // FeedItem
$class4 = new ClassMetadata(NodeClass4::class); // Space

$this->_calc->addNode($class1->name, $class1);
$this->_calc->addNode($class2->name, $class2);
$this->_calc->addNode($class3->name, $class3);
$this->_calc->addNode($class4->name, $class4);

$this->_calc->addDependency($class2->name, $class1->name, 1);
$this->_calc->addDependency($class1->name, $class4->name, 1);
$this->_calc->addDependency($class3->name, $class4->name, 1);
$this->_calc->addDependency($class4->name, $class1->name, 0);

$sorted = $this->_calc->sort();

// There is only multiple valid ordering for this constellation, but
// the class4, class1, class2 ordering is important to break the cycle
// on the nullable link.
$correctOrders = [
[$class4, $class1, $class2, $class3],
[$class4, $class1, $class3, $class2],
[$class4, $class3, $class1, $class2],
];

// We want to perform a strict comparison of the array
$this->assertContains($sorted, $correctOrders, '', false, true, true);
}
}

class NodeClass1 {}
Expand Down

0 comments on commit 722005f

Please sign in to comment.