Skip to content

Commit 028c742

Browse files
committed
Strengthen AbstractPage tests to kill Coalesce mutations
Add two tests that exercise both sides of coalesce expressions simultaneously: - test_parent_page_is_checked_before_parent_page_data_in_cycle_detection: sets parentPage (cyclic) and parentPageData (safe) together; swapping the ?? order would miss the cycle and the test would fail - test_get_parent_page_route_prefers_parent_page_over_parent_page_data: sets routes on both parents; swapping the ?? order returns the wrong route
1 parent 9723f3f commit 028c742

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/Entity/Core/AbstractPageTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ public function test_cycle_via_parent_page_data_reports_correct_field(): void
135135
$pageData->validateNoCircularParent($this->makeContext(1, 'parentPageData'));
136136
}
137137

138+
public function test_parent_page_is_checked_before_parent_page_data_in_cycle_detection(): void
139+
{
140+
// parentPage creates a cycle; parentPageData does not.
141+
// If the coalesce order were swapped ($parentPageData ?? $parentPage) the cycle
142+
// would be missed because parentPageData has no parent chain.
143+
$subject = $this->makePage('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
144+
$cyclingParent = $this->makePage('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb');
145+
$cyclingParent->setParentPage($subject); // creates A→B→A cycle
146+
147+
$safePageData = new TestPageData();
148+
$safePageData->withId(Uuid::fromString('cccccccc-cccc-cccc-cccc-cccccccccccc'));
149+
// safePageData has no parent — no cycle
150+
151+
$subject->setParentPage($cyclingParent);
152+
$subject->setParentPageData($safePageData); // both set (invalid in production, valid for unit testing logic)
153+
154+
$subject->validateNoCircularParent($this->makeContext(1, 'parentPage'));
155+
}
156+
138157
public function test_get_parent_page_route_returns_parent_route(): void
139158
{
140159
$route = new Route();
@@ -147,6 +166,31 @@ public function test_get_parent_page_route_returns_parent_route(): void
147166
$this->assertSame($route, $child->getParentPageRoute());
148167
}
149168

169+
public function test_get_parent_page_route_prefers_parent_page_over_parent_page_data(): void
170+
{
171+
// Exercises the coalesce in getParentPageRoute: parentPage?->getRoute() ?? parentPageData?->getRoute()
172+
// Both parents have routes; the parentPage route must win.
173+
// A swapped coalesce (parentPageData?->getRoute() ?? parentPage?->getRoute()) would return routeB instead.
174+
$routeA = new Route();
175+
$routeA->setPath('/page-route');
176+
177+
$routeB = new Route();
178+
$routeB->setPath('/pagedata-route');
179+
180+
$parentPage = $this->makePage('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb');
181+
$parentPage->setRoute($routeA);
182+
183+
$parentPageData = new TestPageData();
184+
$parentPageData->withId(Uuid::fromString('cccccccc-cccc-cccc-cccc-cccccccccccc'));
185+
$parentPageData->setRoute($routeB);
186+
187+
$child = $this->makePage('dddddddd-dddd-dddd-dddd-dddddddddddd');
188+
$child->setParentPage($parentPage);
189+
$child->setParentPageData($parentPageData);
190+
191+
$this->assertSame($routeA, $child->getParentPageRoute());
192+
}
193+
150194
public function test_get_parent_page_route_returns_null_when_parent_has_no_route(): void
151195
{
152196
$parent = $this->makePage('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb');

0 commit comments

Comments
 (0)