CommitOrderCalculatorTest.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Doctrine\Tests\ORM;
  3. use Doctrine\ORM\Mapping\ClassMetadata;
  4. require_once __DIR__ . '/../TestInit.php';
  5. /**
  6. * Tests of the commit order calculation.
  7. *
  8. * IMPORTANT: When writing tests here consider that a lot of graph constellations
  9. * can have many valid orderings, so you may want to build a graph that has only
  10. * 1 valid order to simplify your tests.
  11. */
  12. class CommitOrderCalculatorTest extends \Doctrine\Tests\OrmTestCase
  13. {
  14. private $_calc;
  15. protected function setUp()
  16. {
  17. $this->_calc = new \Doctrine\ORM\Internal\CommitOrderCalculator();
  18. }
  19. public function testCommitOrdering1()
  20. {
  21. $class1 = new ClassMetadata(__NAMESPACE__ . '\NodeClass1');
  22. $class2 = new ClassMetadata(__NAMESPACE__ . '\NodeClass2');
  23. $class3 = new ClassMetadata(__NAMESPACE__ . '\NodeClass3');
  24. $class4 = new ClassMetadata(__NAMESPACE__ . '\NodeClass4');
  25. $class5 = new ClassMetadata(__NAMESPACE__ . '\NodeClass5');
  26. $this->_calc->addClass($class1);
  27. $this->_calc->addClass($class2);
  28. $this->_calc->addClass($class3);
  29. $this->_calc->addClass($class4);
  30. $this->_calc->addClass($class5);
  31. $this->_calc->addDependency($class1, $class2);
  32. $this->_calc->addDependency($class2, $class3);
  33. $this->_calc->addDependency($class3, $class4);
  34. $this->_calc->addDependency($class5, $class1);
  35. $sorted = $this->_calc->getCommitOrder();
  36. // There is only 1 valid ordering for this constellation
  37. $correctOrder = array($class5, $class1, $class2, $class3, $class4);
  38. $this->assertSame($correctOrder, $sorted);
  39. }
  40. }
  41. class NodeClass1 {}
  42. class NodeClass2 {}
  43. class NodeClass3 {}
  44. class NodeClass4 {}
  45. class NodeClass5 {}