Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not rely on autoincremental ids in materialized path tests #2684

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading