2008-08-01 22:46:14 +04:00
|
|
|
<?php
|
|
|
|
require_once 'lib/DoctrineTestInit.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests of the commit order calculation.
|
|
|
|
*
|
|
|
|
* IMPORTANT: When writing tests here consider that a lot of graph constellations
|
|
|
|
* can have many valid orderings, so you may want to build a graph that has only
|
|
|
|
* 1 valid order to simplify your tests.
|
|
|
|
*/
|
2009-01-04 19:15:32 +03:00
|
|
|
class Orm_CommitOrderCalculatorTest extends Doctrine_OrmTestCase
|
2008-08-01 22:46:14 +04:00
|
|
|
{
|
|
|
|
private $_calc;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2009-01-04 19:15:32 +03:00
|
|
|
$this->_calc = new Doctrine_ORM_Internal_CommitOrderCalculator();
|
2008-08-01 22:46:14 +04:00
|
|
|
}
|
2009-01-04 19:15:32 +03:00
|
|
|
|
|
|
|
/** Helper to create an array of nodes */
|
2008-08-01 22:46:14 +04:00
|
|
|
private function _createNodes(array $names)
|
|
|
|
{
|
|
|
|
$nodes = array();
|
|
|
|
foreach ($names as $name) {
|
2009-01-04 19:15:32 +03:00
|
|
|
$node = new Doctrine_ORM_Internal_CommitOrderNode($name, $this->_calc);
|
2008-08-01 22:46:14 +04:00
|
|
|
$nodes[$name] = $node;
|
|
|
|
$this->_calc->addNode($node->getClass(), $node);
|
|
|
|
}
|
|
|
|
return $nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCommitOrdering1()
|
|
|
|
{
|
|
|
|
$nodes = $this->_createNodes(array("node1", "node2", "node3", "node4", "node5"));
|
|
|
|
|
|
|
|
$nodes['node1']->before($nodes['node2']);
|
|
|
|
$nodes['node2']->before($nodes['node3']);
|
|
|
|
$nodes['node3']->before($nodes['node4']);
|
|
|
|
$nodes['node5']->before($nodes['node1']);
|
|
|
|
|
|
|
|
shuffle($nodes); // some randomness
|
|
|
|
|
|
|
|
$sorted = $this->_calc->getCommitOrder();
|
|
|
|
|
|
|
|
// There is only 1 valid ordering for this constellation
|
|
|
|
$correctOrder = array("node5", "node1", "node2", "node3", "node4");
|
|
|
|
$this->assertSame($correctOrder, $sorted);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|