From 26b263237ffb95a505833e679ef392329723c99e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 19 Feb 2024 14:21:25 +0100 Subject: [PATCH 1/7] Remove readonly modifiers from NavItem class properties --- .../src/Framework/Features/Navigation/NavItem.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/framework/src/Framework/Features/Navigation/NavItem.php b/packages/framework/src/Framework/Features/Navigation/NavItem.php index a885d3eb9ad..c2b35be9acc 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavItem.php @@ -24,16 +24,16 @@ */ class NavItem implements Stringable { - public readonly Route $destination; - public readonly string $label; - public readonly int $priority; - public readonly ?string $group; + public Route $destination; + public string $label; + public int $priority; + public ?string $group; /** The "slugified" version of the label. */ - public readonly string $identifier; + public string $identifier; /** @var array<\Hyde\Framework\Features\Navigation\NavItem> */ - public readonly array $children; + public array $children; /** * Create a new navigation menu item. From e2a8f366d93326e2039e073179f4eb6cf4396a0e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 19 Feb 2024 14:27:05 +0100 Subject: [PATCH 2/7] Breaking: Make `NavItem::$destination` property protected --- .../components/docs/sidebar-item.blade.php | 4 +-- .../Framework/Features/Navigation/NavItem.php | 2 +- packages/framework/tests/Unit/NavItemTest.php | 30 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/framework/resources/views/components/docs/sidebar-item.blade.php b/packages/framework/resources/views/components/docs/sidebar-item.blade.php index a6da983c180..98e259d0950 100644 --- a/packages/framework/resources/views/components/docs/sidebar-item.blade.php +++ b/packages/framework/resources/views/components/docs/sidebar-item.blade.php @@ -5,7 +5,7 @@ : 'active bg-black/5 dark:bg-black/10' => $item->isCurrent() ]) role="listitem"> @if($item->isCurrent()) - @@ -17,7 +17,7 @@ {!! ($page->getTableOfContents()) !!} @endif @else - diff --git a/packages/framework/src/Framework/Features/Navigation/NavItem.php b/packages/framework/src/Framework/Features/Navigation/NavItem.php index c2b35be9acc..7b996af28c3 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavItem.php @@ -24,7 +24,7 @@ */ class NavItem implements Stringable { - public Route $destination; + protected Route $destination; public string $label; public int $priority; public ?string $group; diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavItemTest.php index 71f6697fc7a..3832cec8874 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavItemTest.php @@ -44,36 +44,36 @@ public function testConstruct() $route = new Route(new MarkdownPage()); $item = new NavItem($route, 'Test', 500); - $this->assertSame($route, $item->destination); + $this->assertSame($route, $item->getDestination()); } public function testPassingRouteInstanceToConstructorUsesRouteInstance() { $route = new Route(new MarkdownPage()); - $this->assertSame($route, (new NavItem($route, 'Home'))->destination); + $this->assertSame($route, (new NavItem($route, 'Home'))->getDestination()); } public function testPassingRouteKeyToConstructorUsesRouteInstance() { $route = Routes::get('index'); - $this->assertSame($route, (new NavItem('index', 'Home'))->destination); + $this->assertSame($route, (new NavItem('index', 'Home'))->getDestination()); } public function testPassingUrlToConstructorUsesExternalRoute() { $item = new NavItem('https://example.com', 'Home'); - $this->assertInstanceOf(ExternalRoute::class, $item->destination); - $this->assertEquals(new ExternalRoute('https://example.com'), $item->destination); - $this->assertSame('https://example.com', (string) $item->destination); + $this->assertInstanceOf(ExternalRoute::class, $item->getDestination()); + $this->assertEquals(new ExternalRoute('https://example.com'), $item->getDestination()); + $this->assertSame('https://example.com', (string) $item->getDestination()); } public function testPassingUnknownRouteKeyToConstructorUsesExternalRoute() { $item = new NavItem('foo', 'Home'); - $this->assertInstanceOf(ExternalRoute::class, $item->destination); - $this->assertEquals(new ExternalRoute('foo'), $item->destination); - $this->assertSame('foo', (string) $item->destination); + $this->assertInstanceOf(ExternalRoute::class, $item->getDestination()); + $this->assertEquals(new ExternalRoute('foo'), $item->getDestination()); + $this->assertSame('foo', (string) $item->getDestination()); } public function testCanConstructWithChildren() @@ -86,7 +86,7 @@ public function testCanConstructWithChildren() $item = new NavItem($route, 'Test', 500, null, $children); $this->assertSame('Test', $item->label); - $this->assertSame($route, $item->destination); + $this->assertSame($route, $item->getDestination()); $this->assertSame(500, $item->priority); $this->assertCount(2, $item->children); @@ -111,7 +111,7 @@ public function testCanConstructWithChildrenWithoutRoute() $item = new NavItem('', 'Test', 500, null, $children); $this->assertSame('Test', $item->label); - $this->assertSame('', $item->destination->getLink()); + $this->assertSame('', $item->getDestination()->getLink()); $this->assertCount(2, $item->children); $this->assertSame($children, $item->children); @@ -171,7 +171,7 @@ public function testFromRoute() $route = new Route(new MarkdownPage()); $item = NavItem::fromRoute($route); - $this->assertSame($route, $item->destination); + $this->assertSame($route, $item->getDestination()); } public function testToString() @@ -185,7 +185,7 @@ public function testForLink() { $item = NavItem::forLink('foo', 'bar'); - $this->assertEquals(new ExternalRoute('foo'), $item->destination); + $this->assertEquals(new ExternalRoute('foo'), $item->getDestination()); $this->assertSame('bar', $item->label); $this->assertSame(500, $item->priority); } @@ -200,7 +200,7 @@ public function testForRoute() $route = Routes::get('404'); $item = NavItem::forRoute($route, 'foo'); - $this->assertSame($route, $item->destination); + $this->assertSame($route, $item->getDestination()); $this->assertSame('foo', $item->label); $this->assertSame(999, $item->priority); } @@ -210,7 +210,7 @@ public function testForIndexRoute() $route = Routes::get('index'); $item = NavItem::forRoute($route, 'foo'); - $this->assertSame($route, $item->destination); + $this->assertSame($route, $item->getDestination()); $this->assertSame('foo', $item->label); $this->assertSame(0, $item->priority); } From 5fa2bb206844314bfa97431e37815acb7cf3e6ec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 19 Feb 2024 14:32:52 +0100 Subject: [PATCH 3/7] Breaking: Make `NavItem::$label` property protected --- .../views/components/docs/sidebar-item.blade.php | 4 ++-- .../navigation/navigation-link.blade.php | 2 +- .../Framework/Features/Navigation/NavItem.php | 2 +- .../tests/Feature/NavigationMenuTest.php | 6 +++--- packages/framework/tests/Unit/NavItemTest.php | 16 ++++++++-------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/framework/resources/views/components/docs/sidebar-item.blade.php b/packages/framework/resources/views/components/docs/sidebar-item.blade.php index 98e259d0950..012947357c0 100644 --- a/packages/framework/resources/views/components/docs/sidebar-item.blade.php +++ b/packages/framework/resources/views/components/docs/sidebar-item.blade.php @@ -9,7 +9,7 @@ ? '-ml-8 pl-4 py-1 px-2 block text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out hover:bg-black/10' : '-ml-4 p-2 block hover:bg-black/5 dark:hover:bg-black/10 text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out' ])> - {{ $item->label }} + {{ $item->getLabel() }} @if(config('docs.table_of_contents.enabled', true)) @@ -21,7 +21,7 @@ ? '-ml-8 pl-4 py-1 px-2 block border-l-[0.325rem] border-transparent transition-colors duration-300 ease-in-out hover:bg-black/10' : 'block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10' ])> - {{ $item->label }} + {{ $item->getLabel() }} @endif \ No newline at end of file diff --git a/packages/framework/resources/views/components/navigation/navigation-link.blade.php b/packages/framework/resources/views/components/navigation/navigation-link.blade.php index cfad8bdb1e2..dbb5407245a 100644 --- a/packages/framework/resources/views/components/navigation/navigation-link.blade.php +++ b/packages/framework/resources/views/components/navigation/navigation-link.blade.php @@ -1,4 +1,4 @@ isCurrent() ? 'aria-current="page"' : '' !!} @class([ 'block my-2 md:my-0 md:inline-block py-1 text-gray-700 hover:text-gray-900 dark:text-gray-100', 'border-l-4 border-indigo-500 md:border-none font-medium -ml-6 pl-5 md:ml-0 md:pl-0 bg-gray-100 dark:bg-gray-800 md:bg-transparent dark:md:bg-transparent' => $item->isCurrent() -])>{{ $item->label }} \ No newline at end of file +])>{{ $item->getLabel() }} \ No newline at end of file diff --git a/packages/framework/src/Framework/Features/Navigation/NavItem.php b/packages/framework/src/Framework/Features/Navigation/NavItem.php index 7b996af28c3..1bd1fe61505 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavItem.php @@ -25,7 +25,7 @@ class NavItem implements Stringable { protected Route $destination; - public string $label; + protected string $label; public int $priority; public ?string $group; diff --git a/packages/framework/tests/Feature/NavigationMenuTest.php b/packages/framework/tests/Feature/NavigationMenuTest.php index e19f0039018..31bb0ad3f19 100644 --- a/packages/framework/tests/Feature/NavigationMenuTest.php +++ b/packages/framework/tests/Feature/NavigationMenuTest.php @@ -46,7 +46,7 @@ public function testItemsAreSortedByPriority() Routes::addRoute(new Route(new MarkdownPage('bar', ['navigation.priority' => 2]))); Routes::addRoute(new Route(new MarkdownPage('baz', ['navigation.priority' => 3]))); - $this->assertSame(['Home', 'Foo', 'Bar', 'Baz'], $this->createNavigationMenu()->getItems()->pluck('label')->toArray()); + $this->assertSame(['Home', 'Foo', 'Bar', 'Baz'], $this->createNavigationMenu()->getItems()->map(fn ($item) => $item->getLabel())->toArray()); } public function testItemsWithHiddenPropertySetToTrueAreNotAdded() @@ -54,7 +54,7 @@ public function testItemsWithHiddenPropertySetToTrueAreNotAdded() Routes::addRoute(new Route(new MarkdownPage('foo', ['navigation.hidden' => true]))); Routes::addRoute(new Route(new MarkdownPage('bar', ['navigation.hidden' => false]))); - $this->assertSame(['Home', 'Bar'], $this->createNavigationMenu()->getItems()->pluck('label')->toArray()); + $this->assertSame(['Home', 'Bar'], $this->createNavigationMenu()->getItems()->map(fn ($item) => $item->getLabel())->toArray()); } public function testCreatedCollectionIsSortedByNavigationMenuPriority() @@ -266,7 +266,7 @@ public function testCanAddItemsToMainNavigationMenuResolvedFromContainer() $navigation->add(new NavItem(new ExternalRoute('/foo'), 'Foo')); $this->assertCount(2, $navigation->getItems()); - $this->assertSame('Foo', $navigation->getItems()->last()->label); + $this->assertSame('Foo', $navigation->getItems()->last()->getLabel()); } protected function createNavigationMenu(): NavigationMenu diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavItemTest.php index 3832cec8874..dd28a2d6e24 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavItemTest.php @@ -85,15 +85,15 @@ public function testCanConstructWithChildren() ]; $item = new NavItem($route, 'Test', 500, null, $children); - $this->assertSame('Test', $item->label); + $this->assertSame('Test', $item->getLabel()); $this->assertSame($route, $item->getDestination()); $this->assertSame(500, $item->priority); $this->assertCount(2, $item->children); $this->assertSame($children, $item->children); - $this->assertSame('Foo', $item->children[0]->label); - $this->assertSame('Bar', $item->children[1]->label); + $this->assertSame('Foo', $item->children[0]->getLabel()); + $this->assertSame('Bar', $item->children[1]->getLabel()); $this->assertSame('foo.html', $item->children[0]->getLink()); $this->assertSame('bar.html', $item->children[1]->getLink()); @@ -110,7 +110,7 @@ public function testCanConstructWithChildrenWithoutRoute() ]; $item = new NavItem('', 'Test', 500, null, $children); - $this->assertSame('Test', $item->label); + $this->assertSame('Test', $item->getLabel()); $this->assertSame('', $item->getDestination()->getLink()); $this->assertCount(2, $item->children); @@ -186,7 +186,7 @@ public function testForLink() $item = NavItem::forLink('foo', 'bar'); $this->assertEquals(new ExternalRoute('foo'), $item->getDestination()); - $this->assertSame('bar', $item->label); + $this->assertSame('bar', $item->getLabel()); $this->assertSame(500, $item->priority); } @@ -201,7 +201,7 @@ public function testForRoute() $item = NavItem::forRoute($route, 'foo'); $this->assertSame($route, $item->getDestination()); - $this->assertSame('foo', $item->label); + $this->assertSame('foo', $item->getLabel()); $this->assertSame(999, $item->priority); } @@ -211,7 +211,7 @@ public function testForIndexRoute() $item = NavItem::forRoute($route, 'foo'); $this->assertSame($route, $item->getDestination()); - $this->assertSame('foo', $item->label); + $this->assertSame('foo', $item->getLabel()); $this->assertSame(0, $item->priority); } @@ -265,7 +265,7 @@ public function testDropdownFacade() { $item = NavItem::dropdown('foo', []); - $this->assertSame('foo', $item->label); + $this->assertSame('foo', $item->getLabel()); $this->assertSame([], $item->getChildren()); $this->assertSame(999, $item->priority); } From d51186d4f902bca0889e3cf2d8e06852df801baf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 19 Feb 2024 15:20:13 +0100 Subject: [PATCH 4/7] Breaking: Make `NavItem::$priority` property protected --- .../GeneratesDocumentationSidebarMenu.php | 2 +- .../GeneratesMainNavigationMenu.php | 2 +- .../Framework/Features/Navigation/NavItem.php | 2 +- .../Features/Navigation/NavigationMenu.php | 2 +- .../Services/DocumentationSidebarTest.php | 4 ++-- packages/framework/tests/Unit/NavItemTest.php | 22 +++++++++---------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/framework/src/Framework/Features/Navigation/GeneratesDocumentationSidebarMenu.php b/packages/framework/src/Framework/Features/Navigation/GeneratesDocumentationSidebarMenu.php index 178dfe4b5f9..43ca0b929db 100644 --- a/packages/framework/src/Framework/Features/Navigation/GeneratesDocumentationSidebarMenu.php +++ b/packages/framework/src/Framework/Features/Navigation/GeneratesDocumentationSidebarMenu.php @@ -87,6 +87,6 @@ protected function canAddRoute(Route $route): bool protected function sortByPriority(): void { - $this->items = $this->items->sortBy('priority')->values(); + $this->items = $this->items->sortBy(fn (NavItem $item) => $item->getPriority())->values(); } } diff --git a/packages/framework/src/Framework/Features/Navigation/GeneratesMainNavigationMenu.php b/packages/framework/src/Framework/Features/Navigation/GeneratesMainNavigationMenu.php index de4e5af2503..b3dda7b9f73 100644 --- a/packages/framework/src/Framework/Features/Navigation/GeneratesMainNavigationMenu.php +++ b/packages/framework/src/Framework/Features/Navigation/GeneratesMainNavigationMenu.php @@ -94,6 +94,6 @@ protected function useSubdirectoriesAsDropdowns(): bool protected function sortByPriority(): void { - $this->items = $this->items->sortBy('priority')->values(); + $this->items = $this->items->sortBy(fn (NavItem $item): int => $item->getPriority())->values(); } } diff --git a/packages/framework/src/Framework/Features/Navigation/NavItem.php b/packages/framework/src/Framework/Features/Navigation/NavItem.php index 1bd1fe61505..bc0c7694fd7 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavItem.php @@ -26,7 +26,7 @@ class NavItem implements Stringable { protected Route $destination; protected string $label; - public int $priority; + protected int $priority; public ?string $group; /** The "slugified" version of the label. */ diff --git a/packages/framework/src/Framework/Features/Navigation/NavigationMenu.php b/packages/framework/src/Framework/Features/Navigation/NavigationMenu.php index ca3021f1336..0c1e610a0e2 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavigationMenu.php +++ b/packages/framework/src/Framework/Features/Navigation/NavigationMenu.php @@ -36,7 +36,7 @@ public function __construct(Arrayable|array $items = []) */ public function getItems(): Collection { - return $this->items->sortBy('priority')->values(); + return $this->items->sortBy(fn (NavItem $item) => $item->getPriority())->values(); } /** diff --git a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php index 4d09e812e2c..ed2df0ba297 100644 --- a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php +++ b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php @@ -114,7 +114,7 @@ public function testSidebarItemPriorityCanBeSetInFrontMatter() { $this->makePage('foo', ['navigation.priority' => 25]); - $this->assertEquals(25, DocumentationSidebar::create()->getItems()->first()->priority); + $this->assertEquals(25, DocumentationSidebar::create()->getItems()->first()->getPriority()); } public function testSidebarItemPrioritySetInConfigOverridesFrontMatter() @@ -123,7 +123,7 @@ public function testSidebarItemPrioritySetInConfigOverridesFrontMatter() Config::set('docs.sidebar_order', ['foo']); - $this->assertEquals(25, DocumentationSidebar::create()->getItems()->first()->priority); + $this->assertEquals(25, DocumentationSidebar::create()->getItems()->first()->getPriority()); } public function testSidebarPrioritiesCanBeSetInBothFrontMatterAndConfig() diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavItemTest.php index dd28a2d6e24..b908101810d 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavItemTest.php @@ -87,7 +87,7 @@ public function testCanConstructWithChildren() $this->assertSame('Test', $item->getLabel()); $this->assertSame($route, $item->getDestination()); - $this->assertSame(500, $item->priority); + $this->assertSame(500, $item->getPriority()); $this->assertCount(2, $item->children); $this->assertSame($children, $item->children); @@ -98,8 +98,8 @@ public function testCanConstructWithChildren() $this->assertSame('foo.html', $item->children[0]->getLink()); $this->assertSame('bar.html', $item->children[1]->getLink()); - $this->assertSame(500, $item->children[0]->priority); - $this->assertSame(500, $item->children[1]->priority); + $this->assertSame(500, $item->children[0]->getPriority()); + $this->assertSame(500, $item->children[1]->getPriority()); } public function testCanConstructWithChildrenWithoutRoute() @@ -187,12 +187,12 @@ public function testForLink() $this->assertEquals(new ExternalRoute('foo'), $item->getDestination()); $this->assertSame('bar', $item->getLabel()); - $this->assertSame(500, $item->priority); + $this->assertSame(500, $item->getPriority()); } public function testForLinkWithCustomPriority() { - $this->assertSame(100, NavItem::forLink('foo', 'bar', 100)->priority); + $this->assertSame(100, NavItem::forLink('foo', 'bar', 100)->getPriority()); } public function testForRoute() @@ -202,7 +202,7 @@ public function testForRoute() $this->assertSame($route, $item->getDestination()); $this->assertSame('foo', $item->getLabel()); - $this->assertSame(999, $item->priority); + $this->assertSame(999, $item->getPriority()); } public function testForIndexRoute() @@ -212,7 +212,7 @@ public function testForIndexRoute() $this->assertSame($route, $item->getDestination()); $this->assertSame('foo', $item->getLabel()); - $this->assertSame(0, $item->priority); + $this->assertSame(0, $item->getPriority()); } public function testForRouteWithRouteKey() @@ -231,7 +231,7 @@ public function testForRouteWithMissingRouteKey() public function testForRouteWithCustomPriority() { - $this->assertSame(100, NavItem::forRoute(Routes::get('index'), 'foo', 100)->priority); + $this->assertSame(100, NavItem::forRoute(Routes::get('index'), 'foo', 100)->getPriority()); } public function testRouteBasedNavItemDestinationsAreResolvedRelatively() @@ -267,7 +267,7 @@ public function testDropdownFacade() $this->assertSame('foo', $item->getLabel()); $this->assertSame([], $item->getChildren()); - $this->assertSame(999, $item->priority); + $this->assertSame(999, $item->getPriority()); } public function testDropdownFacadeWithChildren() @@ -278,14 +278,14 @@ public function testDropdownFacadeWithChildren() $item = NavItem::dropdown('foo', $children); $this->assertSame($children, $item->getChildren()); - $this->assertSame(999, $item->priority); + $this->assertSame(999, $item->getPriority()); } public function testDropdownFacadeWithCustomPriority() { $item = NavItem::dropdown('foo', [], 500); - $this->assertSame(500, $item->priority); + $this->assertSame(500, $item->getPriority()); } public function testHasChildren() From 597e6c6e7cf6fdc9e56588b0605be354fc0db603 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 19 Feb 2024 15:40:00 +0100 Subject: [PATCH 5/7] Breaking: Make `NavItem::$group` property protected --- .../framework/src/Framework/Features/Navigation/NavItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Navigation/NavItem.php b/packages/framework/src/Framework/Features/Navigation/NavItem.php index bc0c7694fd7..3f096d557ed 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavItem.php @@ -27,7 +27,7 @@ class NavItem implements Stringable protected Route $destination; protected string $label; protected int $priority; - public ?string $group; + protected ?string $group; /** The "slugified" version of the label. */ public string $identifier; From 55da9624572e1ab2ec1e97425b40e567067cecf5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 19 Feb 2024 15:44:01 +0100 Subject: [PATCH 6/7] Breaking: Make `NavItem::$children` property protected --- .../Framework/Features/Navigation/NavItem.php | 2 +- packages/framework/tests/Unit/NavItemTest.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/framework/src/Framework/Features/Navigation/NavItem.php b/packages/framework/src/Framework/Features/Navigation/NavItem.php index 3f096d557ed..ce42587f8f3 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavItem.php @@ -33,7 +33,7 @@ class NavItem implements Stringable public string $identifier; /** @var array<\Hyde\Framework\Features\Navigation\NavItem> */ - public array $children; + protected array $children; /** * Create a new navigation menu item. diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavItemTest.php index b908101810d..82a4023243d 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavItemTest.php @@ -89,17 +89,17 @@ public function testCanConstructWithChildren() $this->assertSame($route, $item->getDestination()); $this->assertSame(500, $item->getPriority()); - $this->assertCount(2, $item->children); - $this->assertSame($children, $item->children); + $this->assertCount(2, $item->getChildren()); + $this->assertSame($children, $item->getChildren()); - $this->assertSame('Foo', $item->children[0]->getLabel()); - $this->assertSame('Bar', $item->children[1]->getLabel()); + $this->assertSame('Foo', $item->getChildren()[0]->getLabel()); + $this->assertSame('Bar', $item->getChildren()[1]->getLabel()); - $this->assertSame('foo.html', $item->children[0]->getLink()); - $this->assertSame('bar.html', $item->children[1]->getLink()); + $this->assertSame('foo.html', $item->getChildren()[0]->getLink()); + $this->assertSame('bar.html', $item->getChildren()[1]->getLink()); - $this->assertSame(500, $item->children[0]->getPriority()); - $this->assertSame(500, $item->children[1]->getPriority()); + $this->assertSame(500, $item->getChildren()[0]->getPriority()); + $this->assertSame(500, $item->getChildren()[1]->getPriority()); } public function testCanConstructWithChildrenWithoutRoute() @@ -113,8 +113,8 @@ public function testCanConstructWithChildrenWithoutRoute() $this->assertSame('Test', $item->getLabel()); $this->assertSame('', $item->getDestination()->getLink()); - $this->assertCount(2, $item->children); - $this->assertSame($children, $item->children); + $this->assertCount(2, $item->getChildren()); + $this->assertSame($children, $item->getChildren()); } public function testGetDestination() From 482ac8a32f48accef23f334ab8b6e683be11baf7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 19 Feb 2024 15:46:15 +0100 Subject: [PATCH 7/7] Add accessor for the identifier and protect the property Not breaking as it is a new property --- .../src/Framework/Features/Navigation/NavItem.php | 10 +++++++++- packages/framework/tests/Unit/NavItemTest.php | 10 +++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/framework/src/Framework/Features/Navigation/NavItem.php b/packages/framework/src/Framework/Features/Navigation/NavItem.php index ce42587f8f3..0b290e3ca32 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/NavItem.php @@ -30,7 +30,7 @@ class NavItem implements Stringable protected ?string $group; /** The "slugified" version of the label. */ - public string $identifier; + protected string $identifier; /** @var array<\Hyde\Framework\Features\Navigation\NavItem> */ protected array $children; @@ -149,6 +149,14 @@ public function getGroup(): ?string return $this->group; } + /** + * Get the identifier of the navigation item. + */ + public function getIdentifier(): string + { + return $this->identifier; + } + /** * Get the children of the navigation item. * diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavItemTest.php index 82a4023243d..49670868bb9 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavItemTest.php @@ -354,7 +354,7 @@ public function testIdentifier() $route = new Route(new MarkdownPage()); $item = new NavItem($route, 'Test', 500); - $this->assertSame('test', $item->identifier); + $this->assertSame('test', $item->getIdentifier()); } public function testIdentifierWithCustomLabel() @@ -362,13 +362,13 @@ public function testIdentifierWithCustomLabel() $route = new Route(new MarkdownPage()); $item = new NavItem($route, 'Foo Bar', 500); - $this->assertSame('foo-bar', $item->identifier); + $this->assertSame('foo-bar', $item->getIdentifier()); } public function testIdentifierFromRouteKey() { $item = NavItem::fromRoute(Routes::get('index')); - $this->assertSame('home', $item->identifier); + $this->assertSame('home', $item->getIdentifier()); } public function testIdentifierUsesLabelWhenRouteKeyIsFalsy() @@ -376,12 +376,12 @@ public function testIdentifierUsesLabelWhenRouteKeyIsFalsy() $route = new Route(new MarkdownPage()); $item = new NavItem($route, 'Foo Bar', 500); - $this->assertSame('foo-bar', $item->identifier); + $this->assertSame('foo-bar', $item->getIdentifier()); } public function testIdentifierUsesLabelForExternalRoute() { $item = NavItem::forLink('https://example.com', 'Foo Bar'); - $this->assertSame('foo-bar', $item->identifier); + $this->assertSame('foo-bar', $item->getIdentifier()); } }