Skip to content

Commit

Permalink
Do not rely on autoincremental id in materialized path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Sep 3, 2023
1 parent 98ebb3f commit 915f482
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tests/Gedmo/Tree/MaterializedPathORMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 915f482

Please sign in to comment.