From 915f482881a84a96d26b5b61838f9d01ba71d78d Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 29 Aug 2023 11:52:03 +0200 Subject: [PATCH] Do not rely on autoincremental id in materialized path tests --- tests/Gedmo/Tree/MaterializedPathORMTest.php | 27 +++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/Gedmo/Tree/MaterializedPathORMTest.php b/tests/Gedmo/Tree/MaterializedPathORMTest.php index f2071eda24..867f1f8b0a 100644 --- a/tests/Gedmo/Tree/MaterializedPathORMTest.php +++ b/tests/Gedmo/Tree/MaterializedPathORMTest.php @@ -87,10 +87,10 @@ public function testInsertUpdateAndRemove(): void static::assertSame(3, $category3->getLevel()); static::assertSame(1, $category4->getLevel()); - static::assertSame('1-4', $category->getTreeRootValue()); - static::assertSame('1-4', $category2->getTreeRootValue()); - static::assertSame('1-4', $category3->getTreeRootValue()); - static::assertSame('4-1', $category4->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category), $category->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category2), $category2->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category3), $category3->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category4), $category4->getTreeRootValue()); // Update $category2->setParent(null); @@ -110,10 +110,10 @@ public function testInsertUpdateAndRemove(): void static::assertSame(2, $category3->getLevel()); static::assertSame(1, $category4->getLevel()); - static::assertSame('1-4', $category->getTreeRootValue()); - static::assertSame('2-3', $category2->getTreeRootValue()); - static::assertSame('2-3', $category3->getTreeRootValue()); - static::assertSame('4-1', $category4->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category), $category->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category2), $category2->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category3), $category3->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($category4), $category4->getTreeRootValue()); // Remove $this->em->remove($category); @@ -127,7 +127,7 @@ public function testInsertUpdateAndRemove(): void static::assertCount(1, $result); static::assertSame('4', $firstResult->getTitle()); static::assertSame(1, $firstResult->getLevel()); - static::assertSame('4-1', $firstResult->getTreeRootValue()); + static::assertSame($this->getTreeRootValueOfRootNode($firstResult), $firstResult->getTreeRootValue()); } public function testUseOfSeparatorInPathSourceShouldThrowAnException(): void @@ -165,4 +165,13 @@ protected function getUsedEntityFixtures(): array self::CATEGORY, ]; } + + private function getTreeRootValueOfRootNode(MPCategory $category): string + { + while (null !== $category->getParent()) { + $category = $category->getParent(); + } + + return $category->getTreeRootValue(); + } }