1
0
mirror of synced 2024-12-15 07:36:03 +03:00
doctrine2/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php

56 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Doctrine\Tests\ORM;
use Doctrine\ORM\Mapping\ClassMetadata;
require_once __DIR__ . '/../TestInit.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.
*/
class CommitOrderCalculatorTest extends \Doctrine\Tests\OrmTestCase
{
private $_calc;
2011-12-20 01:56:19 +04:00
protected function setUp()
{
$this->_calc = new \Doctrine\ORM\Internal\CommitOrderCalculator();
}
2011-12-20 01:56:19 +04:00
public function testCommitOrdering1()
{
$class1 = new ClassMetadata(__NAMESPACE__ . '\NodeClass1');
$class2 = new ClassMetadata(__NAMESPACE__ . '\NodeClass2');
$class3 = new ClassMetadata(__NAMESPACE__ . '\NodeClass3');
$class4 = new ClassMetadata(__NAMESPACE__ . '\NodeClass4');
$class5 = new ClassMetadata(__NAMESPACE__ . '\NodeClass5');
2011-12-20 01:56:19 +04:00
$this->_calc->addClass($class1);
$this->_calc->addClass($class2);
$this->_calc->addClass($class3);
$this->_calc->addClass($class4);
$this->_calc->addClass($class5);
2011-12-20 01:56:19 +04:00
$this->_calc->addDependency($class1, $class2);
$this->_calc->addDependency($class2, $class3);
$this->_calc->addDependency($class3, $class4);
$this->_calc->addDependency($class5, $class1);
$sorted = $this->_calc->getCommitOrder();
2011-12-20 01:56:19 +04:00
// There is only 1 valid ordering for this constellation
$correctOrder = array($class5, $class1, $class2, $class3, $class4);
$this->assertSame($correctOrder, $sorted);
}
}
class NodeClass1 {}
class NodeClass2 {}
class NodeClass3 {}
class NodeClass4 {}
class NodeClass5 {}