Skip to content

Commit

Permalink
Add tests for doctrine#8349
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Mar 11, 2023
1 parent ae4c1f2 commit d151000
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\ORM\Internal\CommitOrder\CycleDetectedException;
use Doctrine\ORM\Internal\CommitOrderCalculator;
use Doctrine\Tests\OrmTestCase;

use function array_map;
use function array_values;
use function spl_object_id;
Expand Down Expand Up @@ -121,6 +120,36 @@ public function testCommitOrderingFromGH7259Test(): void
self::assertContains($this->computeResult(), $correctOrders);
}

public function testCommitOrderingFromGH8349Case1Test()
{
$this->addNodes('A', 'B', 'C', 'D');

$this->addDependency('D', 'A');
$this->addDependency('A', 'B', true);
$this->addDependency('B', 'D', true);
$this->addDependency('B', 'C', true);
$this->addDependency('C', 'D', true);

// Many orderings are possible here, but the bottom line is D must be before A (it's the only hard requirement).
$result = $this->computeResult();

$indexA = array_search('A', $result, true);
$indexD = array_search('D', $result, true);
self::assertTrue($indexD < $indexA);
}

public function testCommitOrderingFromGH8349Case2Test()
{
$this->addNodes('A', 'B');

$this->addDependency('B', 'A');
$this->addDependency('B', 'A', true); // interesting: We have two edges in that direction
$this->addDependency('A', 'B', true);

// The B -> A requirement determines the result here
self::assertSame(['B', 'A'], $this->computeResult());
}

public function testNodesMaintainOrderWhenNoDepencency(): void
{
$this->addNodes('A', 'B', 'C');
Expand Down Expand Up @@ -157,7 +186,7 @@ public function testDetectLargerCycleNotIncludingStartNode(): void
private function addNodes(string ...$names): void
{
foreach ($names as $name) {
$node = new Node($name);
$node = new Node($name);
$this->nodes[$name] = $node;
$this->_calc->addNode($node->id, $node);
}
Expand All @@ -174,7 +203,7 @@ private function addDependency(string $from, string $to, bool $optional = false)
private function computeResult(): array
{
return array_map(static function (Node $n): string {
return $n->name;
return $n->name;
}, array_values($this->_calc->sort()));
}
}
Expand All @@ -190,6 +219,6 @@ class Node
public function __construct(string $name)
{
$this->name = $name;
$this->id = spl_object_id($this);
$this->id = spl_object_id($this);
}
}

0 comments on commit d151000

Please sign in to comment.