From d1510009a96aa0ad54debd6868d906481ebbb989 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Tue, 28 Feb 2023 09:11:49 +0000 Subject: [PATCH] Add tests for #8349 --- .../Tests/ORM/CommitOrderCalculatorTest.php | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php index 7da48a57df..22e9303a4b 100644 --- a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php +++ b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php @@ -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; @@ -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'); @@ -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); } @@ -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())); } } @@ -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); } }