Skip to content

Commit

Permalink
Merge pull request #229 from peterrehm/self-referencing-classes
Browse files Browse the repository at this point in the history
Added support for self referencing classes in the TopologicalSorter
  • Loading branch information
guilhermeblanco authored Jun 20, 2016
2 parents ac2ce69 + c5eb5de commit b3cae5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ private function visit(Vertex $definition)

$childDefinition = $this->nodeList[$dependency];

// allow self referencing classes
if ($definition === $childDefinition) {
continue;
}

switch ($childDefinition->state) {
case Vertex::VISITED:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@ public function testFailureSortCyclicDependency()
$this->sorter->sort();
}

public function testNoFailureOnSelfReferencingDependency()
{
$node1 = new Mock\Node(1);
$node2 = new Mock\Node(2);
$node3 = new Mock\Node(3);
$node4 = new Mock\Node(4);
$node5 = new Mock\Node(5);

$this->sorter->addNode('1', $node1);
$this->sorter->addNode('2', $node2);
$this->sorter->addNode('3', $node3);
$this->sorter->addNode('4', $node4);
$this->sorter->addNode('5', $node5);

$this->sorter->addDependency('1', '2');
$this->sorter->addDependency('1', '1');
$this->sorter->addDependency('2', '3');
$this->sorter->addDependency('3', '4');
$this->sorter->addDependency('5', '1');

$sortedList = $this->sorter->sort();
$correctList = array($node4, $node3, $node2, $node1, $node5);

self::assertSame($correctList, $sortedList);
}

public function testFailureSortMissingDependency()
{
$node1 = new Mock\Node(1);
Expand Down

0 comments on commit b3cae5e

Please sign in to comment.