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 Aug 29, 2023
1 parent 98ebb3f commit d327807
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->generateTreeNodeValue($category), $category->getTreeRootValue());
static::assertSame($this->generateTreeNodeValue($category2), $category2->getTreeRootValue());
static::assertSame($this->generateTreeNodeValue($category3), $category3->getTreeRootValue());
static::assertSame($this->generateTreeNodeValue($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->generateTreeNodeValue($category), $category->getTreeRootValue());
static::assertSame($this->generateTreeNodeValue($category2), $category2->getTreeRootValue());
static::assertSame($this->generateTreeNodeValue($category3), $category3->getTreeRootValue());
static::assertSame($this->generateTreeNodeValue($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->generateTreeNodeValue($firstResult), $firstResult->getTreeRootValue());
}

public function testUseOfSeparatorInPathSourceShouldThrowAnException(): void
Expand Down Expand Up @@ -159,6 +159,15 @@ public function generatePath(array $sources): string
return $path;
}

private function generateTreeNodeValue(MPCategory $category): string
{
while ($category->getParent() !== null) {
$category = $category->getParent();
}

return $category->getTreeRootValue();
}

protected function getUsedEntityFixtures(): array
{
return [
Expand Down

0 comments on commit d327807

Please sign in to comment.