From 1edb2f2255da8cec7060edddd9dff94114e2b54c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 29 Feb 2024 19:50:07 +0100 Subject: [PATCH] Replace all usages of `fromRoute` with `forRoute` --- .../Navigation/NavigationMenuGenerator.php | 6 +-- .../tests/Feature/NavigationMenuTest.php | 44 +++++++++---------- .../Services/DocumentationSidebarTest.php | 32 +++++++------- .../Unit/DocumentationSidebarUnitTest.php | 2 +- .../tests/Unit/NavItemIsCurrentHelperTest.php | 26 +++++------ packages/framework/tests/Unit/NavItemTest.php | 24 +++++----- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php b/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php index bf82a3bbd5c..342a696d96b 100644 --- a/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php +++ b/packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php @@ -71,7 +71,7 @@ protected function generate(): void if ($this->canGroupRoute($route)) { $this->addRouteToGroup($route); } else { - $this->items->put($route->getRouteKey(), NavItem::fromRoute($route)); + $this->items->put($route->getRouteKey(), NavItem::forRoute($route)); } } }); @@ -79,7 +79,7 @@ protected function generate(): void if ($this->generatesSidebar) { // If there are no pages other than the index page, we add it to the sidebar so that it's not empty if ($this->items->count() === 0 && DocumentationPage::home() !== null) { - $this->items->push(NavItem::fromRoute(DocumentationPage::home())); + $this->items->push(NavItem::forRoute(DocumentationPage::home())); } } else { collect(Config::getArray('hyde.navigation.custom', []))->each(function (NavItem $item): void { @@ -133,7 +133,7 @@ protected function canGroupRoute(Route $route): bool protected function addRouteToGroup(Route $route): void { - $item = NavItem::fromRoute($route); + $item = NavItem::forRoute($route); $groupName = $this->generatesSidebar ? ($item->getGroup() ?? 'Other') : $item->getGroup(); diff --git a/packages/framework/tests/Feature/NavigationMenuTest.php b/packages/framework/tests/Feature/NavigationMenuTest.php index 2163dce6d6d..2bd704cc40e 100644 --- a/packages/framework/tests/Feature/NavigationMenuTest.php +++ b/packages/framework/tests/Feature/NavigationMenuTest.php @@ -38,7 +38,7 @@ public function testGenerateMethodCreatesCollectionOfNavItems() public function testGetItemsReturnsItems() { $this->assertEquals(collect([ - NavItem::fromRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('index')), ]), $this->createNavigationMenu()->getItems()); } @@ -67,9 +67,9 @@ public function testCreatedCollectionIsSortedByNavigationMenuPriority() $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), - NavItem::fromRoute(Routes::get('foo')), - NavItem::fromRoute(Routes::get('docs/index')), + NavItem::forRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('foo')), + NavItem::forRoute(Routes::get('docs/index')), ]); $this->assertCount(count($expected), $menu->getItems()); @@ -83,8 +83,8 @@ public function testIsSortedAutomaticallyWhenUsingNavigationMenuCreate() $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), - NavItem::fromRoute(Routes::get('foo')), + NavItem::forRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('foo')), ]); $this->assertCount(count($expected), $menu->getItems()); @@ -98,7 +98,7 @@ public function testExternalLinkCanBeAddedInConfig() $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('index')), NavItem::forLink('https://example.com', 'foo'), ]); @@ -113,7 +113,7 @@ public function testPathLinkCanBeAddedInConfig() $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('index')), NavItem::forLink('foo', 'foo'), ]); @@ -131,7 +131,7 @@ public function testDuplicatesAreNotRemovedWhenAddingInConfig() $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('index')), NavItem::forLink('foo', 'foo'), NavItem::forLink('foo', 'foo'), ]); @@ -150,7 +150,7 @@ public function testDuplicatesAreNotRemovedWhenAddingInConfigRegardlessOfDestina $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('index')), NavItem::forLink('foo', 'foo'), NavItem::forLink('bar', 'foo'), ]); @@ -168,9 +168,9 @@ public function testConfigItemsTakePrecedenceOverGeneratedItems() $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('index')), NavItem::forLink('bar', 'Foo'), - NavItem::fromRoute(Routes::get('foo')), + NavItem::forRoute(Routes::get('foo')), ]); $this->assertCount(count($expected), $menu->getItems()); @@ -185,8 +185,8 @@ public function testDocumentationPagesThatAreNotIndexAreNotAddedToTheMenu() $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), - NavItem::fromRoute(Routes::get('docs/index')), + NavItem::forRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('docs/index')), ]); $this->assertCount(count($expected), $menu->getItems()); @@ -199,7 +199,7 @@ public function testPagesInSubdirectoriesAreNotAddedToTheNavigationMenu() $this->file('_pages/foo/bar.md'); $menu = $this->createNavigationMenu(); - $expected = collect([NavItem::fromRoute(Routes::get('index'))]); + $expected = collect([NavItem::forRoute(Routes::get('index'))]); $this->assertCount(count($expected), $menu->getItems()); $this->assertEquals($expected, $menu->getItems()); @@ -213,8 +213,8 @@ public function testPagesInSubdirectoriesCanBeAddedToTheNavigationMenuWithConfig $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), - NavItem::fromRoute(Routes::get('foo/bar')), + NavItem::forRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('foo/bar')), ]); $this->assertCount(count($expected), $menu->getItems()); @@ -229,9 +229,9 @@ public function testPagesInSubdirectoriesAreNotAddedToTheNavigationMenuWithConfi $menu = $this->createNavigationMenu(); $expected = collect([ - NavItem::fromRoute(Routes::get('index')), + NavItem::forRoute(Routes::get('index')), NavItem::forGroup('Foo', [ - NavItem::fromRoute(Routes::get('foo/bar')), + NavItem::forRoute(Routes::get('foo/bar')), ]), ]); @@ -249,10 +249,10 @@ public function testPagesInDropdownsDoNotGetAddedToTheMainNavigation() $this->assertCount(3, $menu->getItems()); $this->assertEquals([ - NavItem::fromRoute(Routes::get('index')), - NavItem::fromRoute((new MarkdownPage('foo'))->getRoute()), + NavItem::forRoute(Routes::get('index')), + NavItem::forRoute((new MarkdownPage('foo'))->getRoute()), NavItem::forGroup('Bar', [ - NavItem::fromRoute((new MarkdownPage('bar/baz'))->getRoute()), + NavItem::forRoute((new MarkdownPage('bar/baz'))->getRoute()), ]), ], $menu->getItems()->all()); } diff --git a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php index b2da470a8c5..5195d1f3fdc 100644 --- a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php +++ b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php @@ -86,9 +86,9 @@ public function testSidebarIsOrderedAlphabeticallyWhenNoOrderIsSetInConfig() $this->assertEquals( collect([ - NavItem::fromRoute(Routes::get('docs/a'), priority: 999), - NavItem::fromRoute(Routes::get('docs/b'), priority: 999), - NavItem::fromRoute(Routes::get('docs/c'), priority: 999), + NavItem::forRoute(Routes::get('docs/a'), priority: 999), + NavItem::forRoute(Routes::get('docs/b'), priority: 999), + NavItem::forRoute(Routes::get('docs/c'), priority: 999), ]), NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems() ); @@ -107,9 +107,9 @@ public function testSidebarIsOrderedByPriorityWhenPriorityIsSetInConfig() $this->assertEquals( collect([ - NavItem::fromRoute(Routes::get('docs/c'), priority: 250 + 250), - NavItem::fromRoute(Routes::get('docs/b'), priority: 250 + 251), - NavItem::fromRoute(Routes::get('docs/a'), priority: 250 + 252), + NavItem::forRoute(Routes::get('docs/c'), priority: 250 + 250), + NavItem::forRoute(Routes::get('docs/b'), priority: 250 + 251), + NavItem::forRoute(Routes::get('docs/a'), priority: 250 + 252), ]), NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems() ); @@ -146,9 +146,9 @@ public function testSidebarPrioritiesCanBeSetInBothFrontMatterAndConfig() $this->assertEquals( collect([ - NavItem::fromRoute(Routes::get('docs/first'), priority: 250 + 250), - NavItem::fromRoute(Routes::get('docs/second'), priority: 250 + 252), - NavItem::fromRoute(Routes::get('docs/third'), priority: 250 + 300), + NavItem::forRoute(Routes::get('docs/first'), priority: 250 + 250), + NavItem::forRoute(Routes::get('docs/second'), priority: 250 + 252), + NavItem::forRoute(Routes::get('docs/third'), priority: 250 + 300), ]), NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems() ); @@ -195,7 +195,7 @@ public function testGetItemsInGroupDoesNotIncludeDocsIndex() Filesystem::touch('_docs/index.md'); $this->assertEquals( - collect([NavItem::fromRoute(Routes::get('docs/foo'), priority: 999)]), + collect([NavItem::forRoute(Routes::get('docs/foo'), priority: 999)]), NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems() ); } @@ -268,10 +268,10 @@ public function testCanHaveMultipleGroupedPagesWithTheSameNameLabels() $this->assertEquals( collect([ NavItem::forGroup('Bar', [ - NavItem::fromRoute(Routes::get('docs/bar'), priority: 999), + NavItem::forRoute(Routes::get('docs/bar'), priority: 999), ]), NavItem::forGroup('Foo', [ - NavItem::fromRoute(Routes::get('docs/foo'), priority: 999), + NavItem::forRoute(Routes::get('docs/foo'), priority: 999), ]), ]), $sidebar->getItems() @@ -289,8 +289,8 @@ public function testDuplicateLabelsWithinTheSameGroupAreNotRemoved() $this->assertEquals( collect([ NavItem::forGroup('Foo', [ - NavItem::fromRoute(Routes::get('docs/bar'), priority: 999), - NavItem::fromRoute(Routes::get('docs/foo'), priority: 999), + NavItem::forRoute(Routes::get('docs/bar'), priority: 999), + NavItem::forRoute(Routes::get('docs/foo'), priority: 999), ]), ]), $sidebar->getItems() @@ -312,7 +312,7 @@ public function testIndexPageAddedToSidebarWhenItIsTheOnlyPage() $this->assertCount(1, $sidebar->getItems()); $this->assertEquals( - collect([NavItem::fromRoute(Routes::get('docs/index'))]), + collect([NavItem::forRoute(Routes::get('docs/index'))]), $sidebar->getItems() ); } @@ -325,7 +325,7 @@ public function testIndexPageNotAddedToSidebarWhenOtherPagesExist() $this->assertCount(1, $sidebar->getItems()); $this->assertEquals( - collect([NavItem::fromRoute(Routes::get('docs/test-0'))]), + collect([NavItem::forRoute(Routes::get('docs/test-0'))]), $sidebar->getItems() ); } diff --git a/packages/framework/tests/Unit/DocumentationSidebarUnitTest.php b/packages/framework/tests/Unit/DocumentationSidebarUnitTest.php index fc3b74ea55f..ee75d74d943 100644 --- a/packages/framework/tests/Unit/DocumentationSidebarUnitTest.php +++ b/packages/framework/tests/Unit/DocumentationSidebarUnitTest.php @@ -226,7 +226,7 @@ public function testHasGroupsReturnsTrueWhenAtLeastOneItemHasChildren() $page = new DocumentationPage('foo'); $child = new DocumentationPage('bar'); $menu = new DocumentationSidebar([ - NavItem::fromRoute($page->getRoute())->addChild(NavItem::fromRoute($child->getRoute())), + NavItem::forRoute($page->getRoute())->addChild(NavItem::forRoute($child->getRoute())), ]); $this->assertTrue($menu->hasGroups()); diff --git a/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php b/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php index d9500006247..97aa4de6f6f 100644 --- a/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php +++ b/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php @@ -34,19 +34,19 @@ protected function tearDown(): void public function testIsCurrent() { $this->mockRenderData($this->makeRoute('foo')); - $this->assertFalse(NavItem::fromRoute($this->makeRoute('bar'))->isCurrent()); + $this->assertFalse(NavItem::forRoute($this->makeRoute('bar'))->isCurrent()); } public function testIsCurrentWhenCurrent() { $this->mockRenderData($this->makeRoute('foo')); - $this->assertTrue(NavItem::fromRoute($this->makeRoute('foo'))->isCurrent()); + $this->assertTrue(NavItem::forRoute($this->makeRoute('foo'))->isCurrent()); } public function testIsCurrentUsingCurrentRoute() { $this->mockRenderData($this->makeRoute('index')); - $this->assertTrue(NavItem::fromRoute(Routes::get('index'))->isCurrent()); + $this->assertTrue(NavItem::forRoute(Routes::get('index'))->isCurrent()); } public function testIsCurrentUsingCurrentLink() @@ -58,13 +58,13 @@ public function testIsCurrentUsingCurrentLink() public function testIsCurrentWhenNotCurrent() { $this->mockRenderData($this->makeRoute('foo')); - $this->assertFalse(NavItem::fromRoute($this->makeRoute('bar'))->isCurrent()); + $this->assertFalse(NavItem::forRoute($this->makeRoute('bar'))->isCurrent()); } public function testIsCurrentUsingNotCurrentRoute() { $this->mockRenderData($this->makeRoute('foo')); - $this->assertFalse(NavItem::fromRoute(Routes::get('index'))->isCurrent()); + $this->assertFalse(NavItem::forRoute(Routes::get('index'))->isCurrent()); } public function testIsCurrentUsingNotCurrentLink() @@ -76,49 +76,49 @@ public function testIsCurrentUsingNotCurrentLink() public function testIsCurrentWithNestedCurrentPage() { $this->mockRenderData($this->makeRoute('foo/bar')); - $this->assertFalse(NavItem::fromRoute($this->makeRoute('bar'))->isCurrent()); + $this->assertFalse(NavItem::forRoute($this->makeRoute('bar'))->isCurrent()); } public function testIsCurrentWhenCurrentWithNestedCurrentPage() { $this->mockRenderData($this->makeRoute('foo/bar')); - $this->assertTrue(NavItem::fromRoute($this->makeRoute('foo/bar'))->isCurrent()); + $this->assertTrue(NavItem::forRoute($this->makeRoute('foo/bar'))->isCurrent()); } public function testIsCurrentWithNestedCurrentPageWhenNested() { $this->mockRenderData($this->makeRoute('foo/bar')); - $this->assertTrue(NavItem::fromRoute($this->makeRoute('foo/bar'))->isCurrent()); + $this->assertTrue(NavItem::forRoute($this->makeRoute('foo/bar'))->isCurrent()); } public function testIsCurrentWhenCurrentWithNestedCurrentPageWhenNested() { $this->mockRenderData($this->makeRoute('foo/bar')); - $this->assertFalse(NavItem::fromRoute($this->makeRoute('foo/baz'))->isCurrent()); + $this->assertFalse(NavItem::forRoute($this->makeRoute('foo/baz'))->isCurrent()); } public function testIsCurrentWithNestedCurrentPageWhenVeryNested() { $this->mockRenderData($this->makeRoute('foo/bar/baz')); - $this->assertTrue(NavItem::fromRoute($this->makeRoute('foo/bar/baz'))->isCurrent()); + $this->assertTrue(NavItem::forRoute($this->makeRoute('foo/bar/baz'))->isCurrent()); } public function testIsCurrentWhenCurrentWithNestedCurrentPageWhenVeryNested() { $this->mockRenderData($this->makeRoute('foo/bar/baz')); - $this->assertFalse(NavItem::fromRoute($this->makeRoute('foo/baz/bar'))->isCurrent()); + $this->assertFalse(NavItem::forRoute($this->makeRoute('foo/baz/bar'))->isCurrent()); } public function testIsCurrentWithNestedCurrentPageWhenVeryDifferingNested() { $this->mockRenderData($this->makeRoute('foo')); - $this->assertFalse(NavItem::fromRoute($this->makeRoute('foo/bar/baz'))->isCurrent()); + $this->assertFalse(NavItem::forRoute($this->makeRoute('foo/bar/baz'))->isCurrent()); } public function testIsCurrentWithNestedCurrentPageWhenVeryDifferingNestedInverse() { $this->mockRenderData($this->makeRoute('foo/bar/baz')); - $this->assertFalse(NavItem::fromRoute($this->makeRoute('foo'))->isCurrent()); + $this->assertFalse(NavItem::forRoute($this->makeRoute('foo'))->isCurrent()); } public function testIsCurrentUsingCurrentLinkWithNestedCurrentPage() diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavItemTest.php index 1816633e0d1..525dad28367 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavItemTest.php @@ -169,7 +169,7 @@ public function testGetChildrenWithNoChildren() public function testFromRoute() { $route = new Route(new MarkdownPage()); - $item = NavItem::fromRoute($route); + $item = NavItem::forRoute($route); $this->assertSame($route, $item->getDestination()); } @@ -178,7 +178,7 @@ public function testToString() { Render::shouldReceive('getRouteKey')->once()->andReturn('index'); - $this->assertSame('index.html', (string) NavItem::fromRoute(Routes::get('index'))); + $this->assertSame('index.html', (string) NavItem::forRoute(Routes::get('index'))); } public function testForLink() @@ -241,24 +241,24 @@ public function testRouteBasedNavItemDestinationsAreResolvedRelatively() 'getRouteKey' => 'foo', ])); - $this->assertSame('foo.html', (string) NavItem::fromRoute(new Route(new InMemoryPage('foo')))); - $this->assertSame('foo/bar.html', (string) NavItem::fromRoute(new Route(new InMemoryPage('foo/bar')))); + $this->assertSame('foo.html', (string) NavItem::forRoute(new Route(new InMemoryPage('foo')))); + $this->assertSame('foo/bar.html', (string) NavItem::forRoute(new Route(new InMemoryPage('foo/bar')))); Render::swap(Mockery::mock(RenderData::class, [ 'getRoute' => new Route(new InMemoryPage('foo/bar')), 'getRouteKey' => 'foo/bar', ])); - $this->assertSame('../foo.html', (string) NavItem::fromRoute(new Route(new InMemoryPage('foo')))); - $this->assertSame('../foo/bar.html', (string) NavItem::fromRoute(new Route(new InMemoryPage('foo/bar')))); + $this->assertSame('../foo.html', (string) NavItem::forRoute(new Route(new InMemoryPage('foo')))); + $this->assertSame('../foo/bar.html', (string) NavItem::forRoute(new Route(new InMemoryPage('foo/bar')))); Render::swap(Mockery::mock(RenderData::class, [ 'getRoute' => new Route(new InMemoryPage('foo/bar/baz')), 'getRouteKey' => 'foo/bar/baz', ])); - $this->assertSame('../../foo.html', (string) NavItem::fromRoute(new Route(new InMemoryPage('foo')))); - $this->assertSame('../../foo/bar.html', (string) NavItem::fromRoute(new Route(new InMemoryPage('foo/bar')))); + $this->assertSame('../../foo.html', (string) NavItem::forRoute(new Route(new InMemoryPage('foo')))); + $this->assertSame('../../foo/bar.html', (string) NavItem::forRoute(new Route(new InMemoryPage('foo/bar')))); } public function testDropdownFacade() @@ -309,8 +309,8 @@ public function testIsCurrent() 'getRoute' => new Route(new InMemoryPage('foo')), 'getRouteKey' => 'foo', ])); - $this->assertTrue(NavItem::fromRoute(new Route(new InMemoryPage('foo')))->isCurrent()); - $this->assertFalse(NavItem::fromRoute(new Route(new InMemoryPage('bar')))->isCurrent()); + $this->assertTrue(NavItem::forRoute(new Route(new InMemoryPage('foo')))->isCurrent()); + $this->assertFalse(NavItem::forRoute(new Route(new InMemoryPage('bar')))->isCurrent()); } public function testIsCurrentWithExternalRoute() @@ -335,7 +335,7 @@ public function testGetGroupWithGroup() public function testGetGroupFromRouteWithGroup() { - $this->assertSame('foo', NavItem::fromRoute(new Route(new MarkdownPage(matter: ['navigation.group' => 'foo'])))->getGroup()); + $this->assertSame('foo', NavItem::forRoute(new Route(new MarkdownPage(matter: ['navigation.group' => 'foo'])))->getGroup()); } public function testGetGroupForRouteWithGroup() @@ -367,7 +367,7 @@ public function testIdentifierWithCustomLabel() public function testIdentifierFromRouteKey() { - $item = NavItem::fromRoute(Routes::get('index')); + $item = NavItem::forRoute(Routes::get('index')); $this->assertSame('home', $item->getIdentifier()); }