From 5e790a7f30bcf1f0f100ec769f51bae611039fc0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:10:40 +0200 Subject: [PATCH 001/222] Rename private helper method --- .../framework/src/Framework/Factories/BlogPostDataFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php index 667800b0718..8ff2fbef5aa 100644 --- a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php +++ b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php @@ -110,10 +110,10 @@ protected function makeImage(): ?FeaturedImage private function makeDescriptionFromMarkdownBody(): string { - return $this->getTruncatedMarkdown($this->stripMarkdownFromBody($this->markdown->body())); + return $this->truncateMarkdown($this->stripMarkdownFromBody($this->markdown->body())); } - private function getTruncatedMarkdown(string $markdown): string + private function truncateMarkdown(string $markdown): string { if (strlen($markdown) >= 128) { return substr($markdown, 0, 125).'...'; From f4e4da41da96ab905d64d3c6abb6a2e19fe9c4cd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:12:39 +0200 Subject: [PATCH 002/222] Use Laravel string limiting for truncation Should have the same results --- .../src/Framework/Factories/BlogPostDataFactory.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php index 8ff2fbef5aa..4eb9b1b818a 100644 --- a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php +++ b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Factories; +use Illuminate\Support\Str; use Hyde\Framework\Factories\Concerns\CoreDataObject; use Hyde\Framework\Actions\ConvertsMarkdownToPlainText; use Hyde\Framework\Features\Blogging\Models\FeaturedImage; @@ -13,9 +14,6 @@ use Hyde\Markdown\Models\Markdown; use Hyde\Support\Models\DateString; -use function strlen; -use function substr; - /** * Streamlines the data construction specific to a blog post. * @@ -115,11 +113,7 @@ private function makeDescriptionFromMarkdownBody(): string private function truncateMarkdown(string $markdown): string { - if (strlen($markdown) >= 128) { - return substr($markdown, 0, 125).'...'; - } - - return $markdown; + return Str::limit($markdown, 125); } private function stripMarkdownFromBody(string $body): string From 1344cedb0e2ea515b97bcb95732e7f9a058cb5b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:16:16 +0200 Subject: [PATCH 003/222] Inline simplified helper methods --- .../src/Framework/Factories/BlogPostDataFactory.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php index 4eb9b1b818a..2322375ea88 100644 --- a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php +++ b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php @@ -108,17 +108,7 @@ protected function makeImage(): ?FeaturedImage private function makeDescriptionFromMarkdownBody(): string { - return $this->truncateMarkdown($this->stripMarkdownFromBody($this->markdown->body())); - } - - private function truncateMarkdown(string $markdown): string - { - return Str::limit($markdown, 125); - } - - private function stripMarkdownFromBody(string $body): string - { - return (new ConvertsMarkdownToPlainText($body))->execute(); + return Str::limit((new ConvertsMarkdownToPlainText($this->markdown->body()))->execute(), 125); } protected function getMatter(string $key): string|null|array From 2bdd5350401a382c0cbb1b8e852ef621fe98bc3a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:17:17 +0200 Subject: [PATCH 004/222] Use assert same instead of assert equals --- .../tests/Unit/Pages/MarkdownPostHelpersTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Unit/Pages/MarkdownPostHelpersTest.php b/packages/framework/tests/Unit/Pages/MarkdownPostHelpersTest.php index 721c575eb86..8bbcc8a97d9 100644 --- a/packages/framework/tests/Unit/Pages/MarkdownPostHelpersTest.php +++ b/packages/framework/tests/Unit/Pages/MarkdownPostHelpersTest.php @@ -15,44 +15,44 @@ class MarkdownPostHelpersTest extends TestCase public function testGetCurrentPagePathReturnsLocalUriPathForPostSlug() { $post = new MarkdownPost('foo-bar'); - $this->assertEquals('posts/foo-bar', $post->getRouteKey()); + $this->assertSame('posts/foo-bar', $post->getRouteKey()); } public function testGetCanonicalLinkReturnsCanonicalUriPathForPostSlug() { config(['hyde.url' => 'https://example.com']); $post = new MarkdownPost('foo-bar'); - $this->assertEquals('https://example.com/posts/foo-bar.html', $post->getCanonicalUrl()); + $this->assertSame('https://example.com/posts/foo-bar.html', $post->getCanonicalUrl()); } public function testGetCanonicalLinkReturnsPrettyUrlWhenEnabled() { config(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]); $post = new MarkdownPost('foo-bar'); - $this->assertEquals('https://example.com/posts/foo-bar', $post->getCanonicalUrl()); + $this->assertSame('https://example.com/posts/foo-bar', $post->getCanonicalUrl()); } public function testGetPostDescriptionReturnsPostDescriptionWhenSetInFrontMatter() { $post = MarkdownPost::make('foo-bar', ['description' => 'This is a post description']); - $this->assertEquals('This is a post description', $post->description); + $this->assertSame('This is a post description', $post->description); } public function testGetPostDescriptionReturnsPostBodyWhenNoDescriptionSetInFrontMatter() { $post = MarkdownPost::make('foo-bar', [], 'This is a post body'); - $this->assertEquals('This is a post body', $post->description); + $this->assertSame('This is a post body', $post->description); } public function testDynamicDescriptionIsTruncatedWhenLongerThan128Characters() { $post = MarkdownPost::make('foo-bar', [], str_repeat('a', 128)); - $this->assertEquals(str_repeat('a', 125).'...', $post->description); + $this->assertSame(str_repeat('a', 125).'...', $post->description); } public function testDynamicDescriptionStripsMarkdown() { $post = MarkdownPost::make('foo-bar', [], '## This is a **bold** description with [a link](https://example.com) and more'); - $this->assertEquals('This is a bold description with a link and more', $post->description); + $this->assertSame('This is a bold description with a link and more', $post->description); } } From 0a44117e764a7342835bc2210df5d00aa1a7fcf2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:34:52 +0200 Subject: [PATCH 005/222] Use assert same instead of assert equals --- .../ConvertsArrayToFrontMatterTest.php | 4 +-- .../tests/Feature/FeaturedImageTest.php | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/framework/tests/Feature/ConvertsArrayToFrontMatterTest.php b/packages/framework/tests/Feature/ConvertsArrayToFrontMatterTest.php index 77e6810f107..3eda88a7324 100644 --- a/packages/framework/tests/Feature/ConvertsArrayToFrontMatterTest.php +++ b/packages/framework/tests/Feature/ConvertsArrayToFrontMatterTest.php @@ -36,11 +36,11 @@ public function testActionConvertsAnArrayToFrontMatter() --- YAML; - $this->assertEquals(str_replace("\r", '', $expected), (new ConvertsArrayToFrontMatter)->execute($array)); + $this->assertSame(str_replace("\r", '', $expected), (new ConvertsArrayToFrontMatter)->execute($array)); } public function testActionReturnsEmptyStringIfArrayIsEmpty() { - $this->assertEquals('', (new ConvertsArrayToFrontMatter)->execute([])); + $this->assertSame('', (new ConvertsArrayToFrontMatter)->execute([])); } } diff --git a/packages/framework/tests/Feature/FeaturedImageTest.php b/packages/framework/tests/Feature/FeaturedImageTest.php index 540e2ae1dcf..ca252cd7852 100644 --- a/packages/framework/tests/Feature/FeaturedImageTest.php +++ b/packages/framework/tests/Feature/FeaturedImageTest.php @@ -47,7 +47,7 @@ public function testCanConstructFeaturedImage() $image = new FeaturedImage('_media/foo', ...$this->defaultArguments()); $this->assertInstanceOf(FeaturedImage::class, $image); - $this->assertEquals('media/foo', $image->getSource()); + $this->assertSame('media/foo', $image->getSource()); } public function testFeaturedImageGetContentLength() @@ -55,7 +55,7 @@ public function testFeaturedImageGetContentLength() $this->file('_media/foo', 'image'); $image = new FeaturedImage('_media/foo', ...$this->defaultArguments()); - $this->assertEquals(5, $image->getContentLength()); + $this->assertSame(5, $image->getContentLength()); } public function testFeaturedImageGetContentLengthWithRemoteSource() @@ -67,7 +67,7 @@ public function testFeaturedImageGetContentLengthWithRemoteSource() }); $image = new FeaturedImage('https://hyde.test/static/image.png', ...$this->defaultArguments()); - $this->assertEquals(16, $image->getContentLength()); + $this->assertSame(16, $image->getContentLength()); } public function testFeaturedImageGetContentLengthWithRemoteSourceAndNotFoundResponse() @@ -77,7 +77,7 @@ public function testFeaturedImageGetContentLengthWithRemoteSourceAndNotFoundResp }); $image = new FeaturedImage('https://hyde.test/static/image.png', ...$this->defaultArguments()); - $this->assertEquals(0, $image->getContentLength()); + $this->assertSame(0, $image->getContentLength()); } public function testFeaturedImageGetContentLengthWithRemoteSourceAndInvalidResponse() @@ -89,23 +89,23 @@ public function testFeaturedImageGetContentLengthWithRemoteSourceAndInvalidRespo }); $image = new FeaturedImage('https://hyde.test/static/image.png', ...$this->defaultArguments()); - $this->assertEquals(0, $image->getContentLength()); + $this->assertSame(0, $image->getContentLength()); } public function testGetSourceMethod() { - $this->assertEquals('media/foo', (new FeaturedImage('_media/foo', ...$this->defaultArguments()))->getSource()); + $this->assertSame('media/foo', (new FeaturedImage('_media/foo', ...$this->defaultArguments()))->getSource()); - $this->assertEquals('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'foo']))->getSource()); - $this->assertEquals('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'media/foo']))->getSource()); - $this->assertEquals('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => '_media/foo']))->getSource()); + $this->assertSame('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'foo']))->getSource()); + $this->assertSame('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'media/foo']))->getSource()); + $this->assertSame('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => '_media/foo']))->getSource()); - $this->assertEquals('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'foo']))->getSource()); - $this->assertEquals('//foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => '//foo']))->getSource()); - $this->assertEquals('http', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'http']))->getSource()); + $this->assertSame('media/foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'foo']))->getSource()); + $this->assertSame('//foo', FeaturedImageFactory::make(new FrontMatter(['image.source' => '//foo']))->getSource()); + $this->assertSame('http', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'http']))->getSource()); - $this->assertEquals('media/foo', FeaturedImageFactory::make(new FrontMatter(['image' => 'foo']))->getSource()); - $this->assertEquals('http', FeaturedImageFactory::make(new FrontMatter(['image' => 'http']))->getSource()); + $this->assertSame('media/foo', FeaturedImageFactory::make(new FrontMatter(['image' => 'foo']))->getSource()); + $this->assertSame('http', FeaturedImageFactory::make(new FrontMatter(['image' => 'http']))->getSource()); } protected function defaultArguments(): array From 3a7ccaacbe0022efcf7983299b6786e0bd64fba5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:36:22 +0200 Subject: [PATCH 006/222] Add assert same test --- packages/framework/tests/Feature/FilesystemFacadeTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/tests/Feature/FilesystemFacadeTest.php b/packages/framework/tests/Feature/FilesystemFacadeTest.php index 71d17c6556a..073246f0a31 100644 --- a/packages/framework/tests/Feature/FilesystemFacadeTest.php +++ b/packages/framework/tests/Feature/FilesystemFacadeTest.php @@ -48,6 +48,11 @@ public function testSmartGlob() Collection::make(['foo', 'bar', 'baz']), Filesystem::smartGlob('pattern/*.md') ); + + $this->assertSame( + Collection::make(['foo', 'bar', 'baz'])->all(), + Filesystem::smartGlob('pattern/*.md')->all() + ); } public function testTouch() From 6cd8fe0da12fce5eb19477f05570c70863778be9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:37:04 +0200 Subject: [PATCH 007/222] Introduce local variables --- .../framework/tests/Feature/FilesystemFacadeTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/FilesystemFacadeTest.php b/packages/framework/tests/Feature/FilesystemFacadeTest.php index 073246f0a31..456612020a5 100644 --- a/packages/framework/tests/Feature/FilesystemFacadeTest.php +++ b/packages/framework/tests/Feature/FilesystemFacadeTest.php @@ -44,14 +44,16 @@ public function testSmartGlob() Hyde::path('baz'), ], Hyde::path('pattern/*.md'), 0); + $expected = Collection::make(['foo', 'bar', 'baz']); + $actual = Filesystem::smartGlob('pattern/*.md'); $this->assertEquals( - Collection::make(['foo', 'bar', 'baz']), - Filesystem::smartGlob('pattern/*.md') + $expected, + $actual ); $this->assertSame( - Collection::make(['foo', 'bar', 'baz'])->all(), - Filesystem::smartGlob('pattern/*.md')->all() + $expected->all(), + $actual->all() ); } From 017a9424bd466a116bdda04289fcb6b46d60f7ae Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:37:29 +0200 Subject: [PATCH 008/222] Clean up code --- .../framework/tests/Feature/FilesystemFacadeTest.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/framework/tests/Feature/FilesystemFacadeTest.php b/packages/framework/tests/Feature/FilesystemFacadeTest.php index 456612020a5..55c46f3c6cc 100644 --- a/packages/framework/tests/Feature/FilesystemFacadeTest.php +++ b/packages/framework/tests/Feature/FilesystemFacadeTest.php @@ -46,15 +46,9 @@ public function testSmartGlob() $expected = Collection::make(['foo', 'bar', 'baz']); $actual = Filesystem::smartGlob('pattern/*.md'); - $this->assertEquals( - $expected, - $actual - ); - - $this->assertSame( - $expected->all(), - $actual->all() - ); + + $this->assertEquals($expected, $actual); + $this->assertSame($expected->all(), $actual->all()); } public function testTouch() From 49949cce8a2c94933079dc0059f3cdaccb0db79f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:37:52 +0200 Subject: [PATCH 009/222] Use assert same instead of assert equals --- .../tests/Feature/GlobalMetadataBagTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Feature/GlobalMetadataBagTest.php b/packages/framework/tests/Feature/GlobalMetadataBagTest.php index a20c98890b0..0201731ca39 100644 --- a/packages/framework/tests/Feature/GlobalMetadataBagTest.php +++ b/packages/framework/tests/Feature/GlobalMetadataBagTest.php @@ -42,7 +42,7 @@ public function testSiteMetadataAutomaticallyAddsSitemapWhenEnabled() config(['hyde.url' => 'foo']); config(['hyde.generate_sitemap' => true]); - $this->assertEquals('', GlobalMetadataBag::make()->render()); + $this->assertSame('', GlobalMetadataBag::make()->render()); } public function testSiteMetadataSitemapUsesConfiguredSiteUrl() @@ -52,7 +52,7 @@ public function testSiteMetadataSitemapUsesConfiguredSiteUrl() config(['hyde.url' => 'bar']); config(['hyde.generate_sitemap' => true]); - $this->assertEquals('', GlobalMetadataBag::make()->render()); + $this->assertSame('', GlobalMetadataBag::make()->render()); } public function testSiteMetadataAutomaticallyAddsRssFeedWhenEnabled() @@ -63,7 +63,7 @@ public function testSiteMetadataAutomaticallyAddsRssFeedWhenEnabled() config(['hyde.rss.enabled' => true]); $this->file('_posts/foo.md'); - $this->assertEquals('', GlobalMetadataBag::make()->render()); + $this->assertSame('', GlobalMetadataBag::make()->render()); } public function testSiteMetadataRssFeedUsesConfiguredSiteUrl() @@ -74,7 +74,7 @@ public function testSiteMetadataRssFeedUsesConfiguredSiteUrl() config(['hyde.rss.enabled' => true]); $this->file('_posts/foo.md'); - $this->assertEquals('', GlobalMetadataBag::make()->render()); + $this->assertSame('', GlobalMetadataBag::make()->render()); } public function testSiteMetadataRssFeedUsesConfiguredSiteName() @@ -89,7 +89,7 @@ public function testSiteMetadataRssFeedUsesConfiguredSiteName() config(['hyde' => $config]); $this->file('_posts/foo.md'); - $this->assertEquals('', GlobalMetadataBag::make()->render()); + $this->assertSame('', GlobalMetadataBag::make()->render()); } public function testSiteMetadataRssFeedUsesConfiguredRssFileName() @@ -125,7 +125,7 @@ public function testMetadataExistingInTheCurrentPageIsNotAdded() Render::share('routeKey', 'foo'); Render::share('page', $page); - $this->assertEquals(['metadata:keep' => $keep], GlobalMetadataBag::make()->get()); + $this->assertSame(['metadata:keep' => $keep], GlobalMetadataBag::make()->get()); } public function testMetadataExistingInTheCurrentPageIsNotAddedRegardlessOfItsValue() @@ -140,7 +140,7 @@ public function testMetadataExistingInTheCurrentPageIsNotAddedRegardlessOfItsVal Render::share('routeKey', 'foo'); Render::share('page', $page); - $this->assertEquals([], GlobalMetadataBag::make()->get()); + $this->assertSame([], GlobalMetadataBag::make()->get()); } protected function emptyConfig(): void From a277e038d14b3184cc14f29837f5c3eddba54c10 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:38:01 +0200 Subject: [PATCH 010/222] Add newline --- packages/framework/tests/Feature/GlobalMetadataBagTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Feature/GlobalMetadataBagTest.php b/packages/framework/tests/Feature/GlobalMetadataBagTest.php index 0201731ca39..946c3d4646f 100644 --- a/packages/framework/tests/Feature/GlobalMetadataBagTest.php +++ b/packages/framework/tests/Feature/GlobalMetadataBagTest.php @@ -26,6 +26,7 @@ public function testSiteMetadataAddsConfigDefinedMetadata() 'foo' => 'bar', 'baz', ]]); + $this->assertEquals([ 'links:foo' => Meta::link('foo', 'bar'), 'metadata:foo' => Meta::name('foo', 'bar'), From 8928fb95bd66da1fade9f2c34aefed662ff2af16 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:38:19 +0200 Subject: [PATCH 011/222] Clarify test helper method name --- .../tests/Feature/GlobalMetadataBagTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/framework/tests/Feature/GlobalMetadataBagTest.php b/packages/framework/tests/Feature/GlobalMetadataBagTest.php index 946c3d4646f..0c6a66bceed 100644 --- a/packages/framework/tests/Feature/GlobalMetadataBagTest.php +++ b/packages/framework/tests/Feature/GlobalMetadataBagTest.php @@ -17,7 +17,7 @@ class GlobalMetadataBagTest extends TestCase { public function testSiteMetadataAddsConfigDefinedMetadata() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.meta' => [ Meta::link('foo', 'bar'), @@ -38,7 +38,7 @@ public function testSiteMetadataAddsConfigDefinedMetadata() public function testSiteMetadataAutomaticallyAddsSitemapWhenEnabled() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.url' => 'foo']); config(['hyde.generate_sitemap' => true]); @@ -48,7 +48,7 @@ public function testSiteMetadataAutomaticallyAddsSitemapWhenEnabled() public function testSiteMetadataSitemapUsesConfiguredSiteUrl() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.url' => 'bar']); config(['hyde.generate_sitemap' => true]); @@ -58,7 +58,7 @@ public function testSiteMetadataSitemapUsesConfiguredSiteUrl() public function testSiteMetadataAutomaticallyAddsRssFeedWhenEnabled() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.url' => 'foo']); config(['hyde.rss.enabled' => true]); @@ -69,7 +69,7 @@ public function testSiteMetadataAutomaticallyAddsRssFeedWhenEnabled() public function testSiteMetadataRssFeedUsesConfiguredSiteUrl() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.url' => 'bar']); config(['hyde.rss.enabled' => true]); @@ -80,7 +80,7 @@ public function testSiteMetadataRssFeedUsesConfiguredSiteUrl() public function testSiteMetadataRssFeedUsesConfiguredSiteName() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.url' => 'foo']); config(['hyde.name' => 'Site']); @@ -95,7 +95,7 @@ public function testSiteMetadataRssFeedUsesConfiguredSiteName() public function testSiteMetadataRssFeedUsesConfiguredRssFileName() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.url' => 'foo']); config(['hyde.rss.filename' => 'posts.rss']); @@ -110,7 +110,7 @@ public function testSiteMetadataRssFeedUsesConfiguredRssFileName() public function testMetadataExistingInTheCurrentPageIsNotAdded() { - $this->emptyConfig(); + $this->withEmptyConfig(); $duplicate = Meta::name('remove', 'me'); $keep = Meta::name('keep', 'this'); @@ -131,7 +131,7 @@ public function testMetadataExistingInTheCurrentPageIsNotAdded() public function testMetadataExistingInTheCurrentPageIsNotAddedRegardlessOfItsValue() { - $this->emptyConfig(); + $this->withEmptyConfig(); config(['hyde.meta' => [Meta::name('foo', 'bar')]]); @@ -144,7 +144,7 @@ public function testMetadataExistingInTheCurrentPageIsNotAddedRegardlessOfItsVal $this->assertSame([], GlobalMetadataBag::make()->get()); } - protected function emptyConfig(): void + protected function withEmptyConfig(): void { config(['hyde.url' => null]); config(['hyde.meta' => []]); From b71cfa7096d731fb530d3faab86719ddca99bbc7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:40:33 +0200 Subject: [PATCH 012/222] Introduce local variables --- .../framework/tests/Feature/GlobalMetadataBagTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/GlobalMetadataBagTest.php b/packages/framework/tests/Feature/GlobalMetadataBagTest.php index 0c6a66bceed..6526ab822ed 100644 --- a/packages/framework/tests/Feature/GlobalMetadataBagTest.php +++ b/packages/framework/tests/Feature/GlobalMetadataBagTest.php @@ -27,13 +27,17 @@ public function testSiteMetadataAddsConfigDefinedMetadata() 'baz', ]]); - $this->assertEquals([ + $expected = [ 'links:foo' => Meta::link('foo', 'bar'), 'metadata:foo' => Meta::name('foo', 'bar'), 'properties:foo' => Meta::property('foo', 'bar'), 'generics:0' => 'bar', 'generics:1' => 'baz', - ], GlobalMetadataBag::make()->get()); + ]; + + $actual = GlobalMetadataBag::make()->get(); + + $this->assertEquals($expected, $actual); } public function testSiteMetadataAutomaticallyAddsSitemapWhenEnabled() From 41fa6504afffbbb16dd86a1ad6301f67efd22988 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:41:01 +0200 Subject: [PATCH 013/222] Assert array keys are the same --- packages/framework/tests/Feature/GlobalMetadataBagTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Feature/GlobalMetadataBagTest.php b/packages/framework/tests/Feature/GlobalMetadataBagTest.php index 6526ab822ed..ae90f018079 100644 --- a/packages/framework/tests/Feature/GlobalMetadataBagTest.php +++ b/packages/framework/tests/Feature/GlobalMetadataBagTest.php @@ -38,6 +38,7 @@ public function testSiteMetadataAddsConfigDefinedMetadata() $actual = GlobalMetadataBag::make()->get(); $this->assertEquals($expected, $actual); + $this->assertSame(array_keys($expected), array_keys($actual)); } public function testSiteMetadataAutomaticallyAddsSitemapWhenEnabled() From 3b658b7f31757ca743c58cc7d5abbbc2822f0de6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:42:45 +0200 Subject: [PATCH 014/222] Add missing function imports --- .../src/Framework/Actions/ConvertsMarkdownToPlainText.php | 2 ++ .../src/Framework/Actions/PostBuildTasks/GenerateSitemap.php | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Actions/ConvertsMarkdownToPlainText.php b/packages/framework/src/Framework/Actions/ConvertsMarkdownToPlainText.php index d0a99ba1f0f..8b9b2229cdb 100644 --- a/packages/framework/src/Framework/Actions/ConvertsMarkdownToPlainText.php +++ b/packages/framework/src/Framework/Actions/ConvertsMarkdownToPlainText.php @@ -4,7 +4,9 @@ namespace Hyde\Framework\Actions; +use function trim; use function rtrim; +use function is_numeric; use function str_ends_with; use function str_starts_with; use function substr; diff --git a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSitemap.php b/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSitemap.php index 3f6b5dcda1f..e2e15c55809 100644 --- a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSitemap.php +++ b/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateSitemap.php @@ -9,6 +9,7 @@ use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Framework\Features\XmlGenerators\SitemapGenerator; +use function blank; use function file_put_contents; class GenerateSitemap extends PostBuildTask From 51e44c0b2c6b4c56dcae594b6b5a35a2adc32b88 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:44:06 +0200 Subject: [PATCH 015/222] Clarify outdated language in code comment --- .../src/Framework/Features/Blogging/Models/FeaturedImage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php index 02b2ab3eb99..c8d3567ef56 100644 --- a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php +++ b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php @@ -224,7 +224,7 @@ protected function getContentLengthForLocalImage(): int protected function getContentLengthForRemoteImage(): int { - // Check if the --no-api flag is set when running the build command, and if so, skip the API call. + // API calls can be skipped in the config, or by setting the --no-api flag when running the build command. if (Config::getBool('hyde.api_calls', true)) { /** @var string[][] $headers */ $headers = Http::withHeaders([ From 7d397fc7ae7d1ffeb1e515189e2bd4c4592821f5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:44:46 +0200 Subject: [PATCH 016/222] Call static method statically --- .../src/Framework/Features/Blogging/Models/FeaturedImage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php index c8d3567ef56..a8dcb492315 100644 --- a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php +++ b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php @@ -63,7 +63,7 @@ public function __construct( protected readonly ?string $licenseUrl = null, protected readonly ?string $copyrightText = null ) { - $this->type = $this->isRemote($source) ? self::TYPE_REMOTE : self::TYPE_LOCAL; + $this->type = self::isRemote($source) ? self::TYPE_REMOTE : self::TYPE_LOCAL; $this->source = $this->setSource($source); } From 294111ff34e02bf23a45521d5e1bafd22eb27869 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:45:15 +0200 Subject: [PATCH 017/222] Join comma-separated values into a single line --- .../Concerns/Internal/ForwardsIlluminateFilesystem.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php b/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php index 1b9897700c7..fe6b98c0336 100644 --- a/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php +++ b/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php @@ -89,10 +89,7 @@ protected static function getParameterNames(string $name): array protected static function qualifyArguments(array $parameterNames, array $arguments): Collection { return collect($arguments)->mapWithKeys(function (string|array|int|bool $argumentValue, int|string $key) use ($parameterNames): string|array|int|bool { - $argumentsToQualify = [ - 'path', 'paths', 'file', 'target', 'directory', 'destination', 'firstFile', 'secondFile', - 'pattern', 'link', 'from', 'to', - ]; + $argumentsToQualify = ['path', 'paths', 'file', 'target', 'directory', 'destination', 'firstFile', 'secondFile', 'pattern', 'link', 'from', 'to']; if (is_int($key)) { // If the argument is not named, we'll retrieve it from the reflection data. From 9dd43c9519c28e4474a43322c5858376c1cc4f88 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 15:52:03 +0200 Subject: [PATCH 018/222] Ignore code coverage for deprecated methods --- packages/framework/src/Facades/Features.php | 48 +++++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index c16703d302d..73184177b88 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -104,56 +104,88 @@ public static function hasTorchlight(): bool // Configure features to be used in the config file. // ================================================= - /** @deprecated This method will be removed in v2.0. Please use `Feature::HtmlPages` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::HtmlPages` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::HtmlPages Enum case', replacement: 'Feature::HtmlPages', since: '1.6.0')] public static function htmlPages(): Feature { return Feature::HtmlPages; } - /** @deprecated This method will be removed in v2.0. Please use `Feature::BladePages` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::BladePages` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::BladePages Enum case', replacement: 'Feature::BladePages', since: '1.6.0')] public static function bladePages(): Feature { return Feature::BladePages; } - /** @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPages` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPages` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::MarkdownPages Enum case', replacement: 'Feature::MarkdownPages', since: '1.6.0')] public static function markdownPages(): Feature { return Feature::MarkdownPages; } - /** @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPosts` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPosts` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::MarkdownPosts Enum case', replacement: 'Feature::MarkdownPosts', since: '1.6.0')] public static function markdownPosts(): Feature { return Feature::MarkdownPosts; } - /** @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationPages` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationPages` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::DocumentationPages Enum case', replacement: 'Feature::DocumentationPages', since: '1.6.0')] public static function documentationPages(): Feature { return Feature::DocumentationPages; } - /** @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationSearch` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationSearch` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::DocumentationSearch Enum case', replacement: 'Feature::DocumentationSearch', since: '1.6.0')] public static function documentationSearch(): Feature { return Feature::DocumentationSearch; } - /** @deprecated This method will be removed in v2.0. Please use `Feature::Darkmode` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::Darkmode` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::Darkmode Enum case', replacement: 'Feature::Darkmode', since: '1.6.0')] public static function darkmode(): Feature { return Feature::Darkmode; } - /** @deprecated This method will be removed in v2.0. Please use `Feature::Torchlight` instead. */ + /** + * @codeCoverageIgnore Deprecated method. + * + * @deprecated This method will be removed in v2.0. Please use `Feature::Torchlight` instead. + */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::Torchlight Enum case', replacement: 'Feature::Torchlight', since: '1.6.0')] public static function torchlight(): Feature { From 0a5a1a2b6da955acc466f8cd37b75e777ac7ef15 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 17:43:46 +0200 Subject: [PATCH 019/222] Use assert same instead of assert equals --- .../tests/Feature/HydeKernelTest.php | 10 +- .../tests/Feature/HydeServiceProviderTest.php | 92 +++++++++---------- .../tests/Feature/IncludesFacadeTest.php | 26 +++--- .../tests/Feature/MarkdownPostTest.php | 22 ++--- .../tests/Feature/MarkdownServiceTest.php | 12 +-- .../Unit/HydeBasePathCanBeChangedTest.php | 4 +- 6 files changed, 83 insertions(+), 83 deletions(-) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index 9c64381888b..ab305cf9fc2 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -291,12 +291,12 @@ public function testToArrayMethod() public function testJsonSerializeMethod() { - $this->assertEquals(Hyde::kernel()->jsonSerialize(), collect(Hyde::toArray())->toArray()); + $this->assertSame(Hyde::kernel()->jsonSerialize(), collect(Hyde::toArray())->toArray()); } public function testToJsonMethod() { - $this->assertEquals(Hyde::kernel()->toJson(), json_encode(Hyde::toArray())); + $this->assertSame(Hyde::kernel()->toJson(), json_encode(Hyde::toArray())); } public function testVersionConstantIsAValidSemverString() @@ -435,12 +435,12 @@ public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory public function testMediaOutputDirectoryCanBeChangedInConfiguration() { - $this->assertEquals('_media', Hyde::getMediaDirectory()); + $this->assertSame('_media', Hyde::getMediaDirectory()); config(['hyde.media_directory' => '_assets']); (new HydeServiceProvider($this->app))->register(); - $this->assertEquals('_assets', Hyde::getMediaDirectory()); + $this->assertSame('_assets', Hyde::getMediaDirectory()); } public function testCanAccessKernelFluentlyUsingTheFacade() @@ -522,7 +522,7 @@ public function testCanUseBootingCallbacksToInjectCustomPages() }); $this->assertSame($page, Pages::getPage('foo')); - $this->assertEquals($page->getRoute(), Routes::getRoute('foo')); + $this->assertSame($page->getRoute(), Routes::getRoute('foo')); } public function testIsBootedReturnsFalseWhenNotBooted() diff --git a/packages/framework/tests/Feature/HydeServiceProviderTest.php b/packages/framework/tests/Feature/HydeServiceProviderTest.php index d48d22933cb..1651325e8e8 100644 --- a/packages/framework/tests/Feature/HydeServiceProviderTest.php +++ b/packages/framework/tests/Feature/HydeServiceProviderTest.php @@ -71,17 +71,17 @@ public function testProviderRegistersSourceDirectories() MarkdownPost::setSourceDirectory(''); DocumentationPage::setSourceDirectory(''); - $this->assertEquals('', BladePage::sourceDirectory()); - $this->assertEquals('', MarkdownPage::sourceDirectory()); - $this->assertEquals('', MarkdownPost::sourceDirectory()); - $this->assertEquals('', DocumentationPage::sourceDirectory()); + $this->assertSame('', BladePage::sourceDirectory()); + $this->assertSame('', MarkdownPage::sourceDirectory()); + $this->assertSame('', MarkdownPost::sourceDirectory()); + $this->assertSame('', DocumentationPage::sourceDirectory()); $this->provider->register(); - $this->assertEquals('_pages', BladePage::sourceDirectory()); - $this->assertEquals('_pages', MarkdownPage::sourceDirectory()); - $this->assertEquals('_posts', MarkdownPost::sourceDirectory()); - $this->assertEquals('_docs', DocumentationPage::sourceDirectory()); + $this->assertSame('_pages', BladePage::sourceDirectory()); + $this->assertSame('_pages', MarkdownPage::sourceDirectory()); + $this->assertSame('_posts', MarkdownPost::sourceDirectory()); + $this->assertSame('_docs', DocumentationPage::sourceDirectory()); } public function testProviderRegistersOutputDirectories() @@ -91,17 +91,17 @@ public function testProviderRegistersOutputDirectories() MarkdownPost::setOutputDirectory('foo'); DocumentationPage::setOutputDirectory('foo'); - $this->assertEquals('foo', BladePage::outputDirectory()); - $this->assertEquals('foo', MarkdownPage::outputDirectory()); - $this->assertEquals('foo', MarkdownPost::outputDirectory()); - $this->assertEquals('foo', DocumentationPage::outputDirectory()); + $this->assertSame('foo', BladePage::outputDirectory()); + $this->assertSame('foo', MarkdownPage::outputDirectory()); + $this->assertSame('foo', MarkdownPost::outputDirectory()); + $this->assertSame('foo', DocumentationPage::outputDirectory()); $this->provider->register(); - $this->assertEquals('', BladePage::outputDirectory()); - $this->assertEquals('', MarkdownPage::outputDirectory()); - $this->assertEquals('posts', MarkdownPost::outputDirectory()); - $this->assertEquals('docs', DocumentationPage::outputDirectory()); + $this->assertSame('', BladePage::outputDirectory()); + $this->assertSame('', MarkdownPage::outputDirectory()); + $this->assertSame('posts', MarkdownPost::outputDirectory()); + $this->assertSame('docs', DocumentationPage::outputDirectory()); } public function testCustomSourceRootsAreAppliedToThePageModels() @@ -134,46 +134,46 @@ public function testSourceRootSetInConfigIsAssigned() public function testProviderRegistersSiteOutputDirectory() { - $this->assertEquals('_site', Hyde::getOutputDirectory()); + $this->assertSame('_site', Hyde::getOutputDirectory()); config(['hyde.output_directory' => 'foo']); $this->provider->register(); - $this->assertEquals('foo', Hyde::getOutputDirectory()); + $this->assertSame('foo', Hyde::getOutputDirectory()); } public function testProviderRegistersMediaDirectory() { - $this->assertEquals('_media', Hyde::getMediaDirectory()); + $this->assertSame('_media', Hyde::getMediaDirectory()); config(['hyde.media_directory' => 'foo']); $this->provider->register(); - $this->assertEquals('foo', Hyde::getMediaDirectory()); - $this->assertEquals('foo', Hyde::getMediaOutputDirectory()); + $this->assertSame('foo', Hyde::getMediaDirectory()); + $this->assertSame('foo', Hyde::getMediaOutputDirectory()); } public function testProviderRegistersBladeViewDiscoveryLocationForConfiguredBladeViewPath() { config(['view.paths' => []]); - $this->assertEquals([], config('view.paths')); + $this->assertSame([], config('view.paths')); $this->provider->register(); - $this->assertEquals([realpath(Hyde::path('_pages'))], config('view.paths')); + $this->assertSame([realpath(Hyde::path('_pages'))], config('view.paths')); } public function testBladeViewLocationsAreOnlyRegisteredOncePerKey() { config(['view.paths' => []]); - $this->assertEquals([], config('view.paths')); + $this->assertSame([], config('view.paths')); $this->provider->register(); $this->provider->register(); - $this->assertEquals([realpath(Hyde::path('_pages'))], config('view.paths')); + $this->assertSame([realpath(Hyde::path('_pages'))], config('view.paths')); } public function testProviderRegistersConsoleCommands() @@ -206,7 +206,7 @@ public function testProviderRegistersAllPageModelSourcePaths() $pages = HydeCoreExtension::getPageClasses(); // Assert we are testing all page models - $this->assertEquals([ + $this->assertSame([ HtmlPage::class, BladePage::class, MarkdownPage::class, @@ -254,11 +254,11 @@ public function testProviderRegistersSourceDirectoriesUsingOptionsInConfiguratio $this->provider->register(); - $this->assertEquals('foo', HtmlPage::sourceDirectory()); - $this->assertEquals('foo', BladePage::sourceDirectory()); - $this->assertEquals('foo', MarkdownPage::sourceDirectory()); - $this->assertEquals('foo', MarkdownPost::sourceDirectory()); - $this->assertEquals('foo', DocumentationPage::sourceDirectory()); + $this->assertSame('foo', HtmlPage::sourceDirectory()); + $this->assertSame('foo', BladePage::sourceDirectory()); + $this->assertSame('foo', MarkdownPage::sourceDirectory()); + $this->assertSame('foo', MarkdownPost::sourceDirectory()); + $this->assertSame('foo', DocumentationPage::sourceDirectory()); } public function testSourceDirectoriesCanBeSetUsingKebabCaseClassNames() @@ -273,11 +273,11 @@ public function testSourceDirectoriesCanBeSetUsingKebabCaseClassNames() $this->provider->register(); - $this->assertEquals('foo', HtmlPage::sourceDirectory()); - $this->assertEquals('foo', BladePage::sourceDirectory()); - $this->assertEquals('foo', MarkdownPage::sourceDirectory()); - $this->assertEquals('foo', MarkdownPost::sourceDirectory()); - $this->assertEquals('foo', DocumentationPage::sourceDirectory()); + $this->assertSame('foo', HtmlPage::sourceDirectory()); + $this->assertSame('foo', BladePage::sourceDirectory()); + $this->assertSame('foo', MarkdownPage::sourceDirectory()); + $this->assertSame('foo', MarkdownPost::sourceDirectory()); + $this->assertSame('foo', DocumentationPage::sourceDirectory()); } public function testProviderRegistersOutputDirectoriesUsingOptionsInConfiguration() @@ -292,11 +292,11 @@ public function testProviderRegistersOutputDirectoriesUsingOptionsInConfiguratio $this->provider->register(); - $this->assertEquals('foo', HtmlPage::outputDirectory()); - $this->assertEquals('foo', BladePage::outputDirectory()); - $this->assertEquals('foo', MarkdownPage::outputDirectory()); - $this->assertEquals('foo', MarkdownPost::outputDirectory()); - $this->assertEquals('foo', DocumentationPage::outputDirectory()); + $this->assertSame('foo', HtmlPage::outputDirectory()); + $this->assertSame('foo', BladePage::outputDirectory()); + $this->assertSame('foo', MarkdownPage::outputDirectory()); + $this->assertSame('foo', MarkdownPost::outputDirectory()); + $this->assertSame('foo', DocumentationPage::outputDirectory()); } public function testOutputDirectoriesCanBeSetUsingKebabCaseClassNames() @@ -311,10 +311,10 @@ public function testOutputDirectoriesCanBeSetUsingKebabCaseClassNames() $this->provider->register(); - $this->assertEquals('foo', HtmlPage::outputDirectory()); - $this->assertEquals('foo', BladePage::outputDirectory()); - $this->assertEquals('foo', MarkdownPage::outputDirectory()); - $this->assertEquals('foo', MarkdownPost::outputDirectory()); - $this->assertEquals('foo', DocumentationPage::outputDirectory()); + $this->assertSame('foo', HtmlPage::outputDirectory()); + $this->assertSame('foo', BladePage::outputDirectory()); + $this->assertSame('foo', MarkdownPage::outputDirectory()); + $this->assertSame('foo', MarkdownPost::outputDirectory()); + $this->assertSame('foo', DocumentationPage::outputDirectory()); } } diff --git a/packages/framework/tests/Feature/IncludesFacadeTest.php b/packages/framework/tests/Feature/IncludesFacadeTest.php index e35c2119eed..75ada517c31 100644 --- a/packages/framework/tests/Feature/IncludesFacadeTest.php +++ b/packages/framework/tests/Feature/IncludesFacadeTest.php @@ -17,7 +17,7 @@ class IncludesFacadeTest extends TestCase { public function testPathReturnsTheIncludesDirectory() { - $this->assertEquals( + $this->assertSame( Hyde::path('resources/includes'), Includes::path() ); @@ -25,7 +25,7 @@ public function testPathReturnsTheIncludesDirectory() public function testPathReturnsAPartialWithinTheIncludesDirectory() { - $this->assertEquals( + $this->assertSame( Hyde::path('resources/includes/partial.html'), Includes::path('partial.html') ); @@ -43,34 +43,34 @@ public function testGetReturnsPartial() { $expected = 'foo bar'; file_put_contents(Hyde::path('resources/includes/foo.txt'), $expected); - $this->assertEquals($expected, Includes::get('foo.txt')); + $this->assertSame($expected, Includes::get('foo.txt')); Filesystem::unlink('resources/includes/foo.txt'); } public function testGetReturnsDefaultValueWhenNotFound() { $this->assertNull(Includes::get('foo.txt')); - $this->assertEquals('default', Includes::get('foo.txt', 'default')); + $this->assertSame('default', Includes::get('foo.txt', 'default')); } public function testHtmlReturnsRenderedPartial() { $expected = '

foo bar

'; file_put_contents(Hyde::path('resources/includes/foo.html'), '

foo bar

'); - $this->assertEquals($expected, Includes::html('foo.html')); + $this->assertSame($expected, Includes::html('foo.html')); Filesystem::unlink('resources/includes/foo.html'); } public function testHtmlReturnsEfaultValueWhenNotFound() { $this->assertNull(Includes::html('foo.html')); - $this->assertEquals('

default

', Includes::html('foo.html', '

default

')); + $this->assertSame('

default

', Includes::html('foo.html', '

default

')); } public function testHtmlWithAndWithoutExtension() { file_put_contents(Hyde::path('resources/includes/foo.html'), '# foo bar'); - $this->assertEquals(Includes::html('foo.html'), Includes::html('foo')); + $this->assertSame(Includes::html('foo.html'), Includes::html('foo')); Filesystem::unlink('resources/includes/foo.html'); } @@ -78,20 +78,20 @@ public function testMarkdownReturnsRenderedPartial() { $expected = "

foo bar

\n"; file_put_contents(Hyde::path('resources/includes/foo.md'), '# foo bar'); - $this->assertEquals($expected, Includes::markdown('foo.md')); + $this->assertSame($expected, Includes::markdown('foo.md')); Filesystem::unlink('resources/includes/foo.md'); } public function testMarkdownReturnsRenderedDefaultValueWhenNotFound() { $this->assertNull(Includes::markdown('foo.md')); - $this->assertEquals("

default

\n", Includes::markdown('foo.md', '# default')); + $this->assertSame("

default

\n", Includes::markdown('foo.md', '# default')); } public function testMarkdownWithAndWithoutExtension() { file_put_contents(Hyde::path('resources/includes/foo.md'), '# foo bar'); - $this->assertEquals(Includes::markdown('foo.md'), Includes::markdown('foo')); + $this->assertSame(Includes::markdown('foo.md'), Includes::markdown('foo')); Filesystem::unlink('resources/includes/foo.md'); } @@ -99,20 +99,20 @@ public function testBladeReturnsRenderedPartial() { $expected = 'foo bar'; file_put_contents(Hyde::path('resources/includes/foo.blade.php'), '{{ "foo bar" }}'); - $this->assertEquals($expected, Includes::blade('foo.blade.php')); + $this->assertSame($expected, Includes::blade('foo.blade.php')); Filesystem::unlink('resources/includes/foo.blade.php'); } public function testBladeWithAndWithoutExtension() { file_put_contents(Hyde::path('resources/includes/foo.blade.php'), '# foo bar'); - $this->assertEquals(Includes::blade('foo.blade.php'), Includes::blade('foo')); + $this->assertSame(Includes::blade('foo.blade.php'), Includes::blade('foo')); Filesystem::unlink('resources/includes/foo.blade.php'); } public function testBladeReturnsRenderedDefaultValueWhenNotFound() { $this->assertNull(Includes::blade('foo.blade.php')); - $this->assertEquals('default', Includes::blade('foo.blade.php', '{{ "default" }}')); + $this->assertSame('default', Includes::blade('foo.blade.php', '{{ "default" }}')); } } diff --git a/packages/framework/tests/Feature/MarkdownPostTest.php b/packages/framework/tests/Feature/MarkdownPostTest.php index 3de217ca75e..66c76b3a0ba 100644 --- a/packages/framework/tests/Feature/MarkdownPostTest.php +++ b/packages/framework/tests/Feature/MarkdownPostTest.php @@ -24,7 +24,7 @@ public function testConstructorCanCreateANewAuthorInstanceFromUsernameString() ])); $this->assertInstanceOf(PostAuthor::class, $post->author); - $this->assertEquals('John Doe', $post->author->username); + $this->assertSame('John Doe', $post->author->username); $this->assertNull($post->author->name); $this->assertNull($post->author->website); } @@ -40,9 +40,9 @@ public function testConstructorCanCreateANewAuthorInstanceFromUserArray() ])); $this->assertInstanceOf(PostAuthor::class, $post->author); - $this->assertEquals('john_doe', $post->author->username); - $this->assertEquals('John Doe', $post->author->name); - $this->assertEquals('https://example.com', $post->author->website); + $this->assertSame('john_doe', $post->author->username); + $this->assertSame('John Doe', $post->author->name); + $this->assertSame('https://example.com', $post->author->website); } public function testConstructorCanCreateANewImageInstanceFromAString() @@ -52,7 +52,7 @@ public function testConstructorCanCreateANewImageInstanceFromAString() ])); $this->assertInstanceOf(FeaturedImage::class, $post->image); - $this->assertEquals('https://example.com/image.jpg', $post->image->getSource()); + $this->assertSame('https://example.com/image.jpg', $post->image->getSource()); } public function testConstructorCanCreateANewImageInstanceFromAnArray() @@ -64,7 +64,7 @@ public function testConstructorCanCreateANewImageInstanceFromAnArray() ])); $this->assertInstanceOf(FeaturedImage::class, $post->image); - $this->assertEquals('https://example.com/image.jpg', $post->image->getSource()); + $this->assertSame('https://example.com/image.jpg', $post->image->getSource()); } public function testConstructorCanCreateANewDateStringInstanceFromMatter() @@ -74,7 +74,7 @@ public function testConstructorCanCreateANewDateStringInstanceFromMatter() ])); $this->assertInstanceOf(DateString::class, $post->date); - $this->assertEquals('Jan 1st, 2022', $post->date->short); + $this->assertSame('Jan 1st, 2022', $post->date->short); } public function testFeaturedImageCanBeConstructedReturnsNullWhenNoImageIsSetInThePageMatter() @@ -88,7 +88,7 @@ public function testFeaturedImageCanBeConstructedReturnsImageObjectWithLocalPath $page = MarkdownPost::make(matter: ['image' => 'foo.png']); $image = $page->image; $this->assertInstanceOf(FeaturedImage::class, $image); - $this->assertEquals('media/foo.png', $image->getSource()); + $this->assertSame('media/foo.png', $image->getSource()); } public function testFeaturedImageCanBeConstructedReturnsImageObjectWithRemotePathWhenMatterIsString() @@ -96,7 +96,7 @@ public function testFeaturedImageCanBeConstructedReturnsImageObjectWithRemotePat $page = MarkdownPost::make(matter: ['image' => 'https://example.com/foo.png']); $image = $page->image; $this->assertInstanceOf(FeaturedImage::class, $image); - $this->assertEquals('https://example.com/foo.png', $image->getSource()); + $this->assertSame('https://example.com/foo.png', $image->getSource()); } public function testFeaturedImageCanBeConstructedReturnsImageObjectWithSuppliedDataWhenMatterIsArray() @@ -104,7 +104,7 @@ public function testFeaturedImageCanBeConstructedReturnsImageObjectWithSuppliedD $page = MarkdownPost::make(matter: ['image' => ['source' => 'foo.png', 'titleText' => 'bar']]); $image = $page->image; $this->assertInstanceOf(FeaturedImage::class, $image); - $this->assertEquals('media/foo.png', $image->getSource()); - $this->assertEquals('bar', $image->getTitleText()); + $this->assertSame('media/foo.png', $image->getSource()); + $this->assertSame('bar', $image->getTitleText()); } } diff --git a/packages/framework/tests/Feature/MarkdownServiceTest.php b/packages/framework/tests/Feature/MarkdownServiceTest.php index d3c68a835ef..9c6cfc88cf7 100644 --- a/packages/framework/tests/Feature/MarkdownServiceTest.php +++ b/packages/framework/tests/Feature/MarkdownServiceTest.php @@ -22,7 +22,7 @@ public function testServiceCanParseMarkdownToHtml() $html = (new MarkdownService($markdown))->parse(); $this->assertIsString($html); - $this->assertEquals("

Hello World!

\n", $html); + $this->assertSame("

Hello World!

\n", $html); } public function testServiceCanParseMarkdownToHtmlWithPermalinks() @@ -32,7 +32,7 @@ public function testServiceCanParseMarkdownToHtmlWithPermalinks() $html = (new MarkdownService($markdown))->withPermalinks()->parse(); $this->assertIsString($html); - $this->assertEquals( + $this->assertSame( '

Hello World!

'."\n", $html @@ -72,7 +72,7 @@ public function testTorchlightIntegrationInjectsAttribution() public function testBladedownIsNotEnabledByDefault() { $service = new MarkdownService('[Blade]: {{ "Hello World!" }}'); - $this->assertEquals("

[Blade]: {{ "Hello World!" }}

\n", $service->parse()); + $this->assertSame("

[Blade]: {{ "Hello World!" }}

\n", $service->parse()); } public function testBladedownCanBeEnabled() @@ -80,7 +80,7 @@ public function testBladedownCanBeEnabled() config(['markdown.enable_blade' => true]); $service = new MarkdownService('[Blade]: {{ "Hello World!" }}'); $service->addFeature('bladedown')->parse(); - $this->assertEquals("Hello World!\n", $service->parse()); + $this->assertSame("Hello World!\n", $service->parse()); } public function testRawHtmlTagsAreStrippedByDefault() @@ -88,7 +88,7 @@ public function testRawHtmlTagsAreStrippedByDefault() $markdown = '

foo

'; $service = new MarkdownService($markdown); $html = $service->parse(); - $this->assertEquals("

foo

<style>bar</style><script>hat</script>\n", $html); + $this->assertSame("

foo

<style>bar</style><script>hat</script>\n", $html); } public function testRawHtmlTagsAreNotStrippedWhenExplicitlyEnabled() @@ -97,7 +97,7 @@ public function testRawHtmlTagsAreNotStrippedWhenExplicitlyEnabled() $markdown = '

foo

'; $service = new MarkdownService($markdown); $html = $service->parse(); - $this->assertEquals("

foo

\n", $html); + $this->assertSame("

foo

\n", $html); } public function testHasFeaturesArray() diff --git a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php index 9e40d9ff1da..35bb79665a4 100644 --- a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php +++ b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php @@ -37,7 +37,7 @@ protected function tearDown(): void public function testHydeBasePathCanBeChanged() { Hyde::setBasePath('/foo/bar'); - $this->assertEquals('/foo/bar', Hyde::getBasePath()); - $this->assertEquals('/foo/bar', Hyde::path()); + $this->assertSame('/foo/bar', Hyde::getBasePath()); + $this->assertSame('/foo/bar', Hyde::path()); } } From 1e3aecbf44d3eb231092e9785c966770beb53843 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 17:47:53 +0200 Subject: [PATCH 020/222] Use assert same instead of assert equals --- .../Feature/PageModelConstructorsTest.php | 10 +++--- .../SourceDirectoriesCanBeChangedTest.php | 36 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/framework/tests/Feature/PageModelConstructorsTest.php b/packages/framework/tests/Feature/PageModelConstructorsTest.php index c98d2988dae..a87959409b5 100644 --- a/packages/framework/tests/Feature/PageModelConstructorsTest.php +++ b/packages/framework/tests/Feature/PageModelConstructorsTest.php @@ -25,7 +25,7 @@ public function testDynamicDataConstructorCanFindTitleFromFrontMatter() { $this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'My Title']); $page = MarkdownPage::parse('foo'); - $this->assertEquals('My Title', $page->title); + $this->assertSame('My Title', $page->title); } public function testDynamicDataConstructorCanFindTitleFromH1Tag() @@ -33,7 +33,7 @@ public function testDynamicDataConstructorCanFindTitleFromH1Tag() $this->markdown('_pages/foo.md', '# Foo Bar'); $page = MarkdownPage::parse('foo'); - $this->assertEquals('Foo Bar', $page->title); + $this->assertSame('Foo Bar', $page->title); } public function testDynamicDataConstructorCanFindTitleFromSlug() @@ -41,7 +41,7 @@ public function testDynamicDataConstructorCanFindTitleFromSlug() $this->markdown('_pages/foo-bar.md'); $page = MarkdownPage::parse('foo-bar'); - $this->assertEquals('Foo Bar', $page->title); + $this->assertSame('Foo Bar', $page->title); } public function testDocumentationPageParserCanGetGroupFromFrontMatter() @@ -49,7 +49,7 @@ public function testDocumentationPageParserCanGetGroupFromFrontMatter() $this->markdown('_docs/foo.md', '# Foo Bar', ['navigation.group' => 'foo']); $page = DocumentationPage::parse('foo'); - $this->assertEquals('foo', $page->navigationMenuGroup()); + $this->assertSame('foo', $page->navigationMenuGroup()); } public function testDocumentationPageParserCanGetGroupAutomaticallyFromNestedPage() @@ -59,7 +59,7 @@ public function testDocumentationPageParserCanGetGroupAutomaticallyFromNestedPag /** @var \Hyde\Pages\DocumentationPage $page */ $page = DocumentationPage::parse('foo/bar'); - $this->assertEquals('foo', $page->navigationMenuGroup()); + $this->assertSame('foo', $page->navigationMenuGroup()); Filesystem::unlink('_docs/foo/bar.md'); rmdir(Hyde::path('_docs/foo')); diff --git a/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php b/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php index 5be594d3a8c..fda177d9387 100644 --- a/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php +++ b/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php @@ -27,11 +27,11 @@ public static function tearDownAfterClass(): void public function testBaselines() { - $this->assertEquals('_pages', HtmlPage::sourceDirectory()); - $this->assertEquals('_pages', BladePage::sourceDirectory()); - $this->assertEquals('_pages', MarkdownPage::sourceDirectory()); - $this->assertEquals('_posts', MarkdownPost::sourceDirectory()); - $this->assertEquals('_docs', DocumentationPage::sourceDirectory()); + $this->assertSame('_pages', HtmlPage::sourceDirectory()); + $this->assertSame('_pages', BladePage::sourceDirectory()); + $this->assertSame('_pages', MarkdownPage::sourceDirectory()); + $this->assertSame('_posts', MarkdownPost::sourceDirectory()); + $this->assertSame('_docs', DocumentationPage::sourceDirectory()); } public function testSourceDirectoriesCanBeChangedProgrammatically() @@ -42,11 +42,11 @@ public function testSourceDirectoriesCanBeChangedProgrammatically() MarkdownPost::setSourceDirectory('.source/posts'); DocumentationPage::setSourceDirectory('.source/docs'); - $this->assertEquals('.source/pages', HtmlPage::sourceDirectory()); - $this->assertEquals('.source/pages', BladePage::sourceDirectory()); - $this->assertEquals('.source/pages', MarkdownPage::sourceDirectory()); - $this->assertEquals('.source/posts', MarkdownPost::sourceDirectory()); - $this->assertEquals('.source/docs', DocumentationPage::sourceDirectory()); + $this->assertSame('.source/pages', HtmlPage::sourceDirectory()); + $this->assertSame('.source/pages', BladePage::sourceDirectory()); + $this->assertSame('.source/pages', MarkdownPage::sourceDirectory()); + $this->assertSame('.source/posts', MarkdownPost::sourceDirectory()); + $this->assertSame('.source/docs', DocumentationPage::sourceDirectory()); } public function testSourceDirectoriesCanBeChangedInConfig() @@ -61,18 +61,18 @@ public function testSourceDirectoriesCanBeChangedInConfig() (new HydeServiceProvider($this->app))->register(); - $this->assertEquals('.source/pages', HtmlPage::sourceDirectory()); - $this->assertEquals('.source/pages', BladePage::sourceDirectory()); - $this->assertEquals('.source/pages', MarkdownPage::sourceDirectory()); - $this->assertEquals('.source/posts', MarkdownPost::sourceDirectory()); - $this->assertEquals('.source/docs', DocumentationPage::sourceDirectory()); + $this->assertSame('.source/pages', HtmlPage::sourceDirectory()); + $this->assertSame('.source/pages', BladePage::sourceDirectory()); + $this->assertSame('.source/pages', MarkdownPage::sourceDirectory()); + $this->assertSame('.source/posts', MarkdownPost::sourceDirectory()); + $this->assertSame('.source/docs', DocumentationPage::sourceDirectory()); } public function testBuildServiceRecognizesChangedDirectory() { MarkdownPost::setSourceDirectory('_source/posts'); - $this->assertEquals( + $this->assertSame( '_source/posts', MarkdownPost::sourceDirectory() ); @@ -85,7 +85,7 @@ public function testAutodiscoveryDiscoversPostsInCustomDirectory() MarkdownPost::setSourceDirectory('_source'); - $this->assertEquals( + $this->assertSame( ['test'], MarkdownPost::files() ); @@ -98,7 +98,7 @@ public function testAutodiscoveryDiscoversPostsInCustomSubdirectory() MarkdownPost::setSourceDirectory('_source/posts'); - $this->assertEquals( + $this->assertSame( ['test'], MarkdownPost::files() ); From a0f31f7477971b8e1c7b68545991654c99e6f8b7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 17:48:16 +0200 Subject: [PATCH 021/222] Join comma-separated values into single lines --- .../Feature/SourceDirectoriesCanBeChangedTest.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php b/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php index fda177d9387..6254c6fff2e 100644 --- a/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php +++ b/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php @@ -72,10 +72,7 @@ public function testBuildServiceRecognizesChangedDirectory() { MarkdownPost::setSourceDirectory('_source/posts'); - $this->assertSame( - '_source/posts', - MarkdownPost::sourceDirectory() - ); + $this->assertSame('_source/posts', MarkdownPost::sourceDirectory()); } public function testAutodiscoveryDiscoversPostsInCustomDirectory() @@ -85,10 +82,7 @@ public function testAutodiscoveryDiscoversPostsInCustomDirectory() MarkdownPost::setSourceDirectory('_source'); - $this->assertSame( - ['test'], - MarkdownPost::files() - ); + $this->assertSame(['test'], MarkdownPost::files()); } public function testAutodiscoveryDiscoversPostsInCustomSubdirectory() @@ -98,9 +92,6 @@ public function testAutodiscoveryDiscoversPostsInCustomSubdirectory() MarkdownPost::setSourceDirectory('_source/posts'); - $this->assertSame( - ['test'], - MarkdownPost::files() - ); + $this->assertSame(['test'], MarkdownPost::files()); } } From 6ac72012cf3403d80d5c1e9c0f83314691e77972 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 17:49:54 +0200 Subject: [PATCH 022/222] Clean up and improve test --- .../tests/Feature/SourceFileParserTest.php | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/framework/tests/Feature/SourceFileParserTest.php b/packages/framework/tests/Feature/SourceFileParserTest.php index cf099e08d59..c4bade3c726 100644 --- a/packages/framework/tests/Feature/SourceFileParserTest.php +++ b/packages/framework/tests/Feature/SourceFileParserTest.php @@ -23,8 +23,9 @@ public function testBladePageParser() $parser = new SourceFileParser(BladePage::class, 'foo'); $page = $parser->get(); + $this->assertInstanceOf(BladePage::class, $page); - $this->assertEquals('foo', $page->identifier); + $this->assertSame('foo', $page->identifier); } public function testMarkdownPageParser() @@ -33,10 +34,12 @@ public function testMarkdownPageParser() $parser = new SourceFileParser(MarkdownPage::class, 'foo'); $page = $parser->get(); + $this->assertInstanceOf(MarkdownPage::class, $page); - $this->assertEquals('foo', $page->identifier); + $this->assertSame('foo', $page->identifier); + $this->assertSame('Foo Bar Baz', $page->title); $this->assertEquals('# Foo Bar', $page->markdown); - $this->assertEquals('Foo Bar Baz', $page->title); + $this->assertSame('# Foo Bar', $page->markdown->body()); } public function testMarkdownPostParser() @@ -45,10 +48,12 @@ public function testMarkdownPostParser() $parser = new SourceFileParser(MarkdownPost::class, 'foo'); $page = $parser->get(); + $this->assertInstanceOf(MarkdownPost::class, $page); - $this->assertEquals('foo', $page->identifier); + $this->assertSame('foo', $page->identifier); + $this->assertSame('Foo Bar Baz', $page->title); $this->assertEquals('# Foo Bar', $page->markdown); - $this->assertEquals('Foo Bar Baz', $page->title); + $this->assertSame('# Foo Bar', $page->markdown->body()); } public function testDocumentationPageParser() @@ -57,10 +62,12 @@ public function testDocumentationPageParser() $parser = new SourceFileParser(DocumentationPage::class, 'foo'); $page = $parser->get(); + $this->assertInstanceOf(DocumentationPage::class, $page); - $this->assertEquals('foo', $page->identifier); + $this->assertSame('foo', $page->identifier); + $this->assertSame('Foo Bar Baz', $page->title); $this->assertEquals('# Foo Bar', $page->markdown); - $this->assertEquals('Foo Bar Baz', $page->title); + $this->assertSame('# Foo Bar', $page->markdown->body()); } public function testHtmlPageParser() @@ -69,29 +76,33 @@ public function testHtmlPageParser() $parser = new SourceFileParser(HtmlPage::class, 'foo'); $page = $parser->get(); + $this->assertInstanceOf(HtmlPage::class, $page); - $this->assertEquals('foo', $page->identifier); - $this->assertEquals('

Foo Bar

', $page->contents()); + $this->assertSame('foo', $page->identifier); + $this->assertSame('

Foo Bar

', $page->contents()); } public function testParsedPageIsRunThroughDynamicConstructor() { $this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'Foo Bar Baz']); $page = MarkdownPage::parse('foo'); - $this->assertEquals('Foo Bar Baz', $page->title); + + $this->assertSame('Foo Bar Baz', $page->title); } public function testBladePageDataIsParsedToFrontMatter() { $this->file('_pages/foo.blade.php', "@php(\$foo = 'bar')\n"); $page = BladePage::parse('foo'); - $this->assertEquals('bar', $page->data('foo')); + + $this->assertSame('bar', $page->data('foo')); } public function testBladePageMatterIsUsedForThePageTitle() { $this->file('_pages/foo.blade.php', "@php(\$title = 'Foo Bar')\n"); $page = BladePage::parse('foo'); - $this->assertEquals('Foo Bar', $page->data('title')); + + $this->assertSame('Foo Bar', $page->data('title')); } } From 2f0f483a8af7fe623ba6c4d78a00708e627d1814 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 18:57:24 +0200 Subject: [PATCH 023/222] Sort assertions --- packages/framework/tests/Feature/SourceFileParserTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/SourceFileParserTest.php b/packages/framework/tests/Feature/SourceFileParserTest.php index c4bade3c726..4593096fc51 100644 --- a/packages/framework/tests/Feature/SourceFileParserTest.php +++ b/packages/framework/tests/Feature/SourceFileParserTest.php @@ -38,8 +38,8 @@ public function testMarkdownPageParser() $this->assertInstanceOf(MarkdownPage::class, $page); $this->assertSame('foo', $page->identifier); $this->assertSame('Foo Bar Baz', $page->title); - $this->assertEquals('# Foo Bar', $page->markdown); $this->assertSame('# Foo Bar', $page->markdown->body()); + $this->assertEquals('# Foo Bar', $page->markdown); } public function testMarkdownPostParser() @@ -52,8 +52,8 @@ public function testMarkdownPostParser() $this->assertInstanceOf(MarkdownPost::class, $page); $this->assertSame('foo', $page->identifier); $this->assertSame('Foo Bar Baz', $page->title); - $this->assertEquals('# Foo Bar', $page->markdown); $this->assertSame('# Foo Bar', $page->markdown->body()); + $this->assertEquals('# Foo Bar', $page->markdown); } public function testDocumentationPageParser() @@ -66,8 +66,8 @@ public function testDocumentationPageParser() $this->assertInstanceOf(DocumentationPage::class, $page); $this->assertSame('foo', $page->identifier); $this->assertSame('Foo Bar Baz', $page->title); - $this->assertEquals('# Foo Bar', $page->markdown); $this->assertSame('# Foo Bar', $page->markdown->body()); + $this->assertEquals('# Foo Bar', $page->markdown); } public function testHtmlPageParser() From 57bbbea0c6362a1a044486059e1f876668e8d564 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 18:58:17 +0200 Subject: [PATCH 024/222] Use assert same instead of assert equals --- .../tests/Unit/BuildOutputDirectoryCanBeChangedTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php index 6bd0380a70f..dec0e8ff018 100644 --- a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php +++ b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php @@ -58,12 +58,12 @@ public function testOutputDirectoryIsCreatedIfItDoesNotExistInStaticPageBuilder( public function testSiteOutputDirectoryCanBeChangedInConfiguration() { - $this->assertEquals('_site', Hyde::kernel()->getOutputDirectory()); + $this->assertSame('_site', Hyde::kernel()->getOutputDirectory()); config(['hyde.output_directory' => '_site/build']); (new HydeServiceProvider($this->app))->register(); - $this->assertEquals('_site/build', Hyde::kernel()->getOutputDirectory()); + $this->assertSame('_site/build', Hyde::kernel()->getOutputDirectory()); $this->file('_posts/test-post.md'); StaticPageBuilder::handle(Pages::getPage('_posts/test-post.md')); @@ -75,6 +75,6 @@ public function testSiteOutputDirectoryCanBeChangedInConfiguration() public function testSiteOutputDirectoryPathIsNormalizedToTrimTrailingSlashes() { Hyde::setOutputDirectory('foo/bar/'); - $this->assertEquals('foo/bar', Hyde::kernel()->getOutputDirectory()); + $this->assertSame('foo/bar', Hyde::kernel()->getOutputDirectory()); } } From 9d35b03fec8c37db4e2c33e8ffa5db0a89a10b32 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 18:58:30 +0200 Subject: [PATCH 025/222] Add newline --- .../tests/Unit/BuildOutputDirectoryCanBeChangedTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php index dec0e8ff018..94ab6e1895c 100644 --- a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php +++ b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php @@ -67,6 +67,7 @@ public function testSiteOutputDirectoryCanBeChangedInConfiguration() $this->file('_posts/test-post.md'); StaticPageBuilder::handle(Pages::getPage('_posts/test-post.md')); + $this->assertFileExists(Hyde::path('_site/build/posts/test-post.html')); File::deleteDirectory(Hyde::path('_site/build')); From 02a690364f9ddf5fc7793d7e94a5e687b3a0e27e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 18:59:16 +0200 Subject: [PATCH 026/222] Remove redundant type annotation --- packages/framework/tests/Feature/PageModelConstructorsTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageModelConstructorsTest.php b/packages/framework/tests/Feature/PageModelConstructorsTest.php index a87959409b5..5589ed802ff 100644 --- a/packages/framework/tests/Feature/PageModelConstructorsTest.php +++ b/packages/framework/tests/Feature/PageModelConstructorsTest.php @@ -57,7 +57,6 @@ public function testDocumentationPageParserCanGetGroupAutomaticallyFromNestedPag mkdir(Hyde::path('_docs/foo')); touch(Hyde::path('_docs/foo/bar.md')); - /** @var \Hyde\Pages\DocumentationPage $page */ $page = DocumentationPage::parse('foo/bar'); $this->assertSame('foo', $page->navigationMenuGroup()); From e724e6dfbec6620be82c38deea174e00082e25f2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 18:59:33 +0200 Subject: [PATCH 027/222] Normalize code style --- packages/framework/tests/Feature/PageModelConstructorsTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageModelConstructorsTest.php b/packages/framework/tests/Feature/PageModelConstructorsTest.php index 5589ed802ff..ef823b5f8a2 100644 --- a/packages/framework/tests/Feature/PageModelConstructorsTest.php +++ b/packages/framework/tests/Feature/PageModelConstructorsTest.php @@ -25,6 +25,7 @@ public function testDynamicDataConstructorCanFindTitleFromFrontMatter() { $this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'My Title']); $page = MarkdownPage::parse('foo'); + $this->assertSame('My Title', $page->title); } @@ -47,8 +48,8 @@ public function testDynamicDataConstructorCanFindTitleFromSlug() public function testDocumentationPageParserCanGetGroupFromFrontMatter() { $this->markdown('_docs/foo.md', '# Foo Bar', ['navigation.group' => 'foo']); - $page = DocumentationPage::parse('foo'); + $this->assertSame('foo', $page->navigationMenuGroup()); } From 1461c36117e4db1fe7bc8468df4e6f20049f5e81 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:06:38 +0200 Subject: [PATCH 028/222] Use assert same instead of assert equals for scalar types --- .../framework/tests/Unit/DateStringTest.php | 10 ++--- .../tests/Unit/DocumentationPageTest.php | 44 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/framework/tests/Unit/DateStringTest.php b/packages/framework/tests/Unit/DateStringTest.php index 5f5384707f6..602ce7b2ed8 100644 --- a/packages/framework/tests/Unit/DateStringTest.php +++ b/packages/framework/tests/Unit/DateStringTest.php @@ -16,7 +16,7 @@ class DateStringTest extends UnitTestCase public function testItCanParseDateString() { $dateString = new DateString('2020-01-01'); - $this->assertEquals('2020-01-01', $dateString->string); + $this->assertSame('2020-01-01', $dateString->string); } public function testItCanParseDateStringIntoDatetimeObject() @@ -28,24 +28,24 @@ public function testItCanParseDateStringIntoDatetimeObject() public function testItCanFormatDateStringIntoMachineReadableString() { $dateString = new DateString('2020-01-01 UTC'); - $this->assertEquals('2020-01-01T00:00:00+00:00', $dateString->datetime); + $this->assertSame('2020-01-01T00:00:00+00:00', $dateString->datetime); } public function testItCanFormatDateStringIntoHumanReadableString() { $dateString = new DateString('2020-01-01 UTC'); - $this->assertEquals('Wednesday Jan 1st, 2020, at 12:00am', $dateString->sentence); + $this->assertSame('Wednesday Jan 1st, 2020, at 12:00am', $dateString->sentence); } public function testItCanFormatDateStringIntoShortHumanReadableString() { $dateString = new DateString('2020-01-01 UTC'); - $this->assertEquals('Jan 1st, 2020', $dateString->short); + $this->assertSame('Jan 1st, 2020', $dateString->short); } public function testItCanFormatDateStringIntoShortHumanReadableStringUsingMagicMethod() { $dateString = new DateString('2022-01-01 UTC'); - $this->assertEquals('Jan 1st, 2022', (string) $dateString); + $this->assertSame('Jan 1st, 2022', (string) $dateString); } } diff --git a/packages/framework/tests/Unit/DocumentationPageTest.php b/packages/framework/tests/Unit/DocumentationPageTest.php index b725e59477a..f51cdc979a7 100644 --- a/packages/framework/tests/Unit/DocumentationPageTest.php +++ b/packages/framework/tests/Unit/DocumentationPageTest.php @@ -31,7 +31,7 @@ public function testCanGenerateTableOfContents() public function testCanGetCurrentPagePath() { $page = DocumentationPage::make('foo'); - $this->assertEquals('docs/foo', $page->getRouteKey()); + $this->assertSame('docs/foo', $page->getRouteKey()); } public function testCanGetCurrentCustomPagePath() @@ -40,7 +40,7 @@ public function testCanGetCurrentCustomPagePath() (new HydeServiceProvider($this->app))->register(); $page = DocumentationPage::make('foo'); - $this->assertEquals('documentation/latest/foo', $page->getRouteKey()); + $this->assertSame('documentation/latest/foo', $page->getRouteKey()); } public function testCanGetCurrentPagePathWhenUsingFlattenedOutputPaths() @@ -48,13 +48,13 @@ public function testCanGetCurrentPagePathWhenUsingFlattenedOutputPaths() Config::set('docs.flattened_output_paths', true); $page = DocumentationPage::make('foo/bar'); - $this->assertEquals('docs/bar', $page->getRouteKey()); + $this->assertSame('docs/bar', $page->getRouteKey()); config(['hyde.output_directories.documentation-page' => 'documentation/latest/']); (new HydeServiceProvider($this->app))->register(); $page = DocumentationPage::make('foo/bar'); - $this->assertEquals('documentation/latest/bar', $page->getRouteKey()); + $this->assertSame('documentation/latest/bar', $page->getRouteKey()); } public function testCanGetCurrentPagePathWhenNotUsingFlattenedOutputPaths() @@ -62,13 +62,13 @@ public function testCanGetCurrentPagePathWhenNotUsingFlattenedOutputPaths() Config::set('docs.flattened_output_paths', false); $page = DocumentationPage::make('foo/bar'); - $this->assertEquals('docs/foo/bar', $page->getRouteKey()); + $this->assertSame('docs/foo/bar', $page->getRouteKey()); config(['hyde.output_directories.documentation-page' => 'documentation/latest/']); (new HydeServiceProvider($this->app))->register(); $page = DocumentationPage::make('foo/bar'); - $this->assertEquals('documentation/latest/foo/bar', $page->getRouteKey()); + $this->assertSame('documentation/latest/foo/bar', $page->getRouteKey()); } public function testCanGetOnlineSourcePath() @@ -81,7 +81,7 @@ public function testCanGetOnlineSourcePathWithSourceFileLocationBase() { config(['docs.source_file_location_base' => 'docs.example.com/edit']); $page = DocumentationPage::make('foo'); - $this->assertEquals('docs.example.com/edit/foo.md', $page->getOnlineSourcePath()); + $this->assertSame('docs.example.com/edit/foo.md', $page->getOnlineSourcePath()); } public function testCanGetOnlineSourcePathWithTrailingSlash() @@ -89,22 +89,22 @@ public function testCanGetOnlineSourcePathWithTrailingSlash() $page = DocumentationPage::make('foo'); config(['docs.source_file_location_base' => 'edit/']); - $this->assertEquals('edit/foo.md', $page->getOnlineSourcePath()); + $this->assertSame('edit/foo.md', $page->getOnlineSourcePath()); config(['docs.source_file_location_base' => 'edit']); - $this->assertEquals('edit/foo.md', $page->getOnlineSourcePath()); + $this->assertSame('edit/foo.md', $page->getOnlineSourcePath()); } public function testCanGetDocumentationOutputPath() { - $this->assertEquals('docs', DocumentationPage::outputDirectory()); + $this->assertSame('docs', DocumentationPage::outputDirectory()); } public function testCanGetDocumentationOutputPathWithCustomOutputDirectory() { config(['hyde.output_directories.documentation-page' => 'foo']); (new HydeServiceProvider($this->app))->register(); - $this->assertEquals('foo', DocumentationPage::outputDirectory()); + $this->assertSame('foo', DocumentationPage::outputDirectory()); } public function testCanGetDocumentationOutputPathWithTrailingSlashes() @@ -120,13 +120,13 @@ public function testCanGetDocumentationOutputPathWithTrailingSlashes() foreach ($tests as $test) { config(['hyde.output_directories.documentation-page' => $test]); (new HydeServiceProvider($this->app))->register(); - $this->assertEquals('foo', DocumentationPage::outputDirectory()); + $this->assertSame('foo', DocumentationPage::outputDirectory()); } } public function testGetSourcePathReturnsQualifiedBasename() { - $this->assertEquals( + $this->assertSame( DocumentationPage::sourcePath('foo'), (new DocumentationPage(identifier: 'foo'))->getSourcePath() ); @@ -134,7 +134,7 @@ public function testGetSourcePathReturnsQualifiedBasename() public function testGetSourcePathReturnsQualifiedBasenameForNestedPage() { - $this->assertEquals( + $this->assertSame( DocumentationPage::sourcePath('foo/bar'), (new DocumentationPage(identifier: 'foo/bar'))->getSourcePath() ); @@ -149,7 +149,7 @@ public function testHomeMethodReturnsDocsIndexRouteWhenItExists() { Filesystem::touch('_docs/index.md'); $this->assertInstanceOf(Route::class, DocumentationPage::home()); - $this->assertEquals(Routes::get('docs/index'), DocumentationPage::home()); + $this->assertSame(Routes::get('docs/index'), DocumentationPage::home()); Filesystem::unlink('_docs/index.md'); } @@ -160,7 +160,7 @@ public function testHomeMethodFindsDocsIndexForCustomOutputDirectory() mkdir(Hyde::path('foo')); Filesystem::touch('_docs/index.md'); $this->assertInstanceOf(Route::class, DocumentationPage::home()); - $this->assertEquals(Routes::get('foo/index'), DocumentationPage::home()); + $this->assertSame(Routes::get('foo/index'), DocumentationPage::home()); Filesystem::unlink('_docs/index.md'); File::deleteDirectory(Hyde::path('foo')); } @@ -173,7 +173,7 @@ public function testHomeMethodFindsDocsIndexForCustomNestedOutputDirectory() mkdir(Hyde::path('foo/bar')); Filesystem::touch('_docs/index.md'); $this->assertInstanceOf(Route::class, DocumentationPage::home()); - $this->assertEquals(Routes::get('foo/bar/index'), DocumentationPage::home()); + $this->assertSame(Routes::get('foo/bar/index'), DocumentationPage::home()); Filesystem::unlink('_docs/index.md'); File::deleteDirectory(Hyde::path('foo')); } @@ -205,21 +205,21 @@ public function testHasTableOfContents() public function testCompiledPagesOriginatingInSubdirectoriesGetOutputToRootDocsPath() { $page = DocumentationPage::make('foo/bar'); - $this->assertEquals('docs/bar.html', $page->getOutputPath()); + $this->assertSame('docs/bar.html', $page->getOutputPath()); } public function testCompiledPagesOriginatingInSubdirectoriesGetOutputToRootDocsPathWhenUsingFlattenedOutputPaths() { Config::set('docs.flattened_output_paths', true); $page = DocumentationPage::make('foo/bar'); - $this->assertEquals('docs/bar.html', $page->getOutputPath()); + $this->assertSame('docs/bar.html', $page->getOutputPath()); } public function testCompiledPagesOriginatingInSubdirectoriesRetainSubdirectoryStructureWhenNotUsingFlattenedOutputPaths() { Config::set('docs.flattened_output_paths', false); $page = DocumentationPage::make('foo/bar'); - $this->assertEquals('docs/foo/bar.html', $page->getOutputPath()); + $this->assertSame('docs/foo/bar.html', $page->getOutputPath()); } public function testPageHasFrontMatter() @@ -262,7 +262,7 @@ public function testPageCanSetSidebarPriorityUsingFrontMatter() --- '); $page = DocumentationPage::parse('foo'); - $this->assertEquals(10, $page->navigationMenuPriority()); + $this->assertSame(10, $page->navigationMenuPriority()); } public function testPageCanSetSidebarLabelUsingFrontMatter() @@ -273,6 +273,6 @@ public function testPageCanSetSidebarLabelUsingFrontMatter() --- '); $page = DocumentationPage::parse('foo'); - $this->assertEquals('Bar', $page->navigationMenuLabel()); + $this->assertSame('Bar', $page->navigationMenuLabel()); } } From cabab110df6b26fa97b4147f5ef43dcd1e4c36a9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:08:41 +0200 Subject: [PATCH 029/222] Cleanup test file formatting --- .../tests/Unit/DocumentationPageTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/framework/tests/Unit/DocumentationPageTest.php b/packages/framework/tests/Unit/DocumentationPageTest.php index f51cdc979a7..ff512fc2088 100644 --- a/packages/framework/tests/Unit/DocumentationPageTest.php +++ b/packages/framework/tests/Unit/DocumentationPageTest.php @@ -80,6 +80,7 @@ public function testCanGetOnlineSourcePath() public function testCanGetOnlineSourcePathWithSourceFileLocationBase() { config(['docs.source_file_location_base' => 'docs.example.com/edit']); + $page = DocumentationPage::make('foo'); $this->assertSame('docs.example.com/edit/foo.md', $page->getOnlineSourcePath()); } @@ -104,6 +105,7 @@ public function testCanGetDocumentationOutputPathWithCustomOutputDirectory() { config(['hyde.output_directories.documentation-page' => 'foo']); (new HydeServiceProvider($this->app))->register(); + $this->assertSame('foo', DocumentationPage::outputDirectory()); } @@ -148,8 +150,10 @@ public function testHomeMethodReturnsNullWhenThereIsNoIndexPage() public function testHomeMethodReturnsDocsIndexRouteWhenItExists() { Filesystem::touch('_docs/index.md'); + $this->assertInstanceOf(Route::class, DocumentationPage::home()); $this->assertSame(Routes::get('docs/index'), DocumentationPage::home()); + Filesystem::unlink('_docs/index.md'); } @@ -157,10 +161,13 @@ public function testHomeMethodFindsDocsIndexForCustomOutputDirectory() { config(['hyde.output_directories.documentation-page' => 'foo']); (new HydeServiceProvider($this->app))->register(); + mkdir(Hyde::path('foo')); Filesystem::touch('_docs/index.md'); + $this->assertInstanceOf(Route::class, DocumentationPage::home()); $this->assertSame(Routes::get('foo/index'), DocumentationPage::home()); + Filesystem::unlink('_docs/index.md'); File::deleteDirectory(Hyde::path('foo')); } @@ -169,11 +176,14 @@ public function testHomeMethodFindsDocsIndexForCustomNestedOutputDirectory() { config(['hyde.output_directories.documentation-page' => 'foo/bar']); (new HydeServiceProvider($this->app))->register(); + mkdir(Hyde::path('foo')); mkdir(Hyde::path('foo/bar')); Filesystem::touch('_docs/index.md'); + $this->assertInstanceOf(Route::class, DocumentationPage::home()); $this->assertSame(Routes::get('foo/bar/index'), DocumentationPage::home()); + Filesystem::unlink('_docs/index.md'); File::deleteDirectory(Hyde::path('foo')); } @@ -205,12 +215,14 @@ public function testHasTableOfContents() public function testCompiledPagesOriginatingInSubdirectoriesGetOutputToRootDocsPath() { $page = DocumentationPage::make('foo/bar'); + $this->assertSame('docs/bar.html', $page->getOutputPath()); } public function testCompiledPagesOriginatingInSubdirectoriesGetOutputToRootDocsPathWhenUsingFlattenedOutputPaths() { Config::set('docs.flattened_output_paths', true); + $page = DocumentationPage::make('foo/bar'); $this->assertSame('docs/bar.html', $page->getOutputPath()); } @@ -218,6 +230,7 @@ public function testCompiledPagesOriginatingInSubdirectoriesGetOutputToRootDocsP public function testCompiledPagesOriginatingInSubdirectoriesRetainSubdirectoryStructureWhenNotUsingFlattenedOutputPaths() { Config::set('docs.flattened_output_paths', false); + $page = DocumentationPage::make('foo/bar'); $this->assertSame('docs/foo/bar.html', $page->getOutputPath()); } @@ -230,10 +243,13 @@ public function testPageHasFrontMatter() 'baz' => 'qux', ], ]); + $page = DocumentationPage::parse('foo'); + $this->assertNotNull($page->matter()); $this->assertNotEmpty($page->matter()); $this->assertEquals(new FrontMatter($expected), $page->matter()); + $this->assertSame($expected, $page->matter()->get()); } public function testPageCanBeHiddenFromSidebarUsingFrontMatter() @@ -243,6 +259,7 @@ public function testPageCanBeHiddenFromSidebarUsingFrontMatter() 'hidden' => true, ], ]); + $page = DocumentationPage::parse('foo'); $this->assertFalse($page->showInNavigation()); } @@ -250,6 +267,7 @@ public function testPageCanBeHiddenFromSidebarUsingFrontMatter() public function testPageIsVisibleInSidebarWithoutUsingFrontMatter() { $this->markdown('_docs/foo.md'); + $page = DocumentationPage::parse('foo'); $this->assertTrue($page->showInNavigation()); } @@ -261,6 +279,7 @@ public function testPageCanSetSidebarPriorityUsingFrontMatter() priority: 10 --- '); + $page = DocumentationPage::parse('foo'); $this->assertSame(10, $page->navigationMenuPriority()); } @@ -272,6 +291,7 @@ public function testPageCanSetSidebarLabelUsingFrontMatter() label: Bar --- '); + $page = DocumentationPage::parse('foo'); $this->assertSame('Bar', $page->navigationMenuLabel()); } From c6a60f6e8a21339302f5f8158cb356605aaaa0ec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:09:11 +0200 Subject: [PATCH 030/222] Use assert same instead of assert equals --- .../HyperlinksUrlPathHelpersTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php b/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php index 8da1536405d..cfd4fee8043 100644 --- a/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php +++ b/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php @@ -39,39 +39,39 @@ public function testHasSiteUrlReturnsTrueWhenSiteUrlIsSet() public function testQualifiedUrlReturnsSiteUrlWhenNoPathIsGiven() { config(['hyde.url' => 'https://example.com']); - $this->assertEquals('https://example.com', $this->class->url()); + $this->assertSame('https://example.com', $this->class->url()); } public function testQualifiedUrlReturnsSiteUrlPlusGivenPath() { config(['hyde.url' => 'https://example.com']); - $this->assertEquals('https://example.com/path', $this->class->url('path')); + $this->assertSame('https://example.com/path', $this->class->url('path')); } public function testQualifiedUrlReturnsSiteUrlPlusGivenPathWithExtension() { config(['hyde.url' => 'https://example.com']); - $this->assertEquals('https://example.com/path.html', $this->class->url('path.html')); + $this->assertSame('https://example.com/path.html', $this->class->url('path.html')); } public function testQualifiedUrlReturnsSiteUrlPlusGivenPathWithExtensionAndQueryString() { config(['hyde.url' => 'https://example.com']); - $this->assertEquals('https://example.com/path.html?query=string', $this->class->url('path.html?query=string')); + $this->assertSame('https://example.com/path.html?query=string', $this->class->url('path.html?query=string')); } public function testQualifiedUrlTrimsTrailingSlashes() { config(['hyde.url' => 'https://example.com/']); - $this->assertEquals('https://example.com', $this->class->url()); - $this->assertEquals('https://example.com', $this->class->url('/')); - $this->assertEquals('https://example.com/foo', $this->class->url('/foo/')); + $this->assertSame('https://example.com', $this->class->url()); + $this->assertSame('https://example.com', $this->class->url('/')); + $this->assertSame('https://example.com/foo', $this->class->url('/foo/')); } public function testQualifiedUrlAcceptsMultipleSchemes() { config(['hyde.url' => 'http://example.com']); - $this->assertEquals('http://example.com', $this->class->url()); + $this->assertSame('http://example.com', $this->class->url()); } public function testQualifiedUrlThrowsExceptionWhenNoSiteUrlIsSet() @@ -85,14 +85,14 @@ public function testQualifiedUrlThrowsExceptionWhenNoSiteUrlIsSet() public function testHelperReturnsExpectedStringWhenSiteUrlIsSet() { config(['hyde.url' => 'https://example.com']); - $this->assertEquals('https://example.com/foo/bar.html', $this->class->url('foo/bar.html')); + $this->assertSame('https://example.com/foo/bar.html', $this->class->url('foo/bar.html')); } public function testHelperReturnsExpectedStringWhenPrettyUrlsAreEnabled() { config(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]); - $this->assertEquals('https://example.com', $this->class->url('index.html')); - $this->assertEquals('https://example.com/foo', $this->class->url('foo.html')); - $this->assertEquals('https://example.com/docs', $this->class->url('docs/index.html')); + $this->assertSame('https://example.com', $this->class->url('index.html')); + $this->assertSame('https://example.com/foo', $this->class->url('foo.html')); + $this->assertSame('https://example.com/docs', $this->class->url('docs/index.html')); } } From 4ce89f5f0715d809180094305bdd2bdef3d0f827 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:09:44 +0200 Subject: [PATCH 031/222] Add code newlines between setup and assertions --- .../Unit/Foundation/HyperlinksUrlPathHelpersTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php b/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php index cfd4fee8043..be8fafa99c9 100644 --- a/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php +++ b/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php @@ -27,42 +27,49 @@ protected function setUp(): void public function testHasSiteUrlReturnsFalseWhenNoSiteUrlIsSet() { config(['hyde.url' => null]); + $this->assertFalse($this->class->hasSiteUrl()); } public function testHasSiteUrlReturnsTrueWhenSiteUrlIsSet() { config(['hyde.url' => 'https://example.com']); + $this->assertTrue($this->class->hasSiteUrl()); } public function testQualifiedUrlReturnsSiteUrlWhenNoPathIsGiven() { config(['hyde.url' => 'https://example.com']); + $this->assertSame('https://example.com', $this->class->url()); } public function testQualifiedUrlReturnsSiteUrlPlusGivenPath() { config(['hyde.url' => 'https://example.com']); + $this->assertSame('https://example.com/path', $this->class->url('path')); } public function testQualifiedUrlReturnsSiteUrlPlusGivenPathWithExtension() { config(['hyde.url' => 'https://example.com']); + $this->assertSame('https://example.com/path.html', $this->class->url('path.html')); } public function testQualifiedUrlReturnsSiteUrlPlusGivenPathWithExtensionAndQueryString() { config(['hyde.url' => 'https://example.com']); + $this->assertSame('https://example.com/path.html?query=string', $this->class->url('path.html?query=string')); } public function testQualifiedUrlTrimsTrailingSlashes() { config(['hyde.url' => 'https://example.com/']); + $this->assertSame('https://example.com', $this->class->url()); $this->assertSame('https://example.com', $this->class->url('/')); $this->assertSame('https://example.com/foo', $this->class->url('/foo/')); @@ -71,26 +78,31 @@ public function testQualifiedUrlTrimsTrailingSlashes() public function testQualifiedUrlAcceptsMultipleSchemes() { config(['hyde.url' => 'http://example.com']); + $this->assertSame('http://example.com', $this->class->url()); } public function testQualifiedUrlThrowsExceptionWhenNoSiteUrlIsSet() { config(['hyde.url' => null]); + $this->expectException(BaseUrlNotSetException::class); $this->expectExceptionMessage('No site URL has been set in config (or .env).'); + $this->class->url(); } public function testHelperReturnsExpectedStringWhenSiteUrlIsSet() { config(['hyde.url' => 'https://example.com']); + $this->assertSame('https://example.com/foo/bar.html', $this->class->url('foo/bar.html')); } public function testHelperReturnsExpectedStringWhenPrettyUrlsAreEnabled() { config(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]); + $this->assertSame('https://example.com', $this->class->url('index.html')); $this->assertSame('https://example.com/foo', $this->class->url('foo.html')); $this->assertSame('https://example.com/docs', $this->class->url('docs/index.html')); From bff5ee45acff5a8ff8a04c860057a748a14a2995 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:10:10 +0200 Subject: [PATCH 032/222] Use assert same instead of assert equals --- .../tests/Unit/FrontMatterModelTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/framework/tests/Unit/FrontMatterModelTest.php b/packages/framework/tests/Unit/FrontMatterModelTest.php index fa566a31964..363333cf810 100644 --- a/packages/framework/tests/Unit/FrontMatterModelTest.php +++ b/packages/framework/tests/Unit/FrontMatterModelTest.php @@ -24,25 +24,25 @@ public function testConstructorArgumentsAreOptional() public function testConstructorArgumentsAreAssigned() { - $this->assertEquals(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray()); + $this->assertSame(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray()); } public function testStaticFromArrayMethodCreatesNewFrontMatterModel() { $matter = FrontMatter::fromArray(['foo' => 'bar']); $this->assertInstanceOf(FrontMatter::class, $matter); - $this->assertEquals(['foo' => 'bar'], $matter->toArray()); + $this->assertSame(['foo' => 'bar'], $matter->toArray()); } public function testToStringMagicMethodConvertsModelArrayIntoYamlFrontMatter() { $matter = new FrontMatter(['foo' => 'bar']); - $this->assertEquals("---\nfoo: bar\n---\n", (string) (new FrontMatter(['foo' => 'bar']))); + $this->assertSame("---\nfoo: bar\n---\n", (string) (new FrontMatter(['foo' => 'bar']))); } public function testMagicGetMethodReturnsFrontMatterProperty() { - $this->assertEquals('bar', (new FrontMatter(['foo' => 'bar']))->foo); + $this->assertSame('bar', (new FrontMatter(['foo' => 'bar']))->foo); } public function testMagicGetMethodReturnsNullIfPropertyDoesNotExist() @@ -68,17 +68,17 @@ public function testGetMethodReturnsNullIfSpecifiedFrontMatterKeyDoesNotExist() public function testGetMethodReturnsSpecifiedDefaultValueIfPropertyDoesNotExist() { $matter = new FrontMatter(); - $this->assertEquals('default', $matter->get('bar', 'default')); + $this->assertSame('default', $matter->get('bar', 'default')); } public function testGetMethodReturnsSpecifiedFrontMatterValueIfKeyIsSpecified() { - $this->assertEquals('bar', (new FrontMatter(['foo' => 'bar']))->get('foo')); + $this->assertSame('bar', (new FrontMatter(['foo' => 'bar']))->get('foo')); } public function testSetMethodSetsFrontMatterProperty() { - $this->assertEquals('bar', (new FrontMatter())->set('foo', 'bar')->get('foo')); + $this->assertSame('bar', (new FrontMatter())->set('foo', 'bar')->get('foo')); } public function testSetMethodReturnsSelf() @@ -99,6 +99,6 @@ public function testHasMethodReturnsFalseIfPropertyDoesNotExist() public function testToArrayReturnsFrontMatterArray() { - $this->assertEquals(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray()); + $this->assertSame(['foo' => 'bar'], (new FrontMatter(['foo' => 'bar']))->toArray()); } } From 326d155287f7ec6735c8535e19e7932d4b7f5e02 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:10:31 +0200 Subject: [PATCH 033/222] Add code newlines between setup and assertions --- packages/framework/tests/Unit/FrontMatterModelTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/tests/Unit/FrontMatterModelTest.php b/packages/framework/tests/Unit/FrontMatterModelTest.php index 363333cf810..09e6c1344d5 100644 --- a/packages/framework/tests/Unit/FrontMatterModelTest.php +++ b/packages/framework/tests/Unit/FrontMatterModelTest.php @@ -30,6 +30,7 @@ public function testConstructorArgumentsAreAssigned() public function testStaticFromArrayMethodCreatesNewFrontMatterModel() { $matter = FrontMatter::fromArray(['foo' => 'bar']); + $this->assertInstanceOf(FrontMatter::class, $matter); $this->assertSame(['foo' => 'bar'], $matter->toArray()); } @@ -37,6 +38,7 @@ public function testStaticFromArrayMethodCreatesNewFrontMatterModel() public function testToStringMagicMethodConvertsModelArrayIntoYamlFrontMatter() { $matter = new FrontMatter(['foo' => 'bar']); + $this->assertSame("---\nfoo: bar\n---\n", (string) (new FrontMatter(['foo' => 'bar']))); } @@ -68,6 +70,7 @@ public function testGetMethodReturnsNullIfSpecifiedFrontMatterKeyDoesNotExist() public function testGetMethodReturnsSpecifiedDefaultValueIfPropertyDoesNotExist() { $matter = new FrontMatter(); + $this->assertSame('default', $matter->get('bar', 'default')); } @@ -84,6 +87,7 @@ public function testSetMethodSetsFrontMatterProperty() public function testSetMethodReturnsSelf() { $matter = new FrontMatter(); + $this->assertSame($matter, $matter->set('foo', 'bar')); } From 1fb29962fe852f2d518cc546a8decd6bb73529cb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:10:54 +0200 Subject: [PATCH 034/222] Use setup shorthands --- .../framework/tests/Unit/GenerateBuildManifestTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Unit/GenerateBuildManifestTest.php b/packages/framework/tests/Unit/GenerateBuildManifestTest.php index f3ffc9fd849..1cb432011b7 100644 --- a/packages/framework/tests/Unit/GenerateBuildManifestTest.php +++ b/packages/framework/tests/Unit/GenerateBuildManifestTest.php @@ -15,11 +15,8 @@ */ class GenerateBuildManifestTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - self::mockConfig(); - } + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; public function testActionGeneratesBuildManifest() { From 364528e268e1a88e7b81dd027ceee7a2ae277a02 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:12:05 +0200 Subject: [PATCH 035/222] Use assert same instead of assert equals --- .../framework/tests/Unit/GenerateBuildManifestTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Unit/GenerateBuildManifestTest.php b/packages/framework/tests/Unit/GenerateBuildManifestTest.php index 1cb432011b7..8b2ec50c140 100644 --- a/packages/framework/tests/Unit/GenerateBuildManifestTest.php +++ b/packages/framework/tests/Unit/GenerateBuildManifestTest.php @@ -38,13 +38,13 @@ public function testActionGeneratesBuildManifest() $this->assertArrayHasKey('source_hash', $manifest['pages'][404]); $this->assertArrayHasKey('output_hash', $manifest['pages'][404]); - $this->assertEquals('_pages/404.blade.php', $manifest['pages'][404]['source_path']); - $this->assertEquals('_pages/index.blade.php', $manifest['pages']['index']['source_path']); + $this->assertSame('_pages/404.blade.php', $manifest['pages'][404]['source_path']); + $this->assertSame('_pages/index.blade.php', $manifest['pages']['index']['source_path']); - $this->assertEquals('404.html', $manifest['pages'][404]['output_path']); - $this->assertEquals('index.html', $manifest['pages']['index']['output_path']); + $this->assertSame('404.html', $manifest['pages'][404]['output_path']); + $this->assertSame('index.html', $manifest['pages']['index']['output_path']); - $this->assertEquals(unixsum_file(Hyde::path('_pages/404.blade.php')), $manifest['pages'][404]['source_hash']); + $this->assertSame(unixsum_file(Hyde::path('_pages/404.blade.php')), $manifest['pages'][404]['source_hash']); $this->assertNull($manifest['pages'][404]['output_hash']); } } From 0f707ebe0d1ff8e9d0abe6e1b20cefcddc600299 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:14:31 +0200 Subject: [PATCH 036/222] Clean up test and improve assertions --- .../tests/Feature/AssetServiceTest.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/AssetServiceTest.php b/packages/framework/tests/Feature/AssetServiceTest.php index b45d4d7b0f0..ae8661b8118 100644 --- a/packages/framework/tests/Feature/AssetServiceTest.php +++ b/packages/framework/tests/Feature/AssetServiceTest.php @@ -18,26 +18,33 @@ class AssetServiceTest extends TestCase public function testMediaLinkReturnsMediaPathWithCacheKey() { $service = new AssetService(); + $this->assertIsString($path = $service->mediaLink('app.css')); - $this->assertEquals('media/app.css?v='.md5_file(Hyde::path('_media/app.css')), $path); + $this->assertSame('media/app.css?v='.md5_file(Hyde::path('_media/app.css')), $path); } public function testMediaLinkReturnsMediaPathWithoutCacheKeyIfCacheBustingIsDisabled() { config(['hyde.enable_cache_busting' => false]); + $service = new AssetService(); - $this->assertIsString($path = $service->mediaLink('app.css')); - $this->assertEquals('media/app.css', $path); + $path = $service->mediaLink('app.css'); + + $this->assertIsString($path); + $this->assertSame('media/app.css', $path); } public function testMediaLinkSupportsCustomMediaDirectories() { $this->directory('_assets'); $this->file('_assets/app.css'); + Hyde::setMediaDirectory('_assets'); $service = new AssetService(); - $this->assertIsString($path = $service->mediaLink('app.css')); - $this->assertEquals('assets/app.css?v='.md5_file(Hyde::path('_assets/app.css')), $path); + $path = $service->mediaLink('app.css'); + + $this->assertIsString($path); + $this->assertSame('assets/app.css?v='.md5_file(Hyde::path('_assets/app.css')), $path); } } From d2bd9134e851eeea5e69c1e2e1d000349a533cd0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:14:58 +0200 Subject: [PATCH 037/222] Use assert same instead of assert equals --- .../framework/tests/Feature/BladeMatterParserTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/BladeMatterParserTest.php b/packages/framework/tests/Feature/BladeMatterParserTest.php index d10deb88dbf..7c1d373df91 100644 --- a/packages/framework/tests/Feature/BladeMatterParserTest.php +++ b/packages/framework/tests/Feature/BladeMatterParserTest.php @@ -17,7 +17,7 @@ public function testCanParseFrontMatter() { $parser = new BladeMatterParser('@php($foo = "bar")'); $parser->parse(); - $this->assertEquals(['foo' => 'bar'], $parser->get()); + $this->assertSame(['foo' => 'bar'], $parser->get()); } public function testParseStringHelperMethod() @@ -44,7 +44,7 @@ public function testCanParseMultipleFrontMatterLines() @php($bar = 'baz') @php($baz = 'qux') BLADE; - $this->assertEquals(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux'], BladeMatterParser::parseString($document)); + $this->assertSame(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux'], BladeMatterParser::parseString($document)); } public function testCanParseFrontMatterWithVariousFormats() @@ -57,14 +57,14 @@ public function testCanParseFrontMatterWithVariousFormats() ]; foreach ($matrix as $input => $expected) { - $this->assertEquals($expected, BladeMatterParser::parseString($input)); + $this->assertSame($expected, BladeMatterParser::parseString($input)); } } public function testCanParseFrontMatterWithArray() { $document = "@php(\$foo = ['bar' => 'baz'])"; - $this->assertEquals(['foo' => ['bar' => 'baz']], BladeMatterParser::parseString($document)); + $this->assertSame(['foo' => ['bar' => 'baz']], BladeMatterParser::parseString($document)); } public function testLineMatchesFrontMatter() From 58f47192a9aabb14ab9ea08331c272e37197bcc1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:15:32 +0200 Subject: [PATCH 038/222] Cleanup test --- packages/framework/tests/Feature/BladeMatterParserTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/framework/tests/Feature/BladeMatterParserTest.php b/packages/framework/tests/Feature/BladeMatterParserTest.php index 7c1d373df91..c7c07ca8d30 100644 --- a/packages/framework/tests/Feature/BladeMatterParserTest.php +++ b/packages/framework/tests/Feature/BladeMatterParserTest.php @@ -17,6 +17,7 @@ public function testCanParseFrontMatter() { $parser = new BladeMatterParser('@php($foo = "bar")'); $parser->parse(); + $this->assertSame(['foo' => 'bar'], $parser->get()); } @@ -31,6 +32,7 @@ public function testParseStringHelperMethod() public function testParseFileHelperMethod() { $this->file('foo', 'foo'); + $this->assertSame( (new BladeMatterParser('foo'))->parse()->get(), BladeMatterParser::parseFile('foo') @@ -44,6 +46,7 @@ public function testCanParseMultipleFrontMatterLines() @php($bar = 'baz') @php($baz = 'qux') BLADE; + $this->assertSame(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux'], BladeMatterParser::parseString($document)); } @@ -64,6 +67,7 @@ public function testCanParseFrontMatterWithVariousFormats() public function testCanParseFrontMatterWithArray() { $document = "@php(\$foo = ['bar' => 'baz'])"; + $this->assertSame(['foo' => ['bar' => 'baz']], BladeMatterParser::parseString($document)); } @@ -126,12 +130,14 @@ public function testParseArrayString() public function testParseInvalidArrayString() { $this->expectException(RuntimeException::class); + ParserTestClass::parseArrayString('foo'); } public function testParseMultidimensionalArrayString() { $this->expectException(RuntimeException::class); + ParserTestClass::parseArrayString('["foo" => ["bar" => "baz"]]'); } } From be1911a9d9b7c625eaac654b77514daeb620d053 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:18:13 +0200 Subject: [PATCH 039/222] Cleanup and improve test --- .../Commands/PublishHomepageCommandTest.php | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/framework/tests/Feature/Commands/PublishHomepageCommandTest.php b/packages/framework/tests/Feature/Commands/PublishHomepageCommandTest.php index bd0bdfc0e8d..f04a063227f 100644 --- a/packages/framework/tests/Feature/Commands/PublishHomepageCommandTest.php +++ b/packages/framework/tests/Feature/Commands/PublishHomepageCommandTest.php @@ -23,6 +23,10 @@ protected function setUp(): void protected function tearDown(): void { + if (Filesystem::exists('_pages/index.blade.php')) { + Filesystem::unlink('_pages/index.blade.php'); + } + $this->restoreDefaultPages(); parent::tearDown(); @@ -39,7 +43,7 @@ public function testCommandReturnsExpectedOutput() ->expectsConfirmation('Would you like to rebuild the site?') ->assertExitCode(0); - $this->assertFileExistsThenDeleteIt(); + $this->assertFileExists(Hyde::path('_pages/index.blade.php')); } public function testCommandReturnsExpectedOutputWithRebuild() @@ -50,7 +54,7 @@ public function testCommandReturnsExpectedOutputWithRebuild() ->expectsOutput('Site is built!') ->assertExitCode(0); - $this->assertFileExistsThenDeleteIt(); + $this->assertFileExists(Hyde::path('_pages/index.blade.php')); $this->resetSite(); } @@ -65,7 +69,7 @@ public function testCommandPromptsForOutput() ->expectsConfirmation('Would you like to rebuild the site?') ->assertExitCode(0); - $this->assertFileExistsThenDeleteIt(); + $this->assertFileExists(Hyde::path('_pages/index.blade.php')); } public function testCommandShowsFeedbackOutputWhenSupplyingAHomepageName() @@ -75,7 +79,7 @@ public function testCommandShowsFeedbackOutputWhenSupplyingAHomepageName() ->expectsConfirmation('Would you like to rebuild the site?', false) ->assertExitCode(0); - $this->assertFileExistsThenDeleteIt(); + $this->assertFileExists(Hyde::path('_pages/index.blade.php')); } public function testCommandHandlesErrorCode404() @@ -93,9 +97,9 @@ public function testCommandDoesNotOverwriteModifiedFilesWithoutForceFlag() $this->artisan('publish:homepage welcome') ->assertExitCode(409); - $this->assertEquals('foo', file_get_contents(Hyde::path('_pages/index.blade.php'))); + $this->assertSame('foo', file_get_contents(Hyde::path('_pages/index.blade.php'))); - $this->assertFileExistsThenDeleteIt(); + $this->assertFileExists(Hyde::path('_pages/index.blade.php')); } public function testCommandOverwritesModifiedFilesIfForceFlagIsSet() @@ -107,7 +111,7 @@ public function testCommandOverwritesModifiedFilesIfForceFlagIsSet() $this->assertNotEquals('foo', file_get_contents(Hyde::path('_pages/index.blade.php'))); - $this->assertFileExistsThenDeleteIt(); + $this->assertFileExists(Hyde::path('_pages/index.blade.php')); } public function testCommandDoesNotReturn409IfTheCurrentFileIsADefaultFile() @@ -117,12 +121,6 @@ public function testCommandDoesNotReturn409IfTheCurrentFileIsADefaultFile() $this->artisan('publish:homepage welcome --no-interaction') ->assertExitCode(0); - $this->assertFileExistsThenDeleteIt(); - } - - protected function assertFileExistsThenDeleteIt(): void - { $this->assertFileExists(Hyde::path('_pages/index.blade.php')); - Filesystem::unlink('_pages/index.blade.php'); } } From dc84c8c3699b4cef27c42a68aefb79837c7c8fc5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:18:26 +0200 Subject: [PATCH 040/222] Cleanup and improve test --- .../tests/Feature/Commands/MakePageCommandTest.php | 6 +++++- .../tests/Feature/Commands/PackageDiscoverCommandTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/Commands/MakePageCommandTest.php b/packages/framework/tests/Feature/Commands/MakePageCommandTest.php index 182c3850b41..84fe56be89b 100644 --- a/packages/framework/tests/Feature/Commands/MakePageCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePageCommandTest.php @@ -70,6 +70,7 @@ public function testCommandFailsIfUserSpecifiesInvalidPageType() $this->expectException(Exception::class); $this->expectExceptionMessage('The page type [invalid] is not supported.'); $this->expectExceptionCode(400); + $this->artisan('make:page "foo test page" --type=invalid')->assertExitCode(400); } @@ -92,6 +93,7 @@ public function testCommandCreatesDocumentationFile() $this->artisan('make:page "foo test page" --type="documentation"')->assertExitCode(0); $this->assertFileExists(Hyde::path('_docs/foo-test-page.md')); + Filesystem::unlink('_docs/foo-test-page.md'); } @@ -102,9 +104,10 @@ public function testCommandFailsIfFileAlreadyExists() $this->expectException(FileConflictException::class); $this->expectExceptionMessage('File [_pages/foo-test-page.md] already exists.'); $this->expectExceptionCode(409); + $this->artisan('make:page "foo test page"')->assertExitCode(409); - $this->assertEquals('This should not be overwritten', file_get_contents($this->markdownPath)); + $this->assertSame('This should not be overwritten', file_get_contents($this->markdownPath)); } public function testCommandOverwritesExistingFilesWhenForceOptionIsUsed() @@ -152,6 +155,7 @@ public function testPageTypeShorthandCanBeUsedToCreateDocumentationPages() ->assertExitCode(0); $this->assertFileExists(Hyde::path('_docs/foo-test-page.md')); + Filesystem::unlink('_docs/foo-test-page.md'); } } diff --git a/packages/framework/tests/Feature/Commands/PackageDiscoverCommandTest.php b/packages/framework/tests/Feature/Commands/PackageDiscoverCommandTest.php index e25bed1a5d4..28fdcd113e0 100644 --- a/packages/framework/tests/Feature/Commands/PackageDiscoverCommandTest.php +++ b/packages/framework/tests/Feature/Commands/PackageDiscoverCommandTest.php @@ -17,7 +17,7 @@ public function testPackageDiscoverCommandRegistersManifestPath() { $this->artisan('package:discover')->assertExitCode(0); - $this->assertEquals(Hyde::path('app/storage/framework/cache/packages.php'), + $this->assertSame(Hyde::path('app/storage/framework/cache/packages.php'), $this->app->make(PackageManifest::class)->manifestPath ); From e1dfedd265e5a49db68275d66f57ce20e0d0ef49 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:19:17 +0200 Subject: [PATCH 041/222] Remove voided test constructors --- packages/framework/tests/Feature/DataCollectionTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/tests/Feature/DataCollectionTest.php b/packages/framework/tests/Feature/DataCollectionTest.php index 524711c0495..df35e788f3f 100644 --- a/packages/framework/tests/Feature/DataCollectionTest.php +++ b/packages/framework/tests/Feature/DataCollectionTest.php @@ -68,7 +68,6 @@ public function testJsonCollectionsAsArrays() public function testFindMarkdownFilesMethodReturnsEmptyArrayIfTheSpecifiedDirectoryDoesNotExist() { - $class = new DataCollections(); $this->assertIsArray(DataCollections::markdown('foo')->keys()->toArray()); $this->assertEmpty(DataCollections::markdown('foo')->keys()->toArray()); } @@ -77,7 +76,6 @@ public function testFindMarkdownFilesMethodReturnsEmptyArrayIfNoFilesAreFoundInS { $this->directory('resources/collections/foo'); - $class = new DataCollections(); $this->assertIsArray(DataCollections::markdown('foo')->keys()->toArray()); $this->assertEmpty(DataCollections::markdown('foo')->keys()->toArray()); } From 292c23b8a533560ae7e4489401c4da8926c441d7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:20:15 +0200 Subject: [PATCH 042/222] Fix formatting --- packages/framework/tests/Feature/FileCollectionTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/FileCollectionTest.php b/packages/framework/tests/Feature/FileCollectionTest.php index d90ce310abc..18f29ac74a1 100644 --- a/packages/framework/tests/Feature/FileCollectionTest.php +++ b/packages/framework/tests/Feature/FileCollectionTest.php @@ -38,8 +38,11 @@ public function testBootMethodCreatesNewPageCollectionAndDiscoversPagesAutomatic public function testGetFileReturnsParsedFileObjectForGivenFilePath() { $this->file('_pages/foo.blade.php'); - $this->assertEquals(new SourceFile('_pages/foo.blade.php', BladePage::class), - Files::getFile('_pages/foo.blade.php')); + + $this->assertEquals( + new SourceFile('_pages/foo.blade.php', BladePage::class), + Files::getFile('_pages/foo.blade.php') + ); } public function testGetFileThrowsExceptionWhenFileIsNotFound() From c721df916e48a33e3376987f708951effb5bcc2c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:20:35 +0200 Subject: [PATCH 043/222] Cleanup test --- packages/framework/tests/Feature/FileCollectionTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/FileCollectionTest.php b/packages/framework/tests/Feature/FileCollectionTest.php index 18f29ac74a1..2bc4f1d66a4 100644 --- a/packages/framework/tests/Feature/FileCollectionTest.php +++ b/packages/framework/tests/Feature/FileCollectionTest.php @@ -66,7 +66,7 @@ public function testGetSourceFilesDoesNotIncludeNonPageSourceFiles() $this->withoutDefaultPages(); $this->file('_pages/foo.txt'); - $this->assertEquals([], Files::getFiles()->all()); + $this->assertSame([], Files::getFiles()->all()); $this->restoreDefaultPages(); } @@ -102,6 +102,7 @@ public function testDocumentationPagesAreDiscovered() { $this->file('_docs/foo.md'); $collection = FileCollection::init(Hyde::getInstance())->boot(); + $this->assertArrayHasKey('_docs/foo.md', $collection->toArray()); $this->assertEquals(new SourceFile('_docs/foo.md', DocumentationPage::class), $collection->get('_docs/foo.md')); } From 86ad04870c9f09e2317f649e89f29e2332c040f3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:25:06 +0200 Subject: [PATCH 044/222] Add code spacing --- packages/framework/tests/Feature/FilesystemFacadeTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/tests/Feature/FilesystemFacadeTest.php b/packages/framework/tests/Feature/FilesystemFacadeTest.php index 55c46f3c6cc..db00aefc30c 100644 --- a/packages/framework/tests/Feature/FilesystemFacadeTest.php +++ b/packages/framework/tests/Feature/FilesystemFacadeTest.php @@ -56,12 +56,14 @@ public function testTouch() Filesystem::touch('foo'); $this->assertFileExists(Hyde::path('foo')); + Filesystem::unlink('foo'); } public function testUnlink() { touch(Hyde::path('foo')); + Filesystem::unlink('foo'); $this->assertFileDoesNotExist(Hyde::path('foo')); @@ -70,6 +72,7 @@ public function testUnlink() public function testUnlinkIfExists() { touch(Hyde::path('foo')); + Filesystem::unlinkIfExists('foo'); $this->assertFileDoesNotExist(Hyde::path('foo')); @@ -438,6 +441,7 @@ public function testMethodWithMixedSequentialAndNamedArguments() public function testMethodWithMixedSequentialAndNamedArgumentsSkippingMiddleOne() { Filesystem::makeDirectory('foo', recursive: true); + $this->assertDirectoryExists(Hyde::path('foo')); rmdir(Hyde::path('foo')); From b1b5f69db9c7a4d809e4e8b51e46674a3561f5cf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:25:16 +0200 Subject: [PATCH 045/222] Cleanup and improve test --- .../framework/tests/Feature/MetadataTest.php | 60 ++++++++++++++----- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/packages/framework/tests/Feature/MetadataTest.php b/packages/framework/tests/Feature/MetadataTest.php index c7b3c7ce690..b1186f87ad9 100644 --- a/packages/framework/tests/Feature/MetadataTest.php +++ b/packages/framework/tests/Feature/MetadataTest.php @@ -57,34 +57,37 @@ public function testMetadataObjectIsGeneratedAutomatically() $this->assertNotNull($page->metadata); $this->assertInstanceOf(MetadataBag::class, $page->metadata); - $this->assertEquals([], $page->metadata->get()); + $this->assertSame([], $page->metadata->get()); } public function testLinkItemModel() { $item = new LinkElement('rel', 'href'); - $this->assertEquals('rel', $item->uniqueKey()); - $this->assertEquals('', (string) $item); + + $this->assertSame('rel', $item->uniqueKey()); + $this->assertSame('', (string) $item); $item = new LinkElement('rel', 'href', ['attr' => 'value']); - $this->assertEquals('', (string) $item); + $this->assertSame('', (string) $item); } public function testMetadataItemModel() { $item = new MetadataElement('name', 'content'); - $this->assertEquals('name', $item->uniqueKey()); - $this->assertEquals('', (string) $item); + + $this->assertSame('name', $item->uniqueKey()); + $this->assertSame('', (string) $item); } public function testOpenGraphItemModel() { $item = new OpenGraphElement('property', 'content'); - $this->assertEquals('property', $item->uniqueKey()); - $this->assertEquals('', (string) $item); + + $this->assertSame('property', $item->uniqueKey()); + $this->assertSame('', (string) $item); $item = new OpenGraphElement('og:property', 'content'); - $this->assertEquals('', (string) $item); + $this->assertSame('', (string) $item); } public function testLinkItemCanBeAdded() @@ -157,12 +160,13 @@ public function testMultipleItemsOfSameKeyAndTypeOnlyKeepsLatest() public function testRenderReturnsHtmlStringOfImplodedMetadataArrays() { $page = new MarkdownPage(); + $page->metadata->add(Meta::link('foo', 'bar')); $page->metadata->add(Meta::name('foo', 'bar')); $page->metadata->add(Meta::property('foo', 'bar')); $page->metadata->add('foo'); - $this->assertEquals(implode("\n", [ + $this->assertSame(implode("\n", [ '', '', '', @@ -176,8 +180,10 @@ public function testCustomMetadataOverridesConfigDefinedMetadata() config(['hyde.meta' => [ Meta::name('foo', 'bar'), ]]); + $page = new MarkdownPage(); $page->metadata->add(Meta::name('foo', 'baz')); + $this->assertEquals([ 'metadata:foo' => Meta::name('foo', 'baz'), ], $page->metadata->get()); @@ -188,6 +194,7 @@ public function testDynamicMetadataOverridesConfigDefinedMetadata() config(['hyde.meta' => [ Meta::name('twitter:title', 'bar'), ]]); + $page = MarkdownPage::make(matter: ['title' => 'baz']); $this->assertEquals([ @@ -199,6 +206,7 @@ public function testDynamicMetadataOverridesConfigDefinedMetadata() public function testDoesNotAddCanonicalLinkWhenBaseUrlIsNotSet() { config(['hyde.url' => null]); + $page = MarkdownPage::make('bar'); $this->assertStringNotContainsString('metadata->render()); @@ -207,6 +215,7 @@ public function testDoesNotAddCanonicalLinkWhenBaseUrlIsNotSet() public function testDoesNotAddCanonicalLinkWhenIdentifierIsNotSet() { config(['hyde.url' => 'foo']); + $page = MarkdownPage::make(); $this->assertStringNotContainsString('metadata->render()); @@ -215,6 +224,7 @@ public function testDoesNotAddCanonicalLinkWhenIdentifierIsNotSet() public function testAddsCanonicalLinkWhenBaseUrlAndIdentifierIsSet() { config(['hyde.url' => 'foo']); + $page = MarkdownPage::make('bar'); $this->assertStringContainsString('', $page->metadata->render()); @@ -224,6 +234,7 @@ public function testCanonicalLinkUsesCleanUrlSetting() { config(['hyde.url' => 'foo']); config(['hyde.pretty_urls' => true]); + $page = MarkdownPage::make('bar'); $this->assertStringContainsString('', $page->metadata->render()); @@ -232,9 +243,11 @@ public function testCanonicalLinkUsesCleanUrlSetting() public function testCanOverrideCanonicalLinkWithFrontMatter() { config(['hyde.url' => 'foo']); + $page = MarkdownPage::make('bar', [ 'canonicalUrl' => 'canonical', ]); + $this->assertStringContainsString('', $page->metadata->render()); } @@ -242,7 +255,7 @@ public function testAddsTwitterAndOpenGraphTitleWhenTitleIsSet() { $page = MarkdownPage::make(matter: ['title' => 'Foo Bar']); - $this->assertEquals( + $this->assertSame( ''."\n". '', $page->metadata->render() @@ -253,80 +266,90 @@ public function testDoesNotAddTwitterAndOpenGraphTitleWhenNoTitleIsSet() { $page = MarkdownPage::make(matter: ['title' => null]); - $this->assertEquals('', - $page->metadata->render() - ); + $this->assertSame('', $page->metadata->render()); } public function testAddsDescriptionWhenDescriptionIsSetInPost() { $page = MarkdownPost::make(matter: ['description' => 'My Description']); + $this->assertPageHasMetadata($page, ''); } public function testDoesNotAddDescriptionWhenDescriptionIsNotSetInPost() { $page = new MarkdownPost(); + $this->assertPageDoesNotHaveMetadata($page, ''); } public function testAddsAuthorWhenAuthorIsSetInPost() { $page = MarkdownPost::make(matter: ['author' => 'My Author']); + $this->assertPageHasMetadata($page, ''); } public function testDoesNotAddAuthorWhenAuthorIsNotSetInPost() { $page = new MarkdownPost(); + $this->assertPageDoesNotHaveMetadata($page, ''); } public function testAddsKeywordsWhenCategoryIsSetInPost() { $page = MarkdownPost::make(matter: ['category' => 'My Category']); + $this->assertPageHasMetadata($page, ''); } public function testDoesNotAddKeywordsWhenCategoryIsNotSetInPost() { $page = new MarkdownPost(); + $this->assertPageDoesNotHaveMetadata($page, ''); } public function testAddsUrlPropertyWhenCanonicalUrlIsSetInPost() { $page = MarkdownPost::make(matter: ['canonicalUrl' => 'example.html']); + $this->assertPageHasMetadata($page, ''); } public function testDoesNotAddUrlPropertyWhenCanonicalUrlIsNotSetInPost() { $page = new MarkdownPost(); + $this->assertPageDoesNotHaveMetadata($page, ''); } public function testDoesNotAddUrlPropertyWhenCanonicalUrlIsNull() { $page = MarkdownPost::make(matter: ['canonicalUrl' => null]); + $this->assertPageDoesNotHaveMetadata($page, ''); } public function testAddsTitlePropertyWhenTitleIsSetInPost() { $page = MarkdownPost::make(matter: ['title' => 'My Title']); + $this->assertPageHasMetadata($page, ''); } public function testDoesNotAddTitlePropertyWhenTitleIsNotSetInPost() { $page = new MarkdownPost(); + $this->assertPageDoesNotHaveMetadata($page, ' '2022-01-01']); + $this->assertPageHasMetadata($page, ''); } @@ -339,6 +362,7 @@ public function testDoesNotAddPublishedTimePropertyWhenDateIsNotSetInPost() public function testAddsImagePropertyWhenImageIsSetInPost() { $page = MarkdownPost::make(matter: ['image' => 'image.jpg']); + $this->assertPageHasMetadata($page, ''); } @@ -351,13 +375,15 @@ public function testDoesNotAddImagePropertyWhenImageIsNotSetInPost() public function testAddsTypePropertyAutomatically() { $page = MarkdownPost::make(); + $this->assertPageHasMetadata($page, ''); } public function testDynamicPostMetaPropertiesReturnsBaseArrayWhenInitializedWithEmptyFrontMatter() { $page = MarkdownPost::make(); - $this->assertEquals('', $page->metadata->render()); + + $this->assertSame('', $page->metadata->render()); } public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedImageSetToString() @@ -390,6 +416,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelati public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelativeForNestedOutputDirectories() { MarkdownPost::setOutputDirectory('_posts/foo'); + $page = MarkdownPost::make(matter: [ 'image' => 'foo.jpg', ]); @@ -400,6 +427,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelati public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelativeForNestedPostsAndNestedOutputDirectories() { MarkdownPost::setOutputDirectory('_posts/foo'); + $page = MarkdownPost::make('bar/baz', matter: [ 'image' => 'foo.jpg', ]); @@ -410,6 +438,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelati public function testDynamicPostMetaPropertiesContainsImageLinkThatUsesTheConfiguredMediaDirectory() { Hyde::setMediaDirectory('assets'); + $page = MarkdownPost::make(matter: [ 'image' => 'foo.jpg', ]); @@ -446,6 +475,7 @@ public function testDynamicPostAuthorReturnsAuthorNameWhenAuthorSetToArrayUsingU 'username' => 'username', ], ]); + $this->assertPageHasMetadata($page, ''); } From 8e1d6fa5eabf9a4bf6c029801de446eaefd18707 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:27:13 +0200 Subject: [PATCH 046/222] Cleanup and improve test --- packages/framework/tests/Feature/NavigationDataTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/NavigationDataTest.php b/packages/framework/tests/Feature/NavigationDataTest.php index 510040dbc96..1eaf47f6259 100644 --- a/packages/framework/tests/Feature/NavigationDataTest.php +++ b/packages/framework/tests/Feature/NavigationDataTest.php @@ -33,10 +33,10 @@ public function testConstruct() { $navigationData = new NavigationData('label', 1, true, 'group'); - $this->assertEquals('label', $navigationData->label); - $this->assertEquals('group', $navigationData->group); - $this->assertEquals(true, $navigationData->hidden); - $this->assertEquals(1, $navigationData->priority); + $this->assertSame('label', $navigationData->label); + $this->assertSame('group', $navigationData->group); + $this->assertSame(true, $navigationData->hidden); + $this->assertSame(1, $navigationData->priority); } public function testMake() @@ -61,6 +61,7 @@ protected function getImplementedSchema(string $class): array $reflection = new ReflectionClass($class); $schema = []; + foreach (get_class_vars($class) as $name => $void) { $schema[$name] = $reflection->getProperty($name)->getType()->getName(); } From 650120c3bbd42a473986a7ad896b455c937e7aee Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:27:55 +0200 Subject: [PATCH 047/222] Cleanup test --- packages/framework/tests/Feature/MarkdownFileParserTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/MarkdownFileParserTest.php b/packages/framework/tests/Feature/MarkdownFileParserTest.php index fa2ef4b51fd..2586eb70dab 100644 --- a/packages/framework/tests/Feature/MarkdownFileParserTest.php +++ b/packages/framework/tests/Feature/MarkdownFileParserTest.php @@ -44,9 +44,10 @@ public function testCanParseMarkdownFile() file_put_contents(Hyde::path('_posts/test-post.md'), 'Foo bar'); $document = MarkdownFileParser::parse('_posts/test-post.md'); - $this->assertInstanceOf(MarkdownDocument::class, $document); + $this->assertInstanceOf(MarkdownDocument::class, $document); $this->assertEquals('Foo bar', $document->markdown); + $this->assertSame('Foo bar', $document->markdown->body()); } public function testCanParseMarkdownFileWithFrontMatter() @@ -54,6 +55,7 @@ public function testCanParseMarkdownFileWithFrontMatter() $this->makeTestPost(); $document = MarkdownFileParser::parse('_posts/test-post.md'); + $this->assertInstanceOf(MarkdownDocument::class, $document); $this->assertEquals(FrontMatter::fromArray([ @@ -77,6 +79,7 @@ public function testParsedMarkdownPostContainsValidFrontMatter() $this->makeTestPost(); $post = MarkdownFileParser::parse('_posts/test-post.md'); + $this->assertSame('My New Post', $post->matter('title')); $this->assertSame('Mr. Hyde', $post->matter('author')); $this->assertSame('blog', $post->matter('category')); From 1be9ed057d71c7b0fd12e220702998e9cb13e394 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:28:51 +0200 Subject: [PATCH 048/222] Use assert same instead of assert equals --- .../tests/Feature/Services/BuildTaskServiceTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php index dde62bd8f1f..b63b735af13 100644 --- a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php +++ b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php @@ -56,7 +56,7 @@ public function testGetPostBuildTasksReturnsArrayMergedWithConfig() $service = $this->makeService(); $tasks = $service->getRegisteredTasks(); - $this->assertEquals(1, count(array_keys($tasks, SecondBuildTask::class))); + $this->assertSame(1, count(array_keys($tasks, SecondBuildTask::class))); } public function testGetPostBuildTasksMergesDuplicateKeys() @@ -67,7 +67,7 @@ public function testGetPostBuildTasksMergesDuplicateKeys() $service = $this->makeService(); $tasks = $service->getRegisteredTasks(); - $this->assertEquals(1, count(array_keys($tasks, TestBuildTask::class))); + $this->assertSame(1, count(array_keys($tasks, TestBuildTask::class))); } public function testRunPostBuildTasksRunsConfiguredTasks() @@ -92,7 +92,7 @@ public function handle(): void } })->run(); - $this->assertEquals(1, $return); + $this->assertSame(1, $return); } public function testFindTasksInAppDirectoryMethodDiscoversTasksInAppDirectory() From 37dcd2d8e22721ba75b130cb79085065ed88d50f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:29:01 +0200 Subject: [PATCH 049/222] Inline local variable --- .../tests/Feature/Services/BuildTaskServiceTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php index b63b735af13..8c8d790dc3d 100644 --- a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php +++ b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php @@ -84,15 +84,13 @@ public function testRunPostBuildTasksRunsConfiguredTasks() public function testExceptionHandlerShowsErrorMessageAndExitsWithCode1WithoutThrowingException() { - $return = (new class extends BuildTask + $this->assertSame(1, (new class extends BuildTask { public function handle(): void { throw new Exception('foo', 1); } - })->run(); - - $this->assertSame(1, $return); + })->run()); } public function testFindTasksInAppDirectoryMethodDiscoversTasksInAppDirectory() From adb592baf800b83c1eed2c414f806371ea8d8969 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:30:22 +0200 Subject: [PATCH 050/222] Fix faulty test name --- packages/framework/tests/Feature/Support/MediaFileTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Support/MediaFileTest.php b/packages/framework/tests/Feature/Support/MediaFileTest.php index a320126f2a5..31b8ac97abb 100644 --- a/packages/framework/tests/Feature/Support/MediaFileTest.php +++ b/packages/framework/tests/Feature/Support/MediaFileTest.php @@ -22,7 +22,7 @@ public function testCanConstruct() $this->assertSame('foo', $file->path); } - public function can_make() + public function testCanMake() { $this->assertEquals(new MediaFile('foo'), MediaFile::make('foo')); } From d5ae4f24fb9c9ad72e862ea25b60aa270b009663 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:33:48 +0200 Subject: [PATCH 051/222] Clean up and improve test --- .../tests/Feature/Support/MediaFileTest.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/Support/MediaFileTest.php b/packages/framework/tests/Feature/Support/MediaFileTest.php index 31b8ac97abb..0782bfaf3bc 100644 --- a/packages/framework/tests/Feature/Support/MediaFileTest.php +++ b/packages/framework/tests/Feature/Support/MediaFileTest.php @@ -18,6 +18,7 @@ class MediaFileTest extends TestCase public function testCanConstruct() { $file = new MediaFile('foo'); + $this->assertInstanceOf(MediaFile::class, $file); $this->assertSame('foo', $file->path); } @@ -29,12 +30,12 @@ public function testCanMake() public function testCanConstructWithNestedPaths() { - $this->assertEquals('path/to/file.txt', MediaFile::make('path/to/file.txt')->path); + $this->assertSame('path/to/file.txt', MediaFile::make('path/to/file.txt')->path); } public function testAbsolutePathIsNormalizedToRelative() { - $this->assertEquals('foo', MediaFile::make(Hyde::path('foo'))->path); + $this->assertSame('foo', MediaFile::make(Hyde::path('foo'))->path); } public function testGetNameReturnsNameOfFile() @@ -85,6 +86,7 @@ public function testToArrayReturnsArrayOfFileProperties() public function testToArrayWithEmptyFileWithNoExtension() { $this->file('foo', 'foo bar'); + $this->assertSame([ 'name' => 'foo', 'path' => 'foo', @@ -97,12 +99,14 @@ public function testToArrayWithFileInSubdirectory() { mkdir(Hyde::path('foo')); touch(Hyde::path('foo/bar.txt')); + $this->assertSame([ 'name' => 'bar.txt', 'path' => 'foo/bar.txt', 'length' => 0, 'mimeType' => 'text/plain', ], MediaFile::make('foo/bar.txt')->toArray()); + Filesystem::unlink('foo/bar.txt'); rmdir(Hyde::path('foo')); } @@ -125,6 +129,7 @@ public function testGetContentLengthWithDirectory() $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('File [foo] not found.'); + MediaFile::make('foo')->getContentLength(); } @@ -132,6 +137,7 @@ public function testGetContentLengthWithNonExistentFile() { $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('File [foo] not found.'); + MediaFile::make('foo')->getContentLength(); } @@ -174,17 +180,18 @@ public function testAllHelperReturnsAllMediaFiles() public function testAllHelperDoesNotIncludeNonMediaFiles() { $this->file('_media/foo.blade.php'); + $this->assertEquals([ 'app.css' => new MediaFile('_media/app.css'), ], MediaFile::all()); } - public function testFilesHelper() + public function testFilesHelperReturnsAllMediaFiles() { $this->assertSame(['app.css'], MediaFile::files()); } - public function testGetIdentifier() + public function testGetIdentifierReturnsIdentifier() { $this->assertSame('foo', MediaFile::make('foo')->getIdentifier()); } From cdca7bd0f03996b08607adbc7c31365530ccecc3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:35:44 +0200 Subject: [PATCH 052/222] Clean up and improve test --- .../tests/Feature/Support/SourceFileTest.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/Support/SourceFileTest.php b/packages/framework/tests/Feature/Support/SourceFileTest.php index 62dde1f56a9..5a92e0075d0 100644 --- a/packages/framework/tests/Feature/Support/SourceFileTest.php +++ b/packages/framework/tests/Feature/Support/SourceFileTest.php @@ -34,25 +34,27 @@ public function testCanConstructWithModelClass() $this->assertSame(MarkdownPage::class, $file->pageClass); } - public function can_make() + public function testCanMake() { $this->assertEquals(new SourceFile('foo'), SourceFile::make('foo')); } public function testCanMakeWithModelClass() { - $this->assertEquals(new SourceFile('foo', MarkdownPage::class), - SourceFile::make('foo', MarkdownPage::class)); + $this->assertEquals( + new SourceFile('foo', MarkdownPage::class), + SourceFile::make('foo', MarkdownPage::class) + ); } public function testCanConstructWithNestedPaths() { - $this->assertEquals('path/to/file.txt', SourceFile::make('path/to/file.txt')->path); + $this->assertSame('path/to/file.txt', SourceFile::make('path/to/file.txt')->path); } public function testAbsolutePathIsNormalizedToRelative() { - $this->assertEquals('foo', SourceFile::make(Hyde::path('foo'))->path); + $this->assertSame('foo', SourceFile::make(Hyde::path('foo'))->path); } public function testGetNameReturnsNameOfFile() @@ -102,6 +104,7 @@ public function testToArrayReturnsArrayOfFileProperties() public function testToArrayWithEmptyFileWithNoExtension() { $this->file('foo'); + $this->assertSame([ 'name' => 'foo', 'path' => 'foo', @@ -113,11 +116,13 @@ public function testToArrayWithFileInSubdirectory() { mkdir(Hyde::path('foo')); touch(Hyde::path('foo/bar.txt')); + $this->assertSame([ 'name' => 'bar.txt', 'path' => 'foo/bar.txt', 'pageClass' => HydePage::class, ], SourceFile::make('foo/bar.txt')->toArray()); + Filesystem::unlink('foo/bar.txt'); rmdir(Hyde::path('foo')); } From 029fb561b35aa115a525602962e57d079a0820bf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:35:50 +0200 Subject: [PATCH 053/222] Add spacing --- packages/framework/tests/Unit/DocumentationPageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Unit/DocumentationPageTest.php b/packages/framework/tests/Unit/DocumentationPageTest.php index ff512fc2088..48a2af77b84 100644 --- a/packages/framework/tests/Unit/DocumentationPageTest.php +++ b/packages/framework/tests/Unit/DocumentationPageTest.php @@ -248,6 +248,7 @@ public function testPageHasFrontMatter() $this->assertNotNull($page->matter()); $this->assertNotEmpty($page->matter()); + $this->assertEquals(new FrontMatter($expected), $page->matter()); $this->assertSame($expected, $page->matter()->get()); } From 9708823b1fb7df878b98acf37dbaab01144687e9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:36:01 +0200 Subject: [PATCH 054/222] Use assert same instead of assert equals --- packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php b/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php index 5cbfb808f7c..758bd291e6c 100644 --- a/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php +++ b/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php @@ -25,8 +25,8 @@ public function testMarkdownPageGetLatestHelperReturnsSortedMarkdownPageCollecti $this->assertInstanceOf(Collection::class, $collection); $this->assertContainsOnlyInstancesOf(MarkdownPost::class, $collection); - $this->assertEquals('new', $collection->first()->identifier); - $this->assertEquals('old', $collection->last()->identifier); + $this->assertSame('new', $collection->first()->identifier); + $this->assertSame('old', $collection->last()->identifier); Filesystem::unlink('_posts/new.md'); Filesystem::unlink('_posts/old.md'); From 55a39d25e4178ef093e58baac5fdca9e3dd36012 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:36:08 +0200 Subject: [PATCH 055/222] Formatting --- packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php b/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php index 758bd291e6c..d82edd83e49 100644 --- a/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php +++ b/packages/framework/tests/Unit/GetLatestMarkdownPostsTest.php @@ -21,6 +21,7 @@ public function testMarkdownPageGetLatestHelperReturnsSortedMarkdownPageCollecti file_put_contents(Hyde::path('_posts/old.md'), "---\ndate: '2021-01-01 12:00'\n---\n"); $collection = MarkdownPost::getLatestPosts(); + $this->assertCount(2, $collection); $this->assertInstanceOf(Collection::class, $collection); $this->assertContainsOnlyInstancesOf(MarkdownPost::class, $collection); From 7085a1bb4b18954d63775aa42005d741220be265 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:36:26 +0200 Subject: [PATCH 056/222] Cleanup test --- packages/framework/tests/Unit/HasTableOfContentsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/HasTableOfContentsTest.php b/packages/framework/tests/Unit/HasTableOfContentsTest.php index 9e0b1316223..7e35d98062e 100644 --- a/packages/framework/tests/Unit/HasTableOfContentsTest.php +++ b/packages/framework/tests/Unit/HasTableOfContentsTest.php @@ -20,8 +20,8 @@ class HasTableOfContentsTest extends TestCase public function testConstructorCreatesTableOfContentsString() { $page = new DocumentationPage(); - $page->markdown = new Markdown('## Title'); - $this->assertEquals('', str_replace("\n", '', $page->getTableOfContents())); + + $this->assertSame('', str_replace("\n", '', $page->getTableOfContents())); } } From fad0b41fc681a3fd79e6f6b299b3ed27a8c8e9ce Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:38:21 +0200 Subject: [PATCH 057/222] Remove redundant class descriptions --- .../tests/Feature/ColoredBlockquoteShortcodesTest.php | 2 -- .../tests/Feature/Services/BladeDownProcessorTest.php | 2 -- .../framework/tests/Feature/Services/ValidationServiceTest.php | 2 -- .../tests/Feature/SourceDirectoriesCanBeChangedTest.php | 3 --- .../tests/Unit/BuildOutputDirectoryCanBeChangedTest.php | 3 --- packages/framework/tests/Unit/HasTableOfContentsTest.php | 2 -- packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php | 2 -- .../framework/tests/Unit/HydeGetBasePathHasFallbackTest.php | 2 -- .../tests/Unit/InteractsWithDirectoriesConcernTest.php | 2 -- packages/framework/tests/Unit/MarkdownFacadeTest.php | 2 -- .../Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php | 3 --- .../TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php | 3 --- 12 files changed, 28 deletions(-) diff --git a/packages/framework/tests/Feature/ColoredBlockquoteShortcodesTest.php b/packages/framework/tests/Feature/ColoredBlockquoteShortcodesTest.php index 063429d9d10..dce752c8313 100644 --- a/packages/framework/tests/Feature/ColoredBlockquoteShortcodesTest.php +++ b/packages/framework/tests/Feature/ColoredBlockquoteShortcodesTest.php @@ -8,8 +8,6 @@ use Hyde\Testing\UnitTestCase; /** - * Class ColoredBlockquoteShortcodesTest. - * * @covers \Hyde\Markdown\Processing\ColoredBlockquotes */ class ColoredBlockquoteShortcodesTest extends UnitTestCase diff --git a/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php b/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php index 797e22d2972..be512bf28b9 100644 --- a/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php +++ b/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php @@ -8,8 +8,6 @@ use Hyde\Testing\TestCase; /** - * Class BladeDownProcessorTest. - * * @covers \Hyde\Markdown\Processing\BladeDownProcessor */ class BladeDownProcessorTest extends TestCase diff --git a/packages/framework/tests/Feature/Services/ValidationServiceTest.php b/packages/framework/tests/Feature/Services/ValidationServiceTest.php index e6fbe88846e..74c487725d7 100644 --- a/packages/framework/tests/Feature/Services/ValidationServiceTest.php +++ b/packages/framework/tests/Feature/Services/ValidationServiceTest.php @@ -11,8 +11,6 @@ use Hyde\Testing\TestCase; /** - * Class ValidationServiceTest. - * * @covers \Hyde\Framework\Services\ValidationService * @covers \Hyde\Support\Models\ValidationResult * diff --git a/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php b/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php index 6254c6fff2e..59deaf470ab 100644 --- a/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php +++ b/packages/framework/tests/Feature/SourceDirectoriesCanBeChangedTest.php @@ -13,9 +13,6 @@ use Hyde\Pages\MarkdownPost; use Hyde\Testing\TestCase; -/** - * Class SourceDirectoriesCanBeChangedTest. - */ class SourceDirectoriesCanBeChangedTest extends TestCase { public static function tearDownAfterClass(): void diff --git a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php index 94ab6e1895c..c9374b17f3e 100644 --- a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php +++ b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php @@ -11,9 +11,6 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; -/** - * Class BuildOutputDirectoryCanBeChangedTest. - */ class BuildOutputDirectoryCanBeChangedTest extends TestCase { public function testSiteOutputDirectoryCanBeChangedForSiteBuilds() diff --git a/packages/framework/tests/Unit/HasTableOfContentsTest.php b/packages/framework/tests/Unit/HasTableOfContentsTest.php index 7e35d98062e..dbca4978c8e 100644 --- a/packages/framework/tests/Unit/HasTableOfContentsTest.php +++ b/packages/framework/tests/Unit/HasTableOfContentsTest.php @@ -9,8 +9,6 @@ use Hyde\Testing\TestCase; /** - * Class HasTableOfContentsTest. - * * @covers \Hyde\Pages\DocumentationPage * * @see \Hyde\Framework\Testing\Feature\Actions\GeneratesSidebarTableOfContentsTest diff --git a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php index 35bb79665a4..2f217e7c96d 100644 --- a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php +++ b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php @@ -8,8 +8,6 @@ use Hyde\Testing\TestCase; /** - * Class HydeBasePathCanBeChangedTest. - * * @covers \Hyde\Foundation\HydeKernel::getBasePath * @covers \Hyde\Foundation\HydeKernel::setBasePath * @covers \Hyde\Foundation\HydeKernel::path diff --git a/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php b/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php index dab5596d1d5..8874519625f 100644 --- a/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php +++ b/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php @@ -8,8 +8,6 @@ use Hyde\Testing\TestCase; /** - * Class HydeGetBasePathHasFallbackTest. - * * @covers \Hyde\Foundation\HydeKernel::getBasePath */ class HydeGetBasePathHasFallbackTest extends TestCase diff --git a/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php b/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php index e8210d71776..0250a60c4d0 100644 --- a/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php +++ b/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php @@ -10,8 +10,6 @@ use Illuminate\Support\Facades\File; /** - * Class InteractsWithDirectoriesConcernTest. - * * @covers \Hyde\Framework\Concerns\InteractsWithDirectories */ class InteractsWithDirectoriesConcernTest extends TestCase diff --git a/packages/framework/tests/Unit/MarkdownFacadeTest.php b/packages/framework/tests/Unit/MarkdownFacadeTest.php index 2f17ee603a5..006f171e4c4 100644 --- a/packages/framework/tests/Unit/MarkdownFacadeTest.php +++ b/packages/framework/tests/Unit/MarkdownFacadeTest.php @@ -8,8 +8,6 @@ use PHPUnit\Framework\TestCase; /** - * Class MarkdownConverterTest. - * * @covers \Hyde\Markdown\Models\Markdown */ class MarkdownFacadeTest extends TestCase diff --git a/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php b/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php index f5208611fe0..6e09bed6efb 100644 --- a/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php +++ b/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php @@ -15,9 +15,6 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\File; -/** - * Class SourceFilesInCustomDirectoriesCanBeCompiledTest. - */ class SourceFilesInCustomDirectoriesCanBeCompiledTest extends TestCase { protected function setUp(): void diff --git a/packages/framework/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php b/packages/framework/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php index b9e3638b7d2..1e4dffa2780 100644 --- a/packages/framework/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php +++ b/packages/framework/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php @@ -8,9 +8,6 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; -/** - * Class TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest. - */ class TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest extends TestCase { public function testPrettyUrlsCanBeEnabledWithFlag() From 9667df8292c54dec2c606e180234003b47c19d2c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:41:21 +0200 Subject: [PATCH 058/222] Extend our unit test case --- packages/framework/tests/Unit/MarkdownFacadeTest.php | 4 ++-- packages/framework/tests/Unit/SerializableContractTest.php | 4 ++-- packages/framework/tests/Unit/UnixsumTest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/framework/tests/Unit/MarkdownFacadeTest.php b/packages/framework/tests/Unit/MarkdownFacadeTest.php index 006f171e4c4..c8c5fe751d0 100644 --- a/packages/framework/tests/Unit/MarkdownFacadeTest.php +++ b/packages/framework/tests/Unit/MarkdownFacadeTest.php @@ -4,13 +4,13 @@ namespace Hyde\Framework\Testing\Unit; +use Hyde\Testing\UnitTestCase; use Hyde\Markdown\Models\Markdown; -use PHPUnit\Framework\TestCase; /** * @covers \Hyde\Markdown\Models\Markdown */ -class MarkdownFacadeTest extends TestCase +class MarkdownFacadeTest extends UnitTestCase { public function testRender(): void { diff --git a/packages/framework/tests/Unit/SerializableContractTest.php b/packages/framework/tests/Unit/SerializableContractTest.php index 97d1b60ad6e..a19c2402082 100644 --- a/packages/framework/tests/Unit/SerializableContractTest.php +++ b/packages/framework/tests/Unit/SerializableContractTest.php @@ -4,16 +4,16 @@ namespace Hyde\Framework\Testing\Unit; +use Hyde\Testing\UnitTestCase; use Hyde\Support\Contracts\SerializableContract; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; use JsonSerializable; -use PHPUnit\Framework\TestCase; /** * @see \Hyde\Support\Contracts\SerializableContract */ -class SerializableContractTest extends TestCase +class SerializableContractTest extends UnitTestCase { public function testInterface() { diff --git a/packages/framework/tests/Unit/UnixsumTest.php b/packages/framework/tests/Unit/UnixsumTest.php index b72b3eefab1..c1cd7782318 100644 --- a/packages/framework/tests/Unit/UnixsumTest.php +++ b/packages/framework/tests/Unit/UnixsumTest.php @@ -4,15 +4,15 @@ namespace Hyde\Framework\Testing\Unit; +use Hyde\Testing\UnitTestCase; use Hyde\Foundation\HydeKernel; use Illuminate\Filesystem\Filesystem; use Mockery; -use PHPUnit\Framework\TestCase; use function Hyde\unixsum; use function Hyde\unixsum_file; -class UnixsumTest extends TestCase +class UnixsumTest extends UnitTestCase { public function testMethodReturnsString() { From 49978c02041ba327b81ce2665e6c4c632bf09200 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:41:27 +0200 Subject: [PATCH 059/222] Inline local variable --- packages/framework/tests/Unit/MarkdownFacadeTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/MarkdownFacadeTest.php b/packages/framework/tests/Unit/MarkdownFacadeTest.php index c8c5fe751d0..aeb0c415a91 100644 --- a/packages/framework/tests/Unit/MarkdownFacadeTest.php +++ b/packages/framework/tests/Unit/MarkdownFacadeTest.php @@ -14,9 +14,7 @@ class MarkdownFacadeTest extends UnitTestCase { public function testRender(): void { - $markdown = '# Hello World!'; - - $html = Markdown::render($markdown); + $html = Markdown::render('# Hello World!'); $this->assertIsString($html); $this->assertEquals("

Hello World!

\n", $html); From 115a0326f8e6554a1ec8f12b6bb902b413f5ed1f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:41:43 +0200 Subject: [PATCH 060/222] Use assert same instead of assert equals --- packages/framework/tests/Unit/MarkdownFacadeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/MarkdownFacadeTest.php b/packages/framework/tests/Unit/MarkdownFacadeTest.php index aeb0c415a91..88531f35744 100644 --- a/packages/framework/tests/Unit/MarkdownFacadeTest.php +++ b/packages/framework/tests/Unit/MarkdownFacadeTest.php @@ -17,6 +17,6 @@ public function testRender(): void $html = Markdown::render('# Hello World!'); $this->assertIsString($html); - $this->assertEquals("

Hello World!

\n", $html); + $this->assertSame("

Hello World!

\n", $html); } } From 72416826fe41babe5b4e25e240efcaa504f8f263 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:42:11 +0200 Subject: [PATCH 061/222] Add newlines to code --- .../tests/Unit/InteractsWithDirectoriesConcernTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php b/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php index 0250a60c4d0..d788f101506 100644 --- a/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php +++ b/packages/framework/tests/Unit/InteractsWithDirectoriesConcernTest.php @@ -55,6 +55,7 @@ public function testNeedsDirectoryHandlesExistingDirectory() { $this->needsDirectory('foo'); $this->needsDirectory('foo'); + $this->assertDirectoryExists(Hyde::path('foo')); } @@ -67,6 +68,7 @@ public function testNeedsDirectoriesCreatesSingleDirectory() public function testNeedsDirectoriesCreatesMultipleDirectories() { $this->needsDirectories(['foo', 'bar']); + $this->assertDirectoryExists(Hyde::path('foo')); $this->assertDirectoryExists(Hyde::path('bar')); From bd1e4088b24da60a17eddeceb4d14ca19dda81e1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:42:43 +0200 Subject: [PATCH 062/222] Add spacing --- .../tests/Unit/BuildOutputDirectoryCanBeChangedTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php index c9374b17f3e..8205f17dae7 100644 --- a/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php +++ b/packages/framework/tests/Unit/BuildOutputDirectoryCanBeChangedTest.php @@ -45,11 +45,14 @@ public function testSiteOutputDirectoryCanBeChangedInStaticPageBuilder() public function testOutputDirectoryIsCreatedIfItDoesNotExistInStaticPageBuilder() { $this->file('_posts/test-post.md'); + File::deleteDirectory(Hyde::path('_site/build/foo')); Hyde::setOutputDirectory('_site/build/foo'); + StaticPageBuilder::handle(Pages::getPage('_posts/test-post.md')); $this->assertFileExists(Hyde::path('_site/build/foo/posts/test-post.html')); + File::deleteDirectory(Hyde::path('_site/build/foo')); } @@ -63,6 +66,7 @@ public function testSiteOutputDirectoryCanBeChangedInConfiguration() $this->assertSame('_site/build', Hyde::kernel()->getOutputDirectory()); $this->file('_posts/test-post.md'); + StaticPageBuilder::handle(Pages::getPage('_posts/test-post.md')); $this->assertFileExists(Hyde::path('_site/build/posts/test-post.html')); @@ -73,6 +77,7 @@ public function testSiteOutputDirectoryCanBeChangedInConfiguration() public function testSiteOutputDirectoryPathIsNormalizedToTrimTrailingSlashes() { Hyde::setOutputDirectory('foo/bar/'); + $this->assertSame('foo/bar', Hyde::kernel()->getOutputDirectory()); } } From 972c3cb64c8ccd6bd415c1bfc4ad26363e75f431 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:43:50 +0200 Subject: [PATCH 063/222] Refactor and improve test --- .../tests/Unit/HydeGetBasePathHasFallbackTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php b/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php index 8874519625f..32de083a97e 100644 --- a/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php +++ b/packages/framework/tests/Unit/HydeGetBasePathHasFallbackTest.php @@ -5,19 +5,22 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Hyde; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; /** * @covers \Hyde\Foundation\HydeKernel::getBasePath */ -class HydeGetBasePathHasFallbackTest extends TestCase +class HydeGetBasePathHasFallbackTest extends UnitTestCase { - public function testHydeGetBasePathFallsBackToGetcwd() + protected static bool $needsKernel = true; + + public function testHydeGetBasePathFallsBackToCurrentWorkingDirectory() { $mock = new class extends Hyde { public static string $basePath; }; - $this->assertEquals(getcwd(), $mock::getBasePath()); + + $this->assertSame(getcwd(), $mock::getBasePath()); } } From 6cd484313c9c5edc1641ab309312a3cd68579646 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:46:26 +0200 Subject: [PATCH 064/222] Refactor and improve test --- .../tests/Unit/MarkdownDocumentTest.php | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index dce948cd7c2..c1caa585963 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -8,66 +8,77 @@ use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Markdown\Models\MarkdownDocument; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; use Illuminate\Support\HtmlString; /** * @covers \Hyde\Markdown\Models\MarkdownDocument * @covers \Hyde\Markdown\Models\Markdown */ -class MarkdownDocumentTest extends TestCase +class MarkdownDocumentTest extends UnitTestCase { + protected static bool $needsKernel = true; + public function testConstructorCreatesNewMarkdownDocument() { $document = new MarkdownDocument([], ''); + $this->assertInstanceOf(MarkdownDocument::class, $document); } public function testConstructorArgumentsAreOptional() { $document = new MarkdownDocument(); + $this->assertInstanceOf(MarkdownDocument::class, $document); } public function testConstructorArgumentsAreAssigned() { $document = new MarkdownDocument(['foo' => 'bar'], 'Hello, world!'); + $this->assertEquals(FrontMatter::fromArray(['foo' => 'bar']), $document->matter); } public function testMagicToStringMethodReturnsBody() { $document = new MarkdownDocument(['foo' => 'bar'], 'Hello, world!'); - $this->assertEquals('Hello, world!', (string) $document); + + $this->assertSame('Hello, world!', (string) $document); } public function testCompileMethodReturnsRenderedHtml() { $document = new MarkdownDocument([], 'Hello, world!'); - $this->assertEquals("

Hello, world!

\n", $document->markdown->compile()); + + $this->assertSame("

Hello, world!

\n", $document->markdown->compile()); } public function testToHtmlMethodReturnsRenderedAsHtmlString() { $document = new MarkdownDocument([], 'Hello, world!'); + $this->assertInstanceOf(HtmlString::class, $document->markdown->toHtml()); - $this->assertEquals("

Hello, world!

\n", (string) $document->markdown->toHtml()); + $this->assertSame("

Hello, world!

\n", (string) $document->markdown->toHtml()); } public function testParseMethodParsesAFileUsingTheMarkdownFileService() { file_put_contents('_pages/foo.md', "---\nfoo: bar\n---\nHello, world!"); + $document = MarkdownDocument::parse('_pages/foo.md'); + $this->assertInstanceOf(MarkdownDocument::class, $document); - $this->assertEquals('Hello, world!', $document->markdown()->body()); + $this->assertSame('Hello, world!', $document->markdown()->body()); $this->assertEquals(FrontMatter::fromArray(['foo' => 'bar']), $document->matter()); + Filesystem::unlink('_pages/foo.md'); } public function testToArrayMethodReturnsArrayMarkdownBodyLines() { $document = new MarkdownDocument(body: "foo\nbar\nbaz"); - $this->assertEquals(['foo', 'bar', 'baz'], $document->markdown->toArray()); + $this->assertSame(['foo', 'bar', 'baz'], $document->markdown->toArray()); } public function testFromFileMethodReturnsNewMarkdownDocument() @@ -75,25 +86,25 @@ public function testFromFileMethodReturnsNewMarkdownDocument() file_put_contents('_pages/foo.md', "---\nfoo: bar\n---\nHello, world!"); $markdown = Markdown::fromFile('_pages/foo.md'); $this->assertInstanceOf(Markdown::class, $markdown); - $this->assertEquals('Hello, world!', $markdown->body()); + $this->assertSame('Hello, world!', $markdown->body()); Filesystem::unlink('_pages/foo.md'); } - public function end_of_markdown_body_is_trimmed() + public function testEndOfMarkdownBodyIsTrimmed() { $markdown = new Markdown("Hello, world!\n\r\t "); - $this->assertEquals('Hello, world!', $markdown->body()); + $this->assertSame('Hello, world!', $markdown->body()); } public function testCarriageReturnsAreNormalized() { $markdown = new Markdown("foo\rbar"); - $this->assertEquals("foo\rbar", $markdown->body()); + $this->assertSame("foo\rbar", $markdown->body()); $markdown = new Markdown("foo\r\nbar"); - $this->assertEquals("foo\nbar", $markdown->body()); + $this->assertSame("foo\nbar", $markdown->body()); $markdown = new Markdown("foo\nbar"); - $this->assertEquals("foo\nbar", $markdown->body()); + $this->assertSame("foo\nbar", $markdown->body()); } } From 6d491fd9964727f1fc540544bcdd930445875939 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:48:10 +0200 Subject: [PATCH 065/222] Refactor and improve test --- packages/framework/tests/Unit/UnixsumTest.php | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/framework/tests/Unit/UnixsumTest.php b/packages/framework/tests/Unit/UnixsumTest.php index c1cd7782318..968c1d0d5f1 100644 --- a/packages/framework/tests/Unit/UnixsumTest.php +++ b/packages/framework/tests/Unit/UnixsumTest.php @@ -5,7 +5,6 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Testing\UnitTestCase; -use Hyde\Foundation\HydeKernel; use Illuminate\Filesystem\Filesystem; use Mockery; @@ -21,7 +20,7 @@ public function testMethodReturnsString() public function testMethodReturnsStringWithLengthOf32() { - $this->assertEquals(32, strlen(unixsum('foo'))); + $this->assertSame(32, strlen(unixsum('foo'))); } public function testMethodReturnsStringMatchingExpectedFormat() @@ -31,7 +30,7 @@ public function testMethodReturnsStringMatchingExpectedFormat() public function testMethodReturnsSameValueForSameStringUsingNormalMethod() { - $this->assertEquals(md5('foo'), unixsum('foo')); + $this->assertSame(md5('foo'), unixsum('foo')); } public function testMethodReturnsDifferentValueForDifferentString() @@ -51,27 +50,27 @@ public function testFunctionIsSpaceSensitive() public function testMethodReturnsSameValueRegardlessOfEndOfLineSequence() { - $this->assertEquals(unixsum('foo'), unixsum('foo')); - $this->assertEquals(unixsum("foo\n"), unixsum("foo\n")); - $this->assertEquals(unixsum("foo\n"), unixsum("foo\r")); - $this->assertEquals(unixsum("foo\n"), unixsum("foo\r\n")); + $this->assertSame(unixsum('foo'), unixsum('foo')); + $this->assertSame(unixsum("foo\n"), unixsum("foo\n")); + $this->assertSame(unixsum("foo\n"), unixsum("foo\r")); + $this->assertSame(unixsum("foo\n"), unixsum("foo\r\n")); } public function testMethodReturnsSameValueForStringWithMixedEndOfLineSequences() { - $this->assertEquals(unixsum("foo\nbar\r\nbaz\r\n"), - unixsum("foo\nbar\nbaz\n")); + $this->assertSame(unixsum("foo\nbar\r\nbaz\r\n"), unixsum("foo\nbar\nbaz\n")); } public function testMethodReturnsSameValueWhenLoadedFromFileUsingShorthand() { + self::needsKernel(); + $string = "foo\nbar\r\nbaz\r\n"; - HydeKernel::setInstance(new HydeKernel()); - $filesystem = Mockery::mock(Filesystem::class); - $filesystem->shouldReceive('get')->andReturn($string); - app()->instance(Filesystem::class, $filesystem); + app()->instance(Filesystem::class, Mockery::mock(Filesystem::class, [ + 'get' => $string, + ])); - $this->assertEquals(unixsum($string), unixsum_file('foo')); + $this->assertSame(unixsum($string), unixsum_file('foo')); } } From f235908cc97dcbbed21ca416924a8197112b95fc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:49:27 +0200 Subject: [PATCH 066/222] Normalize test style --- ...rceFilesInCustomDirectoriesCanBeCompiledTest.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php b/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php index 6e09bed6efb..087d49f29b1 100644 --- a/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php +++ b/packages/framework/tests/Unit/SourceFilesInCustomDirectoriesCanBeCompiledTest.php @@ -21,7 +21,7 @@ protected function setUp(): void { parent::setUp(); - is_dir(Hyde::path('testSourceDir')) || mkdir(Hyde::path('testSourceDir')); + is_dir(Hyde::path('testSourceDir')) || Filesystem::makeDirectory('testSourceDir'); } protected function tearDown(): void @@ -33,7 +33,7 @@ protected function tearDown(): void public function testMarkdownPostsInChangedDirectoryCanBeCompiled() { - mkdir(Hyde::path('testSourceDir/blog')); + Filesystem::makeDirectory('testSourceDir/blog'); Filesystem::touch('testSourceDir/blog/test.md'); MarkdownPost::setSourceDirectory('testSourceDir/blog'); @@ -41,12 +41,13 @@ public function testMarkdownPostsInChangedDirectoryCanBeCompiled() StaticPageBuilder::handle(MarkdownPost::parse('test')); $this->assertFileExists(Hyde::path('_site/posts/test.html')); + Filesystem::unlink('_site/posts/test.html'); } public function testMarkdownPagesInChangedDirectoryCanBeCompiled() { - mkdir(Hyde::path('testSourceDir/pages')); + Filesystem::makeDirectory('testSourceDir/pages'); Filesystem::touch('testSourceDir/pages/test.md'); MarkdownPage::setSourceDirectory('testSourceDir/pages'); @@ -59,7 +60,7 @@ public function testMarkdownPagesInChangedDirectoryCanBeCompiled() public function testDocumentationPagesInChangedDirectoryCanBeCompiled() { - mkdir(Hyde::path('testSourceDir/documentation')); + Filesystem::makeDirectory('testSourceDir/documentation'); Filesystem::touch('testSourceDir/documentation/test.md'); DocumentationPage::setSourceDirectory('testSourceDir/documentation'); @@ -67,12 +68,13 @@ public function testDocumentationPagesInChangedDirectoryCanBeCompiled() StaticPageBuilder::handle(DocumentationPage::parse('test')); $this->assertFileExists(Hyde::path('_site/docs/test.html')); + Filesystem::unlink('_site/docs/test.html'); } public function testBladePagesInChangedDirectoryCanBeCompiled() { - mkdir(Hyde::path('testSourceDir/blade')); + Filesystem::makeDirectory('testSourceDir/blade'); Filesystem::touch('testSourceDir/blade/test.blade.php'); BladePage::setSourceDirectory('testSourceDir/blade'); @@ -81,6 +83,7 @@ public function testBladePagesInChangedDirectoryCanBeCompiled() StaticPageBuilder::handle(BladePage::parse('test')); $this->assertFileExists(Hyde::path('_site/test.html')); + Filesystem::unlink('_site/test.html'); } } From d2c46cfacc8d116a6668c535fd203570e9c4539c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:50:51 +0200 Subject: [PATCH 067/222] Revert "Refactor and improve test" This reverts commit 6d491fd9964727f1fc540544bcdd930445875939. --- packages/framework/tests/Unit/UnixsumTest.php | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/framework/tests/Unit/UnixsumTest.php b/packages/framework/tests/Unit/UnixsumTest.php index 968c1d0d5f1..c1cd7782318 100644 --- a/packages/framework/tests/Unit/UnixsumTest.php +++ b/packages/framework/tests/Unit/UnixsumTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Testing\UnitTestCase; +use Hyde\Foundation\HydeKernel; use Illuminate\Filesystem\Filesystem; use Mockery; @@ -20,7 +21,7 @@ public function testMethodReturnsString() public function testMethodReturnsStringWithLengthOf32() { - $this->assertSame(32, strlen(unixsum('foo'))); + $this->assertEquals(32, strlen(unixsum('foo'))); } public function testMethodReturnsStringMatchingExpectedFormat() @@ -30,7 +31,7 @@ public function testMethodReturnsStringMatchingExpectedFormat() public function testMethodReturnsSameValueForSameStringUsingNormalMethod() { - $this->assertSame(md5('foo'), unixsum('foo')); + $this->assertEquals(md5('foo'), unixsum('foo')); } public function testMethodReturnsDifferentValueForDifferentString() @@ -50,27 +51,27 @@ public function testFunctionIsSpaceSensitive() public function testMethodReturnsSameValueRegardlessOfEndOfLineSequence() { - $this->assertSame(unixsum('foo'), unixsum('foo')); - $this->assertSame(unixsum("foo\n"), unixsum("foo\n")); - $this->assertSame(unixsum("foo\n"), unixsum("foo\r")); - $this->assertSame(unixsum("foo\n"), unixsum("foo\r\n")); + $this->assertEquals(unixsum('foo'), unixsum('foo')); + $this->assertEquals(unixsum("foo\n"), unixsum("foo\n")); + $this->assertEquals(unixsum("foo\n"), unixsum("foo\r")); + $this->assertEquals(unixsum("foo\n"), unixsum("foo\r\n")); } public function testMethodReturnsSameValueForStringWithMixedEndOfLineSequences() { - $this->assertSame(unixsum("foo\nbar\r\nbaz\r\n"), unixsum("foo\nbar\nbaz\n")); + $this->assertEquals(unixsum("foo\nbar\r\nbaz\r\n"), + unixsum("foo\nbar\nbaz\n")); } public function testMethodReturnsSameValueWhenLoadedFromFileUsingShorthand() { - self::needsKernel(); - $string = "foo\nbar\r\nbaz\r\n"; - app()->instance(Filesystem::class, Mockery::mock(Filesystem::class, [ - 'get' => $string, - ])); + HydeKernel::setInstance(new HydeKernel()); + $filesystem = Mockery::mock(Filesystem::class); + $filesystem->shouldReceive('get')->andReturn($string); + app()->instance(Filesystem::class, $filesystem); - $this->assertSame(unixsum($string), unixsum_file('foo')); + $this->assertEquals(unixsum($string), unixsum_file('foo')); } } From 44ce49e6a0865ddbf94468ff2f7266438cbf8464 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:51:04 +0200 Subject: [PATCH 068/222] Refactor and simplify test --- .../Unit/HydeBasePathCanBeChangedTest.php | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php index 2f217e7c96d..bfe7f155b53 100644 --- a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php +++ b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php @@ -5,37 +5,27 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Hyde; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; /** * @covers \Hyde\Foundation\HydeKernel::getBasePath * @covers \Hyde\Foundation\HydeKernel::setBasePath * @covers \Hyde\Foundation\HydeKernel::path */ -class HydeBasePathCanBeChangedTest extends TestCase +class HydeBasePathCanBeChangedTest extends UnitTestCase { - protected string $basePath; - - protected function setUp(): void - { - parent::setUp(); - - if (! isset($this->basePath)) { - $this->basePath = Hyde::getBasePath(); - } - } - - protected function tearDown(): void - { - Hyde::setBasePath($this->basePath); - - parent::tearDown(); - } + protected static bool $needsKernel = true; public function testHydeBasePathCanBeChanged() { + $basePath = Hyde::getBasePath(); + Hyde::setBasePath('/foo/bar'); + $this->assertSame('/foo/bar', Hyde::getBasePath()); $this->assertSame('/foo/bar', Hyde::path()); + + Hyde::setBasePath($basePath); + } } From ebdd9d7bbb2662177f6f916f17c2bf8abdc0855d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:51:39 +0200 Subject: [PATCH 069/222] Reapply "Refactor and improve test" This reverts commit d2c46cfacc8d116a6668c535fd203570e9c4539c. --- packages/framework/tests/Unit/UnixsumTest.php | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/framework/tests/Unit/UnixsumTest.php b/packages/framework/tests/Unit/UnixsumTest.php index c1cd7782318..968c1d0d5f1 100644 --- a/packages/framework/tests/Unit/UnixsumTest.php +++ b/packages/framework/tests/Unit/UnixsumTest.php @@ -5,7 +5,6 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Testing\UnitTestCase; -use Hyde\Foundation\HydeKernel; use Illuminate\Filesystem\Filesystem; use Mockery; @@ -21,7 +20,7 @@ public function testMethodReturnsString() public function testMethodReturnsStringWithLengthOf32() { - $this->assertEquals(32, strlen(unixsum('foo'))); + $this->assertSame(32, strlen(unixsum('foo'))); } public function testMethodReturnsStringMatchingExpectedFormat() @@ -31,7 +30,7 @@ public function testMethodReturnsStringMatchingExpectedFormat() public function testMethodReturnsSameValueForSameStringUsingNormalMethod() { - $this->assertEquals(md5('foo'), unixsum('foo')); + $this->assertSame(md5('foo'), unixsum('foo')); } public function testMethodReturnsDifferentValueForDifferentString() @@ -51,27 +50,27 @@ public function testFunctionIsSpaceSensitive() public function testMethodReturnsSameValueRegardlessOfEndOfLineSequence() { - $this->assertEquals(unixsum('foo'), unixsum('foo')); - $this->assertEquals(unixsum("foo\n"), unixsum("foo\n")); - $this->assertEquals(unixsum("foo\n"), unixsum("foo\r")); - $this->assertEquals(unixsum("foo\n"), unixsum("foo\r\n")); + $this->assertSame(unixsum('foo'), unixsum('foo')); + $this->assertSame(unixsum("foo\n"), unixsum("foo\n")); + $this->assertSame(unixsum("foo\n"), unixsum("foo\r")); + $this->assertSame(unixsum("foo\n"), unixsum("foo\r\n")); } public function testMethodReturnsSameValueForStringWithMixedEndOfLineSequences() { - $this->assertEquals(unixsum("foo\nbar\r\nbaz\r\n"), - unixsum("foo\nbar\nbaz\n")); + $this->assertSame(unixsum("foo\nbar\r\nbaz\r\n"), unixsum("foo\nbar\nbaz\n")); } public function testMethodReturnsSameValueWhenLoadedFromFileUsingShorthand() { + self::needsKernel(); + $string = "foo\nbar\r\nbaz\r\n"; - HydeKernel::setInstance(new HydeKernel()); - $filesystem = Mockery::mock(Filesystem::class); - $filesystem->shouldReceive('get')->andReturn($string); - app()->instance(Filesystem::class, $filesystem); + app()->instance(Filesystem::class, Mockery::mock(Filesystem::class, [ + 'get' => $string, + ])); - $this->assertEquals(unixsum($string), unixsum_file('foo')); + $this->assertSame(unixsum($string), unixsum_file('foo')); } } From 83536738b94b4d90ceffed5f567b73910371e358 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:51:44 +0200 Subject: [PATCH 070/222] Revert "Refactor and improve test" This reverts commit 6cd484313c9c5edc1641ab309312a3cd68579646. --- .../Unit/HydeBasePathCanBeChangedTest.php | 1 - .../tests/Unit/MarkdownDocumentTest.php | 37 +++++++------------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php index bfe7f155b53..c4e266e5cd5 100644 --- a/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php +++ b/packages/framework/tests/Unit/HydeBasePathCanBeChangedTest.php @@ -26,6 +26,5 @@ public function testHydeBasePathCanBeChanged() $this->assertSame('/foo/bar', Hyde::path()); Hyde::setBasePath($basePath); - } } diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index c1caa585963..dce948cd7c2 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -8,77 +8,66 @@ use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Markdown\Models\MarkdownDocument; -use Hyde\Testing\UnitTestCase; +use Hyde\Testing\TestCase; use Illuminate\Support\HtmlString; /** * @covers \Hyde\Markdown\Models\MarkdownDocument * @covers \Hyde\Markdown\Models\Markdown */ -class MarkdownDocumentTest extends UnitTestCase +class MarkdownDocumentTest extends TestCase { - protected static bool $needsKernel = true; - public function testConstructorCreatesNewMarkdownDocument() { $document = new MarkdownDocument([], ''); - $this->assertInstanceOf(MarkdownDocument::class, $document); } public function testConstructorArgumentsAreOptional() { $document = new MarkdownDocument(); - $this->assertInstanceOf(MarkdownDocument::class, $document); } public function testConstructorArgumentsAreAssigned() { $document = new MarkdownDocument(['foo' => 'bar'], 'Hello, world!'); - $this->assertEquals(FrontMatter::fromArray(['foo' => 'bar']), $document->matter); } public function testMagicToStringMethodReturnsBody() { $document = new MarkdownDocument(['foo' => 'bar'], 'Hello, world!'); - - $this->assertSame('Hello, world!', (string) $document); + $this->assertEquals('Hello, world!', (string) $document); } public function testCompileMethodReturnsRenderedHtml() { $document = new MarkdownDocument([], 'Hello, world!'); - - $this->assertSame("

Hello, world!

\n", $document->markdown->compile()); + $this->assertEquals("

Hello, world!

\n", $document->markdown->compile()); } public function testToHtmlMethodReturnsRenderedAsHtmlString() { $document = new MarkdownDocument([], 'Hello, world!'); - $this->assertInstanceOf(HtmlString::class, $document->markdown->toHtml()); - $this->assertSame("

Hello, world!

\n", (string) $document->markdown->toHtml()); + $this->assertEquals("

Hello, world!

\n", (string) $document->markdown->toHtml()); } public function testParseMethodParsesAFileUsingTheMarkdownFileService() { file_put_contents('_pages/foo.md', "---\nfoo: bar\n---\nHello, world!"); - $document = MarkdownDocument::parse('_pages/foo.md'); - $this->assertInstanceOf(MarkdownDocument::class, $document); - $this->assertSame('Hello, world!', $document->markdown()->body()); + $this->assertEquals('Hello, world!', $document->markdown()->body()); $this->assertEquals(FrontMatter::fromArray(['foo' => 'bar']), $document->matter()); - Filesystem::unlink('_pages/foo.md'); } public function testToArrayMethodReturnsArrayMarkdownBodyLines() { $document = new MarkdownDocument(body: "foo\nbar\nbaz"); - $this->assertSame(['foo', 'bar', 'baz'], $document->markdown->toArray()); + $this->assertEquals(['foo', 'bar', 'baz'], $document->markdown->toArray()); } public function testFromFileMethodReturnsNewMarkdownDocument() @@ -86,25 +75,25 @@ public function testFromFileMethodReturnsNewMarkdownDocument() file_put_contents('_pages/foo.md', "---\nfoo: bar\n---\nHello, world!"); $markdown = Markdown::fromFile('_pages/foo.md'); $this->assertInstanceOf(Markdown::class, $markdown); - $this->assertSame('Hello, world!', $markdown->body()); + $this->assertEquals('Hello, world!', $markdown->body()); Filesystem::unlink('_pages/foo.md'); } - public function testEndOfMarkdownBodyIsTrimmed() + public function end_of_markdown_body_is_trimmed() { $markdown = new Markdown("Hello, world!\n\r\t "); - $this->assertSame('Hello, world!', $markdown->body()); + $this->assertEquals('Hello, world!', $markdown->body()); } public function testCarriageReturnsAreNormalized() { $markdown = new Markdown("foo\rbar"); - $this->assertSame("foo\rbar", $markdown->body()); + $this->assertEquals("foo\rbar", $markdown->body()); $markdown = new Markdown("foo\r\nbar"); - $this->assertSame("foo\nbar", $markdown->body()); + $this->assertEquals("foo\nbar", $markdown->body()); $markdown = new Markdown("foo\nbar"); - $this->assertSame("foo\nbar", $markdown->body()); + $this->assertEquals("foo\nbar", $markdown->body()); } } From cb65bce06b1108695de9afe0e2cffbe4dccaf6b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:52:59 +0200 Subject: [PATCH 071/222] Reapply "Refactor and improve test" This reverts commit b884872b6da6882984c51c7b42f2a8a76ec4464e. --- .../tests/Unit/MarkdownDocumentTest.php | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index dce948cd7c2..c1caa585963 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -8,66 +8,77 @@ use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Markdown\Models\MarkdownDocument; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; use Illuminate\Support\HtmlString; /** * @covers \Hyde\Markdown\Models\MarkdownDocument * @covers \Hyde\Markdown\Models\Markdown */ -class MarkdownDocumentTest extends TestCase +class MarkdownDocumentTest extends UnitTestCase { + protected static bool $needsKernel = true; + public function testConstructorCreatesNewMarkdownDocument() { $document = new MarkdownDocument([], ''); + $this->assertInstanceOf(MarkdownDocument::class, $document); } public function testConstructorArgumentsAreOptional() { $document = new MarkdownDocument(); + $this->assertInstanceOf(MarkdownDocument::class, $document); } public function testConstructorArgumentsAreAssigned() { $document = new MarkdownDocument(['foo' => 'bar'], 'Hello, world!'); + $this->assertEquals(FrontMatter::fromArray(['foo' => 'bar']), $document->matter); } public function testMagicToStringMethodReturnsBody() { $document = new MarkdownDocument(['foo' => 'bar'], 'Hello, world!'); - $this->assertEquals('Hello, world!', (string) $document); + + $this->assertSame('Hello, world!', (string) $document); } public function testCompileMethodReturnsRenderedHtml() { $document = new MarkdownDocument([], 'Hello, world!'); - $this->assertEquals("

Hello, world!

\n", $document->markdown->compile()); + + $this->assertSame("

Hello, world!

\n", $document->markdown->compile()); } public function testToHtmlMethodReturnsRenderedAsHtmlString() { $document = new MarkdownDocument([], 'Hello, world!'); + $this->assertInstanceOf(HtmlString::class, $document->markdown->toHtml()); - $this->assertEquals("

Hello, world!

\n", (string) $document->markdown->toHtml()); + $this->assertSame("

Hello, world!

\n", (string) $document->markdown->toHtml()); } public function testParseMethodParsesAFileUsingTheMarkdownFileService() { file_put_contents('_pages/foo.md', "---\nfoo: bar\n---\nHello, world!"); + $document = MarkdownDocument::parse('_pages/foo.md'); + $this->assertInstanceOf(MarkdownDocument::class, $document); - $this->assertEquals('Hello, world!', $document->markdown()->body()); + $this->assertSame('Hello, world!', $document->markdown()->body()); $this->assertEquals(FrontMatter::fromArray(['foo' => 'bar']), $document->matter()); + Filesystem::unlink('_pages/foo.md'); } public function testToArrayMethodReturnsArrayMarkdownBodyLines() { $document = new MarkdownDocument(body: "foo\nbar\nbaz"); - $this->assertEquals(['foo', 'bar', 'baz'], $document->markdown->toArray()); + $this->assertSame(['foo', 'bar', 'baz'], $document->markdown->toArray()); } public function testFromFileMethodReturnsNewMarkdownDocument() @@ -75,25 +86,25 @@ public function testFromFileMethodReturnsNewMarkdownDocument() file_put_contents('_pages/foo.md', "---\nfoo: bar\n---\nHello, world!"); $markdown = Markdown::fromFile('_pages/foo.md'); $this->assertInstanceOf(Markdown::class, $markdown); - $this->assertEquals('Hello, world!', $markdown->body()); + $this->assertSame('Hello, world!', $markdown->body()); Filesystem::unlink('_pages/foo.md'); } - public function end_of_markdown_body_is_trimmed() + public function testEndOfMarkdownBodyIsTrimmed() { $markdown = new Markdown("Hello, world!\n\r\t "); - $this->assertEquals('Hello, world!', $markdown->body()); + $this->assertSame('Hello, world!', $markdown->body()); } public function testCarriageReturnsAreNormalized() { $markdown = new Markdown("foo\rbar"); - $this->assertEquals("foo\rbar", $markdown->body()); + $this->assertSame("foo\rbar", $markdown->body()); $markdown = new Markdown("foo\r\nbar"); - $this->assertEquals("foo\nbar", $markdown->body()); + $this->assertSame("foo\nbar", $markdown->body()); $markdown = new Markdown("foo\nbar"); - $this->assertEquals("foo\nbar", $markdown->body()); + $this->assertSame("foo\nbar", $markdown->body()); } } From 915be48a135b738e1b56ec76d7a36651b9d3cdf5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:53:13 +0200 Subject: [PATCH 072/222] Add code spacing --- packages/framework/tests/Unit/MarkdownDocumentTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index c1caa585963..3a62ec35194 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -84,9 +84,12 @@ public function testToArrayMethodReturnsArrayMarkdownBodyLines() public function testFromFileMethodReturnsNewMarkdownDocument() { file_put_contents('_pages/foo.md', "---\nfoo: bar\n---\nHello, world!"); + $markdown = Markdown::fromFile('_pages/foo.md'); + $this->assertInstanceOf(Markdown::class, $markdown); $this->assertSame('Hello, world!', $markdown->body()); + Filesystem::unlink('_pages/foo.md'); } From cf55a0d1a2d4ed10d40e96fe8f062116b9764685 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:54:05 +0200 Subject: [PATCH 073/222] Setup fresh filesystem instance --- packages/framework/tests/Unit/MarkdownDocumentTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index 3a62ec35194..9233865fb02 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -19,6 +19,13 @@ class MarkdownDocumentTest extends UnitTestCase { protected static bool $needsKernel = true; + public static function setUpBeforeClass(): void + { + parent::setUpBeforeClass(); + + app()->instance('filesystem', new Filesystem()); + } + public function testConstructorCreatesNewMarkdownDocument() { $document = new MarkdownDocument([], ''); From 0ab37dd06cbfbf19b6d7a39430a6b231fd05fb1c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:55:58 +0200 Subject: [PATCH 074/222] Update MarkdownDocumentTest.php --- packages/framework/tests/Unit/MarkdownDocumentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index 9233865fb02..6326ab4b8c4 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -23,7 +23,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - app()->instance('filesystem', new Filesystem()); + app()->instance('files', new Filesystem()); } public function testConstructorCreatesNewMarkdownDocument() From 0a6e5fe0428092b922902e57f25d6e493d879faf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:56:50 +0200 Subject: [PATCH 075/222] Update MarkdownDocumentTest.php --- packages/framework/tests/Unit/MarkdownDocumentTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index 6326ab4b8c4..741b2c5e987 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -23,7 +23,9 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - app()->instance('files', new Filesystem()); + app()->singleton('files', function () { + return new \Illuminate\Filesystem\Filesystem(); + }); } public function testConstructorCreatesNewMarkdownDocument() From af60865840b2912ec42fbcaa2d41a5215d43dbf0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 19:58:21 +0200 Subject: [PATCH 076/222] Update MarkdownDocumentTest.php --- packages/framework/tests/Unit/MarkdownDocumentTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index 741b2c5e987..fa1bc3b27c6 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Facades\Filesystem; +use Hyde\Foundation\HydeKernel; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Markdown\Models\MarkdownDocument; @@ -24,7 +25,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); app()->singleton('files', function () { - return new \Illuminate\Filesystem\Filesystem(); + return new \Hyde\Foundation\Kernel\Filesystem(HydeKernel::getInstance()); }); } From 67017ae33fc568782e296192eeef1060482c8d61 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:00:25 +0200 Subject: [PATCH 077/222] Update MarkdownDocumentTest.php --- packages/framework/tests/Unit/MarkdownDocumentTest.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index fa1bc3b27c6..89cc96763a5 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -5,7 +5,6 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Facades\Filesystem; -use Hyde\Foundation\HydeKernel; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Markdown\Models\MarkdownDocument; @@ -20,13 +19,11 @@ class MarkdownDocumentTest extends UnitTestCase { protected static bool $needsKernel = true; - public static function setUpBeforeClass(): void + public static function tearDownAfterClass(): void { - parent::setUpBeforeClass(); + parent::tearDownAfterClass(); - app()->singleton('files', function () { - return new \Hyde\Foundation\Kernel\Filesystem(HydeKernel::getInstance()); - }); + app()->forgetInstances(); } public function testConstructorCreatesNewMarkdownDocument() From 3b1f92beba5959062650d7028478cc2878c643ba Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:02:03 +0200 Subject: [PATCH 078/222] Update MarkdownDocumentTest.php --- .../framework/tests/Unit/MarkdownDocumentTest.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/framework/tests/Unit/MarkdownDocumentTest.php b/packages/framework/tests/Unit/MarkdownDocumentTest.php index 89cc96763a5..ae88a4a464c 100644 --- a/packages/framework/tests/Unit/MarkdownDocumentTest.php +++ b/packages/framework/tests/Unit/MarkdownDocumentTest.php @@ -8,24 +8,15 @@ use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Markdown\Models\MarkdownDocument; -use Hyde\Testing\UnitTestCase; +use Hyde\Testing\TestCase; use Illuminate\Support\HtmlString; /** * @covers \Hyde\Markdown\Models\MarkdownDocument * @covers \Hyde\Markdown\Models\Markdown */ -class MarkdownDocumentTest extends UnitTestCase +class MarkdownDocumentTest extends TestCase { - protected static bool $needsKernel = true; - - public static function tearDownAfterClass(): void - { - parent::tearDownAfterClass(); - - app()->forgetInstances(); - } - public function testConstructorCreatesNewMarkdownDocument() { $document = new MarkdownDocument([], ''); From 57235ca30de62ef2e70319f1d97743173f4f1399 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:07:05 +0200 Subject: [PATCH 079/222] Add null coalesce to handle missing keys gracefully in test --- packages/framework/tests/Unit/LoadConfigurationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/LoadConfigurationTest.php b/packages/framework/tests/Unit/LoadConfigurationTest.php index 4358e8bfd6e..ff3e966f8fc 100644 --- a/packages/framework/tests/Unit/LoadConfigurationTest.php +++ b/packages/framework/tests/Unit/LoadConfigurationTest.php @@ -66,6 +66,6 @@ public function __construct(array $env) protected function getEnv(string $name): string|false|null { - return $this->env[$name]; + return $this->env[$name] ?? null; } } From 7ef7e9463bd9d1797fabf3827cdc13ac20fff140 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:10:48 +0200 Subject: [PATCH 080/222] Update Pest test names to be more fluent --- .../realtime-compiler/tests/RealtimeCompilerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/realtime-compiler/tests/RealtimeCompilerTest.php b/packages/realtime-compiler/tests/RealtimeCompilerTest.php index 9f48e9467a9..db191d45161 100644 --- a/packages/realtime-compiler/tests/RealtimeCompilerTest.php +++ b/packages/realtime-compiler/tests/RealtimeCompilerTest.php @@ -21,7 +21,7 @@ putenv('SERVER_LIVE_EDIT=false'); }); -test('handle routes index page', function () { +it('handles routes index page', function () { putenv('SERVER_DASHBOARD=false'); mockRoute(''); @@ -40,7 +40,7 @@ Filesystem::unlink('_site/index.html'); }); -test('handle routes custom pages', function () { +it('handles routes custom pages', function () { mockRoute('foo'); Filesystem::put('_pages/foo.md', '# Hello World!'); @@ -58,7 +58,7 @@ Filesystem::unlink('_site/foo.html'); }); -test('handle routes pages with .html extension', function () { +it('handles routes pages with .html extension', function () { mockRoute('foo.html'); Filesystem::put('_pages/foo.md', '# Hello World!'); @@ -76,7 +76,7 @@ Filesystem::unlink('_site/foo.html'); }); -test('handle routes static assets', function () { +it('handles routes static assets', function () { mockRoute('media/app.css'); $kernel = new HttpKernel(); @@ -89,14 +89,14 @@ expect($response->body)->toBe(file_get_contents(\Hyde\Hyde::path('_media/app.css'))); }); -test('handle throws route not found exception for missing route', function () { +it('handles throws route not found exception for missing route', function () { mockRoute('missing'); $kernel = new HttpKernel(); $kernel->handle(new Request()); })->throws(RouteNotFoundException::class, 'Route [missing] not found'); -test('handle sends 404 error response for missing asset', function () { +it('handles sends 404 error response for missing asset', function () { mockRoute('missing.css'); $kernel = new HttpKernel(); From a1ab7e0901eeda7fd475be1662584df4f9fe340c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:14:34 +0200 Subject: [PATCH 081/222] Add newlines --- .../framework/tests/Unit/ServeCommandOptionsUnitTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php index 86cf267463d..f08d9cd0d60 100644 --- a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php +++ b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php @@ -41,12 +41,14 @@ public function testGetHostSelectionWithHostOption() public function testGetHostSelectionWithConfigOption() { self::mockConfig(['hyde.server.host' => 'foo']); + $this->assertSame('foo', $this->getMock()->getHostSelection()); } public function testGetHostSelectionWithHostOptionAndConfigOption() { self::mockConfig(['hyde.server.host' => 'foo']); + $this->assertSame('bar', $this->getMock(['host' => 'bar'])->getHostSelection()); } @@ -63,12 +65,14 @@ public function testGetPortSelectionWithPortOption() public function testGetPortSelectionWithConfigOption() { self::mockConfig(['hyde.server.port' => 8082]); + $this->assertSame(8082, $this->getMock()->getPortSelection()); } public function testGetPortSelectionWithPortOptionAndConfigOption() { self::mockConfig(['hyde.server.port' => 8082]); + $this->assertSame(8081, $this->getMock(['port' => 8081])->getPortSelection()); } @@ -230,6 +234,7 @@ protected function openInBrowser(): void }; $command->safeHandle(); + $this->assertTrue($command->openInBrowserCalled); } From 184fbdfa70d910e430f100687ddebade1072ad95 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:15:02 +0200 Subject: [PATCH 082/222] Make class description more fluent --- .../Features/Documentation/SemanticDocumentationArticle.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php b/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php index 3a093c51786..584655ee893 100644 --- a/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php +++ b/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php @@ -17,8 +17,7 @@ use function trim; /** - * Class to make Hyde documentation pages smarter, - * by dynamically enriching them with semantic HTML. + * Class to make Hyde documentation pages smarter by dynamically enriching them with semantic HTML. */ class SemanticDocumentationArticle { From 065f5d9c6c7b65984771ac24fb1c266315c569fe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:15:33 +0200 Subject: [PATCH 083/222] Normalize comment style --- .../Documentation/SemanticDocumentationArticle.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php b/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php index 584655ee893..81116d00590 100644 --- a/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php +++ b/packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php @@ -98,6 +98,7 @@ protected function getTokenizedDataArray(): array protected function normalizeBody(): void { // Remove possible trailing newlines added by the Markdown compiler to normalize the body. + $this->body = trim($this->body, "\n"); } @@ -139,9 +140,7 @@ protected function renderSourceLink(): string ])->render(); } - /** - * Do we satisfy the requirements to render an edit source button in the supplied position? - */ + /** Do we satisfy the requirements to render an edit source button in the supplied position? */ protected function canRenderSourceLink(string $inPosition): bool { $config = Config::getString('docs.edit_source_link_position', 'both'); @@ -150,9 +149,7 @@ protected function canRenderSourceLink(string $inPosition): bool return ($this->page->getOnlineSourcePath() !== false) && in_array($inPosition, $positions); } - /** - * Does the current document use Torchlight? - */ + /** Does the current document use Torchlight? */ public function hasTorchlight(): bool { return Features::hasTorchlight() && str_contains($this->html, 'Syntax highlighted by torchlight.dev'); From fc8756c41dfe7623724e933fb3f6770ba38bbf30 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:16:31 +0200 Subject: [PATCH 084/222] Comment test behaviour --- packages/framework/tests/Feature/HydeKernelTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index ab305cf9fc2..003dcb6d2b2 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -324,12 +324,14 @@ public function testVersionConstantIsUpToDateWithGit() try { $version = trim(shell_exec('git describe --abbrev=0 --tags')); } catch (Throwable) { + // Gracefully skip the test if the version cannot be fetched $this->markTestSkipped('Could not get version from Git'); } if ('v'.HydeKernel::VERSION === $version) { $this->assertSame('v'.HydeKernel::VERSION, $version); } else { + // Gracefully skip the test if the version is not up-to-date $this->markTestSkipped('Version constant does not match Git version!'); } } From 87f64a85e117e4f7ef01eb4b862db65e0fe5ef52 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:18:51 +0200 Subject: [PATCH 085/222] Fix comment link --- packages/framework/tests/Feature/HydeKernelTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index 003dcb6d2b2..2021d1b14d9 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -301,7 +301,7 @@ public function testToJsonMethod() public function testVersionConstantIsAValidSemverString() { - // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-stringd + // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string $this->assertMatchesRegularExpression( '/^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/', HydeKernel::VERSION From 870a96d43bc6dee4a0a6428b799c23fccb1c0eb3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:19:08 +0200 Subject: [PATCH 086/222] Move down comment --- packages/framework/tests/Feature/HydeKernelTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index 2021d1b14d9..2d5d0da6cd0 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -301,8 +301,8 @@ public function testToJsonMethod() public function testVersionConstantIsAValidSemverString() { - // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string $this->assertMatchesRegularExpression( + // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string '/^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/', HydeKernel::VERSION ); From cf5f2cf98c00bc2a0912299663f14264974cf235 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:20:18 +0200 Subject: [PATCH 087/222] Clean up and improve test --- .../framework/tests/Feature/HydeKernelTest.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index 2d5d0da6cd0..d59dc86f679 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -91,6 +91,7 @@ public function testCurrentRouteHelperReturnsCurrentRouteObject() { $expected = new Route(new MarkdownPage()); Render::share('route', $expected); + $this->assertInstanceOf(Route::class, Hyde::currentRoute()); $this->assertSame($expected, Hyde::currentRoute()); } @@ -99,6 +100,7 @@ public function testCurrentPageHelperReturnsCurrentPageObject() { $expected = new MarkdownPage(); Render::share('page', $expected); + $this->assertInstanceOf(HydePage::class, Hyde::currentPage()); $this->assertSame($expected, Hyde::currentPage()); } @@ -260,10 +262,6 @@ public function testFluentModelSourcePathHelpers() $this->assertSame(Hyde::path('_docs'), DocumentationPage::path()); $this->assertSame(Hyde::path('_media'), Hyde::mediaPath()); - $this->assertSame(Hyde::path('_pages'), BladePage::path()); - $this->assertSame(Hyde::path('_pages'), MarkdownPage::path()); - $this->assertSame(Hyde::path('_posts'), MarkdownPost::path()); - $this->assertSame(Hyde::path('_docs'), DocumentationPage::path()); $this->assertSame(Hyde::path('_site'), Hyde::sitePath()); $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); } @@ -372,6 +370,7 @@ public function testCanGetOutputDirectory() public function testCanSetOutputDirectory() { Hyde::setOutputDirectory('foo'); + $this->assertSame('foo', Hyde::getOutputDirectory()); $this->assertSame(Hyde::path('foo'), Hyde::sitePath()); } @@ -379,6 +378,7 @@ public function testCanSetOutputDirectory() public function testCanSetOutputDirectoryToAbsoluteProjectPath() { Hyde::setOutputDirectory(Hyde::path('foo')); + $this->assertSame('foo', Hyde::getOutputDirectory()); $this->assertSame(Hyde::path('foo'), Hyde::sitePath()); } @@ -432,6 +432,7 @@ public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory { Hyde::setOutputDirectory(Hyde::path('foo')); Hyde::setMediaDirectory('bar'); + $this->assertSame(Hyde::path('foo/bar'), Hyde::siteMediaPath()); } @@ -449,6 +450,10 @@ public function testCanAccessKernelFluentlyUsingTheFacade() { $this->assertInstanceOf(HydeKernel::class, Hyde::kernel()); $this->assertSame(HydeKernel::getInstance(), Hyde::kernel()); + } + + public function testCanAccessKernelSymbolsFluentlyUsingTheFacade() + { $this->assertSame(HydeKernel::VERSION, Hyde::kernel()->version()); } @@ -519,6 +524,7 @@ public function testCanUseBootingCallbacksToInjectCustomPages() $kernel = HydeKernel::getInstance(); $page = new InMemoryPage('foo'); + $kernel->booting(function (HydeKernel $kernel) use ($page): void { $kernel->pages()->addPage($page); }); @@ -537,6 +543,7 @@ public function testIsBootedReturnsTrueWhenBooted() { $kernel = new HydeKernel(); $kernel->boot(); + $this->assertTrue($kernel->isBooted()); } From 2894fad224c377664d383804372d544636e6b511 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:21:40 +0200 Subject: [PATCH 088/222] Merge data assembly --- packages/framework/tests/Unit/HasTableOfContentsTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/HasTableOfContentsTest.php b/packages/framework/tests/Unit/HasTableOfContentsTest.php index dbca4978c8e..dc13c637bb9 100644 --- a/packages/framework/tests/Unit/HasTableOfContentsTest.php +++ b/packages/framework/tests/Unit/HasTableOfContentsTest.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Testing\Unit; -use Hyde\Markdown\Models\Markdown; use Hyde\Pages\DocumentationPage; use Hyde\Testing\TestCase; @@ -17,8 +16,7 @@ class HasTableOfContentsTest extends TestCase { public function testConstructorCreatesTableOfContentsString() { - $page = new DocumentationPage(); - $page->markdown = new Markdown('## Title'); + $page = new DocumentationPage(markdown: '## Title'); $this->assertSame('', str_replace("\n", '', $page->getTableOfContents())); } From 1c7eabf3d6a78e5fca835d29211bc99b18f28abd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:22:58 +0200 Subject: [PATCH 089/222] Refactor to use unit test case --- packages/framework/tests/Unit/HasTableOfContentsTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/HasTableOfContentsTest.php b/packages/framework/tests/Unit/HasTableOfContentsTest.php index dc13c637bb9..309fa4e1cd8 100644 --- a/packages/framework/tests/Unit/HasTableOfContentsTest.php +++ b/packages/framework/tests/Unit/HasTableOfContentsTest.php @@ -5,15 +5,18 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Pages\DocumentationPage; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; /** * @covers \Hyde\Pages\DocumentationPage * * @see \Hyde\Framework\Testing\Feature\Actions\GeneratesSidebarTableOfContentsTest */ -class HasTableOfContentsTest extends TestCase +class HasTableOfContentsTest extends UnitTestCase { + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; + public function testConstructorCreatesTableOfContentsString() { $page = new DocumentationPage(markdown: '## Title'); From a6dd1e22c1c7e4152d85c9ce3ce3d2d3ef0c80f7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:23:22 +0200 Subject: [PATCH 090/222] Inline local variable --- packages/framework/tests/Unit/HasTableOfContentsTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/HasTableOfContentsTest.php b/packages/framework/tests/Unit/HasTableOfContentsTest.php index 309fa4e1cd8..c7c0b295033 100644 --- a/packages/framework/tests/Unit/HasTableOfContentsTest.php +++ b/packages/framework/tests/Unit/HasTableOfContentsTest.php @@ -19,8 +19,6 @@ class HasTableOfContentsTest extends UnitTestCase public function testConstructorCreatesTableOfContentsString() { - $page = new DocumentationPage(markdown: '## Title'); - - $this->assertSame('', str_replace("\n", '', $page->getTableOfContents())); + $this->assertSame('', str_replace("\n", '', (new DocumentationPage(markdown: '## Title'))->getTableOfContents())); } } From 7d7d86471e0e1de959372ee6acfc4e6c5b9eea26 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:23:40 +0200 Subject: [PATCH 091/222] Split comma-separated values into multiple lines --- packages/framework/tests/Unit/HasTableOfContentsTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/HasTableOfContentsTest.php b/packages/framework/tests/Unit/HasTableOfContentsTest.php index c7c0b295033..93a3375fc56 100644 --- a/packages/framework/tests/Unit/HasTableOfContentsTest.php +++ b/packages/framework/tests/Unit/HasTableOfContentsTest.php @@ -19,6 +19,8 @@ class HasTableOfContentsTest extends UnitTestCase public function testConstructorCreatesTableOfContentsString() { - $this->assertSame('', str_replace("\n", '', (new DocumentationPage(markdown: '## Title'))->getTableOfContents())); + $this->assertSame('', + str_replace("\n", '', (new DocumentationPage(markdown: '## Title'))->getTableOfContents()) + ); } } From 0ee9fd0e2b1e7dc55babd703305222b547333a14 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 20:23:49 +0200 Subject: [PATCH 092/222] Fix formatting --- packages/framework/tests/Unit/HasTableOfContentsTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/HasTableOfContentsTest.php b/packages/framework/tests/Unit/HasTableOfContentsTest.php index 93a3375fc56..2995b0b509e 100644 --- a/packages/framework/tests/Unit/HasTableOfContentsTest.php +++ b/packages/framework/tests/Unit/HasTableOfContentsTest.php @@ -19,7 +19,8 @@ class HasTableOfContentsTest extends UnitTestCase public function testConstructorCreatesTableOfContentsString() { - $this->assertSame('', + $this->assertSame( + '', str_replace("\n", '', (new DocumentationPage(markdown: '## Title'))->getTableOfContents()) ); } From b6a93a6a0981e704e89ed1420abc71f22f69f77d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:09:33 +0200 Subject: [PATCH 093/222] Refactor and improve code quality of test --- .../framework/tests/Feature/HydePageTest.php | 319 +++++++++--------- 1 file changed, 164 insertions(+), 155 deletions(-) diff --git a/packages/framework/tests/Feature/HydePageTest.php b/packages/framework/tests/Feature/HydePageTest.php index dde95fffb96..c8487693cd1 100644 --- a/packages/framework/tests/Feature/HydePageTest.php +++ b/packages/framework/tests/Feature/HydePageTest.php @@ -39,66 +39,42 @@ class HydePageTest extends TestCase public function testBaseSourceDirectory() { - $this->assertSame( - '', - HydePage::sourceDirectory() - ); + $this->assertSame('', HydePage::sourceDirectory()); } public function testBaseOutputDirectory() { - $this->assertSame( - '', - HydePage::outputDirectory() - ); + $this->assertSame('', HydePage::outputDirectory()); } public function testBaseFileExtension() { - $this->assertSame( - '', - HydePage::fileExtension() - ); + $this->assertSame('', HydePage::fileExtension()); } public function testBaseSourcePath() { - $this->assertSame( - 'hello-world', - HydePage::sourcePath('hello-world') - ); + $this->assertSame('hello-world', HydePage::sourcePath('hello-world')); } public function testBaseOutputPath() { - $this->assertSame( - 'hello-world.html', - HydePage::outputPath('hello-world') - ); + $this->assertSame('hello-world.html', HydePage::outputPath('hello-world')); } public function testBasePath() { - $this->assertSame( - Hyde::path('hello-world'), - HydePage::path('hello-world') - ); + $this->assertSame(Hyde::path('hello-world'), HydePage::path('hello-world')); } public function testBasePathToIdentifier() { - $this->assertSame( - 'hello-world', - HydePage::pathToIdentifier('hello-world') - ); + $this->assertSame('hello-world', HydePage::pathToIdentifier('hello-world')); } public function testBaseBaseRouteKey() { - $this->assertSame( - HydePage::outputDirectory(), - HydePage::baseRouteKey() - ); + $this->assertSame(HydePage::outputDirectory(), HydePage::baseRouteKey()); } public function testBaseIsDiscoverable() @@ -110,58 +86,37 @@ public function testBaseIsDiscoverable() public function testSourceDirectory() { - $this->assertSame( - 'source', - TestPage::sourceDirectory() - ); + $this->assertSame('source', TestPage::sourceDirectory()); } public function testOutputDirectory() { - $this->assertSame( - 'output', - TestPage::outputDirectory() - ); + $this->assertSame('output', TestPage::outputDirectory()); } public function testFileExtension() { - $this->assertSame( - '.md', - TestPage::fileExtension() - ); + $this->assertSame('.md', TestPage::fileExtension()); } public function testSourcePath() { - $this->assertSame( - 'source/hello-world.md', - TestPage::sourcePath('hello-world') - ); + $this->assertSame('source/hello-world.md', TestPage::sourcePath('hello-world')); } public function testOutputPath() { - $this->assertSame( - 'output/hello-world.html', - TestPage::outputPath('hello-world') - ); + $this->assertSame('output/hello-world.html', TestPage::outputPath('hello-world')); } public function testPath() { - $this->assertSame( - Hyde::path('source/hello-world'), - TestPage::path('hello-world') - ); + $this->assertSame(Hyde::path('source/hello-world'), TestPage::path('hello-world')); } public function testBaseRouteKey() { - $this->assertSame( - TestPage::outputDirectory(), - TestPage::baseRouteKey() - ); + $this->assertSame(TestPage::outputDirectory(), TestPage::baseRouteKey()); } public function testIsDiscoverable() @@ -263,74 +218,81 @@ public function testToArray() public function testGetSourceDirectoryReturnsStaticProperty() { MarkdownPage::setSourceDirectory('foo'); - $this->assertEquals('foo', MarkdownPage::sourceDirectory()); + + $this->assertSame('foo', MarkdownPage::sourceDirectory()); $this->resetDirectoryConfiguration(); } public function testSetSourceDirectoryTrimsTrailingSlashes() { MarkdownPage::setSourceDirectory('/foo/\\'); - $this->assertEquals('foo', MarkdownPage::sourceDirectory()); + + $this->assertSame('foo', MarkdownPage::sourceDirectory()); $this->resetDirectoryConfiguration(); } public function testGetOutputDirectoryReturnsStaticProperty() { MarkdownPage::setOutputDirectory('foo'); - $this->assertEquals('foo', MarkdownPage::outputDirectory()); + + $this->assertSame('foo', MarkdownPage::outputDirectory()); $this->resetDirectoryConfiguration(); } public function testSetOutputDirectoryTrimsTrailingSlashes() { MarkdownPage::setOutputDirectory('/foo/\\'); - $this->assertEquals('foo', MarkdownPage::outputDirectory()); + + $this->assertSame('foo', MarkdownPage::outputDirectory()); $this->resetDirectoryConfiguration(); } public function testGetFileExtensionReturnsStaticProperty() { MarkdownPage::setFileExtension('.foo'); - $this->assertEquals('.foo', MarkdownPage::fileExtension()); + + $this->assertSame('.foo', MarkdownPage::fileExtension()); $this->resetDirectoryConfiguration(); } public function testSetFileExtensionForcesLeadingPeriod() { MarkdownPage::setFileExtension('foo'); - $this->assertEquals('.foo', MarkdownPage::fileExtension()); + + $this->assertSame('.foo', MarkdownPage::fileExtension()); $this->resetDirectoryConfiguration(); } public function testSetFileExtensionRemovesTrailingPeriod() { MarkdownPage::setFileExtension('foo.'); - $this->assertEquals('.foo', MarkdownPage::fileExtension()); + + $this->assertSame('.foo', MarkdownPage::fileExtension()); $this->resetDirectoryConfiguration(); } public function testGetIdentifierReturnsIdentifierProperty() { $page = new MarkdownPage('foo'); - $this->assertEquals('foo', $page->getIdentifier()); + $this->assertSame('foo', $page->getIdentifier()); } public function testSetSourceDirectory() { ConfigurableSourcesTestPage::setSourceDirectory('foo'); - $this->assertEquals('foo', ConfigurableSourcesTestPage::sourceDirectory()); + $this->assertSame('foo', ConfigurableSourcesTestPage::sourceDirectory()); } public function testSetOutputDirectory() { ConfigurableSourcesTestPage::setOutputDirectory('foo'); - $this->assertEquals('foo', ConfigurableSourcesTestPage::outputDirectory()); + $this->assertSame('foo', ConfigurableSourcesTestPage::outputDirectory()); } public function testSetFileExtension() { ConfigurableSourcesTestPage::setFileExtension('.foo'); - $this->assertEquals('.foo', ConfigurableSourcesTestPage::fileExtension()); + $this->assertSame('.foo', ConfigurableSourcesTestPage::fileExtension()); } public function testStaticGetMethodReturnsDiscoveredPage() @@ -349,7 +311,7 @@ public function testParseParsesSuppliedSlugIntoAPageModel() Filesystem::touch('_pages/foo.md'); $this->assertInstanceOf(MarkdownPage::class, $page = MarkdownPage::parse('foo')); - $this->assertEquals('foo', $page->identifier); + $this->assertSame('foo', $page->identifier); Filesystem::unlink('_pages/foo.md'); } @@ -357,118 +319,127 @@ public function testParseParsesSuppliedSlugIntoAPageModel() public function testFilesReturnsArrayOfSourceFiles() { Filesystem::touch('_pages/foo.md'); - $this->assertEquals(['foo'], MarkdownPage::files()); + + $this->assertSame(['foo'], MarkdownPage::files()); + Filesystem::unlink('_pages/foo.md'); } public function testAllReturnsCollectionOfAllParsedSourceFilesFromPageIndex() { Filesystem::touch('_pages/foo.md'); + $this->assertEquals( Pages::getPages(MarkdownPage::class), MarkdownPage::all() ); + $this->assertEquals( ['_pages/foo.md' => (new MarkdownPage('foo'))], MarkdownPage::all()->all() ); + Filesystem::unlink('_pages/foo.md'); } public function testQualifyBasenameProperlyExpandsBasenameForTheModel() { - $this->assertEquals('_pages/foo.md', MarkdownPage::sourcePath('foo')); + $this->assertSame('_pages/foo.md', MarkdownPage::sourcePath('foo')); } public function testQualifyBasenameTrimsSlashesFromInput() { - $this->assertEquals('_pages/foo.md', MarkdownPage::sourcePath('/foo/\\')); + $this->assertSame('_pages/foo.md', MarkdownPage::sourcePath('/foo/\\')); } public function testQualifyBasenameUsesTheStaticProperties() { MarkdownPage::setSourceDirectory('foo'); MarkdownPage::setFileExtension('txt'); - $this->assertEquals('foo/bar.txt', MarkdownPage::sourcePath('bar')); + + $this->assertSame('foo/bar.txt', MarkdownPage::sourcePath('bar')); + $this->resetDirectoryConfiguration(); } public function testPathReturnsAbsolutePathToSourceDirectoryWhenNoParameterIsSupplied() { - $this->assertSame( - Hyde::path('source'), TestPage::path() - ); + $this->assertSame(Hyde::path('source'), TestPage::path()); } public function testPathReturnsAbsolutePathToFileInSourceDirectoryWhenParameterIsSupplied() { - $this->assertSame( - Hyde::path('source/foo.md'), TestPage::path('foo.md') - ); + $this->assertSame(Hyde::path('source/foo.md'), TestPage::path('foo.md')); } public function testPathMethodRemovesTrailingSlashes() { - $this->assertSame( - Hyde::path('source/foo.md'), TestPage::path('/foo.md/') - ); + $this->assertSame(Hyde::path('source/foo.md'), TestPage::path('/foo.md/')); } public function testGetOutputLocationReturnsTheFileOutputPathForTheSuppliedBasename() { - $this->assertEquals('foo.html', MarkdownPage::outputPath('foo')); + $this->assertSame('foo.html', MarkdownPage::outputPath('foo')); } public function testGetOutputLocationReturnsTheConfiguredLocation() { MarkdownPage::setOutputDirectory('foo'); - $this->assertEquals('foo/bar.html', MarkdownPage::outputPath('bar')); + + $this->assertSame('foo/bar.html', MarkdownPage::outputPath('bar')); + $this->resetDirectoryConfiguration(); } public function testGetOutputLocationTrimsTrailingSlashesFromDirectorySetting() { MarkdownPage::setOutputDirectory('/foo/\\'); - $this->assertEquals('foo/bar.html', MarkdownPage::outputPath('bar')); + + $this->assertSame('foo/bar.html', MarkdownPage::outputPath('bar')); + $this->resetDirectoryConfiguration(); } public function testGetOutputLocationTrimsTrailingSlashesFromBasename() { - $this->assertEquals('foo.html', MarkdownPage::outputPath('/foo/\\')); + $this->assertSame('foo.html', MarkdownPage::outputPath('/foo/\\')); } - public function testGetCurrentPagePathReturnsOutputDirectoryAndBasename() + public function testGetRouteKeyReturnsOutputDirectoryAndBasename() { $page = new MarkdownPage('foo'); - $this->assertEquals('foo', $page->getRouteKey()); + $this->assertSame('foo', $page->getRouteKey()); } - public function testGetCurrentPagePathReturnsOutputDirectoryAndBasenameForConfiguredDirectory() + public function testGetRouteKeyReturnsOutputDirectoryAndBasenameForConfiguredDirectory() { MarkdownPage::setOutputDirectory('foo'); + $page = new MarkdownPage('bar'); - $this->assertEquals('foo/bar', $page->getRouteKey()); + $this->assertSame('foo/bar', $page->getRouteKey()); + $this->resetDirectoryConfiguration(); } - public function testGetCurrentPagePathTrimsTrailingSlashesFromDirectorySetting() + public function testGetRouteKeyTrimsTrailingSlashesFromDirectorySetting() { MarkdownPage::setOutputDirectory('/foo/\\'); + $page = new MarkdownPage('bar'); - $this->assertEquals('foo/bar', $page->getRouteKey()); + $this->assertSame('foo/bar', $page->getRouteKey()); + $this->resetDirectoryConfiguration(); } public function testGetOutputPathReturnsCurrentPagePathWithHtmlExtensionAppended() { $page = new MarkdownPage('foo'); - $this->assertEquals('foo.html', $page->getOutputPath()); + $this->assertSame('foo.html', $page->getOutputPath()); } public function testGetSourcePathReturnsQualifiedBasename() { - $this->assertEquals( + $this->assertSame( MarkdownPage::sourcePath('foo'), (new MarkdownPage('foo'))->getSourcePath() ); @@ -507,7 +478,8 @@ public function testAllPageModelsHaveConfiguredSourceDirectory() ]; foreach ($pages as $page => $expected) { - $this->assertEquals($expected, $page::sourceDirectory()); + assert(is_a($page, HydePage::class, true)); + $this->assertSame($expected, $page::sourceDirectory()); } } @@ -521,7 +493,8 @@ public function testAllPageModelsHaveConfiguredOutputDirectory() ]; foreach ($pages as $page => $expected) { - $this->assertEquals($expected, $page::outputDirectory()); + assert(is_a($page, HydePage::class, true)); + $this->assertSame($expected, $page::outputDirectory()); } } @@ -535,7 +508,8 @@ public function testAllPageModelsHaveConfiguredFileExtension() ]; foreach ($pages as $page => $expected) { - $this->assertEquals($expected, $page::fileExtension()); + assert(is_a($page, HydePage::class, true)); + $this->assertSame($expected, $page::fileExtension()); } } @@ -561,12 +535,13 @@ public function testAbstractMarkdownPageHasFileExtensionProperty() public function testAbstractMarkdownPageFileExtensionPropertyIsSetToMd() { - $this->assertEquals('.md', BaseMarkdownPage::fileExtension()); + $this->assertSame('.md', BaseMarkdownPage::fileExtension()); } public function testAbstractMarkdownPageConstructorArgumentsAreOptional() { $page = $this->mock(BaseMarkdownPage::class); + $this->assertInstanceOf(BaseMarkdownPage::class, $page); } @@ -574,6 +549,7 @@ public function testAbstractMarkdownPageConstructorAssignsMarkdownDocumentProper { $markdown = new Markdown(); $page = new MarkdownPage(markdown: $markdown); + $this->assertSame($markdown, $page->markdown); } @@ -593,13 +569,14 @@ public function testAbstractMarkdownPageMarkdownHelperReturnsTheConfiguredMarkdo { $markdown = new Markdown(); $page = new MarkdownPage(markdown: $markdown); + $this->assertSame($markdown, $page->markdown()); } public function testAbstractMarkdownPageMakeHelperConstructsDynamicTitleAutomatically() { $page = MarkdownPage::make('', ['title' => 'Foo']); - $this->assertEquals('Foo', $page->title); + $this->assertSame('Foo', $page->title); } public function testMarkdownBasedPagesExtendAbstractMarkdownPage() @@ -629,6 +606,7 @@ public function testGetRouteReturnsPageRoute() public function testGetRouteReturnsTheRouteObjectFromTheRouterIndex() { $this->file('_pages/foo.md'); + $page = MarkdownPage::parse('foo'); $this->assertSame(Routes::get('foo'), $page->getRoute()); } @@ -636,20 +614,21 @@ public function testGetRouteReturnsTheRouteObjectFromTheRouterIndex() public function testHtmlTitleReturnsSiteNamePlusPageTitle() { $make = MarkdownPage::make('', ['title' => 'Foo']); - $this->assertEquals('HydePHP - Foo', $make->title()); + $this->assertSame('HydePHP - Foo', $make->title()); } public function testHtmlTitleUsesConfiguredSiteName() { config(['hyde.name' => 'Foo Bar']); + $markdownPage = new MarkdownPage('Foo'); - $this->assertEquals('Foo Bar - Foo', $markdownPage->title()); + $this->assertSame('Foo Bar - Foo', $markdownPage->title()); } public function testBodyHelperReturnsMarkdownDocumentBodyInMarkdownPages() { $page = new MarkdownPage(markdown: new Markdown(body: '# Foo')); - $this->assertEquals('# Foo', $page->markdown->body()); + $this->assertSame('# Foo', $page->markdown->body()); } public function testShowInNavigationReturnsFalseForMarkdownPost() @@ -707,6 +686,7 @@ public function testShowInNavigationReturnsFalseIfSlugIsPresentInConfigHydeNavig $this->assertTrue($page->showInNavigation()); config(['hyde.navigation.exclude' => ['foo']]); + $page = MarkdownPage::make('foo'); $this->assertFalse($page->showInNavigation()); } @@ -726,111 +706,116 @@ public function testShowInNavigationDefaultsToTrueIfAllChecksPass() public function testNavigationMenuPriorityReturnsFrontMatterValueOfNavigationPriorityIfAbstractMarkdownPageAndNotNull() { $page = MarkdownPage::make('foo', ['navigation.priority' => 1]); - $this->assertEquals(1, $page->navigationMenuPriority()); + $this->assertSame(1, $page->navigationMenuPriority()); } public function testNavigationMenuPriorityCanBeSetUsingOrderProperty() { $page = MarkdownPage::make('foo', ['navigation.order' => 1]); - $this->assertEquals(1, $page->navigationMenuPriority()); + $this->assertSame(1, $page->navigationMenuPriority()); } public function testNavigationMenuPriorityReturnsSpecifiedConfigValueIfSlugExistsInConfigHydeNavigationOrder() { $page = MarkdownPage::make('foo'); - $this->assertEquals(999, $page->navigationMenuPriority()); + $this->assertSame(999, $page->navigationMenuPriority()); config(['hyde.navigation.order' => ['foo' => 1]]); + $page = MarkdownPage::make('foo'); - $this->assertEquals(1, $page->navigationMenuPriority()); + $this->assertSame(1, $page->navigationMenuPriority()); } public function testNavigationMenuPriorityGivesPrecedenceToFrontMatterOverConfigHydeNavigationOrder() { $page = MarkdownPage::make('foo', ['navigation.priority' => 1]); - $this->assertEquals(1, $page->navigationMenuPriority()); + $this->assertSame(1, $page->navigationMenuPriority()); config(['hyde.navigation.order' => ['foo' => 2]]); - $this->assertEquals(1, $page->navigationMenuPriority()); + + $page = MarkdownPage::make('foo', ['navigation.priority' => 1]); + $this->assertSame(1, $page->navigationMenuPriority()); } public function testNavigationMenuPriorityReturns999ForDocumentationPage() { $page = DocumentationPage::make('index'); - $this->assertEquals(999, $page->navigationMenuPriority()); + $this->assertSame(999, $page->navigationMenuPriority()); } public function testNavigationMenuPriorityReturns0IfSlugIsIndex() { $page = MarkdownPage::make('index'); - $this->assertEquals(0, $page->navigationMenuPriority()); + $this->assertSame(0, $page->navigationMenuPriority()); } public function testNavigationMenuPriorityReturns10IfSlugIsPosts() { $page = MarkdownPage::make('posts'); - $this->assertEquals(10, $page->navigationMenuPriority()); + $this->assertSame(10, $page->navigationMenuPriority()); } public function testNavigationMenuPriorityDefaultsTo999IfNoOtherConditionsAreMet() { $page = MarkdownPage::make('foo'); - $this->assertEquals(999, $page->navigationMenuPriority()); + $this->assertSame(999, $page->navigationMenuPriority()); } public function testNavigationMenuTitleReturnsNavigationTitleMatterIfSet() { $page = MarkdownPage::make('foo', ['navigation.label' => 'foo']); - $this->assertEquals('foo', $page->navigationMenuLabel()); + $this->assertSame('foo', $page->navigationMenuLabel()); } public function testNavigationMenuTitleReturnsTitleMatterIfSet() { $page = MarkdownPage::make('foo', ['title' => 'foo']); - $this->assertEquals('foo', $page->navigationMenuLabel()); + $this->assertSame('foo', $page->navigationMenuLabel()); } public function testNavigationMenuTitleNavigationTitleHasPrecedenceOverTitle() { $page = MarkdownPage::make('foo', ['title' => 'foo', 'navigation.label' => 'bar']); - $this->assertEquals('bar', $page->navigationMenuLabel()); + $this->assertSame('bar', $page->navigationMenuLabel()); } public function testNavigationMenuTitleReturnsDocsIfSlugIsIndexAndModelIsDocumentationPage() { $page = DocumentationPage::make('index'); - $this->assertEquals('Docs', $page->navigationMenuLabel()); + $this->assertSame('Docs', $page->navigationMenuLabel()); } public function testNavigationMenuTitleReturnsHomeIfSlugIsIndexAndModelIsNotDocumentationPage() { $page = MarkdownPage::make('index'); - $this->assertEquals('Home', $page->navigationMenuLabel()); + $this->assertSame('Home', $page->navigationMenuLabel()); } public function testNavigationMenuTitleReturnsTitleIfTitleIsSetAndNotEmpty() { $page = MarkdownPage::make('bar', ['title' => 'foo']); - $this->assertEquals('foo', $page->navigationMenuLabel()); + $this->assertSame('foo', $page->navigationMenuLabel()); } public function testNavigationMenuTitleFallsBackToHydeMakeTitleFromSlug() { $page = MarkdownPage::make('foo'); - $this->assertEquals('Foo', $page->navigationMenuLabel()); + $this->assertSame('Foo', $page->navigationMenuLabel()); } public function testNavigationMenuTitleCanBeSetInConfiguration() { config(['hyde.navigation.labels' => ['foo' => 'bar']]); + $page = MarkdownPage::make('foo'); - $this->assertEquals('bar', $page->navigationMenuLabel()); + $this->assertSame('bar', $page->navigationMenuLabel()); } public function testDocumentationPageCanBeHiddenFromNavigationUsingConfig() { config(['hyde.navigation.exclude' => ['docs/index']]); + $page = DocumentationPage::make('index'); $this->assertFalse($page->showInNavigation()); } @@ -838,67 +823,69 @@ public function testDocumentationPageCanBeHiddenFromNavigationUsingConfig() public function testGetCanonicalUrlReturnsUrlForTopLevelPage() { config(['hyde.url' => 'https://example.com']); - $page = new MarkdownPage('foo'); - $this->assertEquals('https://example.com/foo.html', $page->getCanonicalUrl()); + $page = new MarkdownPage('foo'); + $this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl()); } public function testGetCanonicalUrlReturnsPrettyUrlForTopLevelPage() { config(['hyde.url' => 'https://example.com']); config(['hyde.pretty_urls' => true]); + $page = new MarkdownPage('foo'); - $this->assertEquals('https://example.com/foo', $page->getCanonicalUrl()); + $this->assertSame('https://example.com/foo', $page->getCanonicalUrl()); } public function testGetCanonicalUrlReturnsUrlForNestedPage() { config(['hyde.url' => 'https://example.com']); + $page = new MarkdownPage('foo/bar'); - $this->assertEquals('https://example.com/foo/bar.html', $page->getCanonicalUrl()); + $this->assertSame('https://example.com/foo/bar.html', $page->getCanonicalUrl()); } public function testGetCanonicalUrlReturnsUrlForDeeplyNestedPage() { config(['hyde.url' => 'https://example.com']); + $page = new MarkdownPage('foo/bar/baz'); - $this->assertEquals('https://example.com/foo/bar/baz.html', $page->getCanonicalUrl()); + $this->assertSame('https://example.com/foo/bar/baz.html', $page->getCanonicalUrl()); } public function testCanonicalUrlIsNotSetWhenIdentifierIsNull() { config(['hyde.url' => 'https://example.com']); + $page = new MarkdownPage(); + $this->assertNull($page->getCanonicalUrl()); - $this->assertStringNotContainsString( - 'metadata()->render() - ); + $this->assertStringNotContainsString('canonical', $page->metadata()->render()); + $this->assertStringNotContainsString('metadata()->render()); } public function testCanonicalUrlIsNotSetWhenSiteUrlIsNull() { config(['hyde.url' => null]); + $page = new MarkdownPage('foo'); + $this->assertNull($page->getCanonicalUrl()); - $this->assertStringNotContainsString( - 'metadata()->render() - ); + $this->assertStringNotContainsString('canonical', $page->metadata()->render()); + $this->assertStringNotContainsString('metadata()->render()); } public function testCustomCanonicalLinkCanBeSetInFrontMatter() { config(['hyde.url' => 'https://example.com']); + $page = MarkdownPage::make(matter: ['canonicalUrl' => 'foo/bar']); - $this->assertEquals('foo/bar', $page->getCanonicalUrl()); - $this->assertStringContainsString( - '', - $page->metadata()->render() - ); + + $this->assertSame('foo/bar', $page->getCanonicalUrl()); + $this->assertStringContainsString('', $page->metadata()->render()); } public function testCanCreateCanonicalUrlUsingBaseUrlFromConfig() @@ -923,6 +910,7 @@ public function testCanCreateCanonicalUrlUsingBaseUrlFromConfigUsingPrettyUrls() public function testCanonicalUrlIsNullWhenNoBaseUrlIsSet() { config(['hyde' => []]); + $this->assertNull((new MarkdownPage('foo'))->getCanonicalUrl()); } @@ -990,34 +978,42 @@ public function testMarkdownPagesCanBeSavedToDisk() { $page = new MarkdownPage('foo'); $page->save(); + $this->assertFileExists(Hyde::path('_pages/foo.md')); + Filesystem::unlink('_pages/foo.md'); } public function testSaveMethodConvertsFrontMatterArrayToYamlBlock() { MarkdownPage::make('foo', matter: ['foo' => 'bar'])->save(); - $this->assertEquals("---\nfoo: bar\n---\n", + + $this->assertSame("---\nfoo: bar\n---\n", file_get_contents(Hyde::path('_pages/foo.md')) ); + Filesystem::unlink('_pages/foo.md'); } public function testSaveMethodWritesPageBodyToFile() { MarkdownPage::make('foo', markdown: 'foo')->save(); - $this->assertEquals("foo\n", + + $this->assertSame("foo\n", file_get_contents(Hyde::path('_pages/foo.md')) ); + Filesystem::unlink('_pages/foo.md'); } public function testSaveMethodWritesPageBodyToFileWithFrontMatter() { MarkdownPage::make('foo', matter: ['foo' => 'bar'], markdown: 'foo bar')->save(); - $this->assertEquals("---\nfoo: bar\n---\n\nfoo bar\n", + + $this->assertSame("---\nfoo: bar\n---\n\nfoo bar\n", file_get_contents(Hyde::path('_pages/foo.md')) ); + Filesystem::unlink('_pages/foo.md'); } @@ -1039,8 +1035,8 @@ public function testExistingParsedMarkdownPagesCanBeSaved() $this->assertSame("bar\n", file_get_contents(Hyde::path('_pages/foo.md'))); - /** @var BaseMarkdownPage $parsed */ $parsed = Pages::getPage('_pages/foo.md'); + $this->assertInstanceOf(MarkdownPage::class, $parsed); $this->assertSame('bar', $parsed->markdown->body()); $parsed->markdown = new Markdown('baz'); @@ -1082,7 +1078,9 @@ public function testMarkdownPostsCanBeSaved() { $post = new MarkdownPost('foo'); $post->save(); + $this->assertFileExists(Hyde::path('_posts/foo.md')); + Filesystem::unlink('_posts/foo.md'); } @@ -1090,34 +1088,35 @@ public function testDocumentationPagesCanBeSaved() { $page = new DocumentationPage('foo'); $page->save(); + $this->assertFileExists(Hyde::path('_docs/foo.md')); + Filesystem::unlink('_docs/foo.md'); } public function testGetMethodCanAccessDataFromPage() { $page = MarkdownPage::make('foo', ['foo' => 'bar']); - $this->assertEquals('bar', $page->data('foo')); + $this->assertSame('bar', $page->data('foo')); } public function testGetMethodCanAccessNestedDataFromPage() { $page = MarkdownPage::make('foo', ['foo' => ['bar' => 'baz']]); - $this->assertEquals('baz', $page->data('foo')['bar']); + $this->assertSame('baz', $page->data('foo')['bar']); } public function testGetMethodCanAccessNestedDataFromPageWithDotNotation() { $page = MarkdownPage::make('foo', ['foo' => ['bar' => 'baz']]); - $this->assertEquals('baz', $page->data('foo.bar')); + $this->assertSame('baz', $page->data('foo.bar')); } public function testGetLinkWithPrettyUrls() { config(['hyde.pretty_urls' => true]); - $this->assertEquals('output/hello-world', - (new TestPage('hello-world'))->getLink() - ); + + $this->assertSame('output/hello-world', (new TestPage('hello-world'))->getLink()); } public function testGetLinkUsesHyperlinksHelper() @@ -1146,8 +1145,11 @@ public function testAllPagesAreRoutable() HtmlPage::class, ]; - /** @var HydePage $page */ foreach ($pages as $page) { + assert(is_a($page, HydePage::class, true)); + + Hyde::boot(); + $page = new $page('foo'); $this->assertInstanceOf(Route::class, $page->getRoute()); @@ -1161,13 +1163,13 @@ public function testAllPagesAreRoutable() $this->assertArrayHasKey($page->getRouteKey(), Hyde::routes()); unlink($page::sourcePath('foo')); - Hyde::boot(); } } public function testNavigationDataFactoryHidesPageFromNavigationWhenInASubdirectory() { $page = MarkdownPage::make('foo/bar'); + $this->assertFalse($page->showInNavigation()); $this->assertNull($page->navigationMenuGroup()); } @@ -1175,7 +1177,9 @@ public function testNavigationDataFactoryHidesPageFromNavigationWhenInASubdirect public function testNavigationDataFactoryHidesPageFromNavigationWhenInAAndConfigIsSetToHidden() { config(['hyde.navigation.subdirectories' => 'hidden']); + $page = MarkdownPage::make('foo/bar'); + $this->assertFalse($page->showInNavigation()); $this->assertNull($page->navigationMenuGroup()); } @@ -1183,7 +1187,9 @@ public function testNavigationDataFactoryHidesPageFromNavigationWhenInAAndConfig public function testNavigationDataFactoryDoesNotHidePageFromNavigationWhenInASubdirectoryAndAllowedInConfiguration() { config(['hyde.navigation.subdirectories' => 'flat']); + $page = MarkdownPage::make('foo/bar'); + $this->assertTrue($page->showInNavigation()); $this->assertNull($page->navigationMenuGroup()); } @@ -1191,9 +1197,11 @@ public function testNavigationDataFactoryDoesNotHidePageFromNavigationWhenInASub public function testNavigationDataFactoryAllowsShowInNavigationAndSetsGroupWhenDropdownIsSelectedInConfig() { config(['hyde.navigation.subdirectories' => 'dropdown']); + $page = MarkdownPage::make('foo/bar'); + $this->assertTrue($page->showInNavigation()); - $this->assertEquals('foo', $page->navigationMenuGroup()); + $this->assertSame('foo', $page->navigationMenuGroup()); } public function testIsDiscoverableMethodReturnsTrueForDiscoverablePages() @@ -1218,8 +1226,8 @@ public function testIsDiscoverableMethodRequiresSourceDirectoryToBeFilled() public function testAllCoreExtensionPagesAreDiscoverable() { - /** @var class-string $page */ foreach (HydeCoreExtension::getPageClasses() as $page) { + assert(is_a($page, HydePage::class, true)); $this->assertTrue($page::isDiscoverable()); } } @@ -1227,6 +1235,7 @@ public function testAllCoreExtensionPagesAreDiscoverable() public function testNestedIndexPagesShowUpInNavigation() { $page = MarkdownPage::make('foo/index'); + $this->assertTrue($page->showInNavigation()); $this->assertSame('Foo', $page->navigationMenuLabel()); } From 13c5e30c94f4272ac82b0af8a38e9f498e0555eb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:11:39 +0200 Subject: [PATCH 094/222] Use assert same instead of assert equals --- .../Services/BladeDownProcessorTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php b/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php index be512bf28b9..003425477f9 100644 --- a/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php +++ b/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php @@ -14,12 +14,12 @@ class BladeDownProcessorTest extends TestCase { public function testItRendersBladeEchoSyntax() { - $this->assertEquals('Hello World!', BladeDownProcessor::render('[Blade]: {{ "Hello World!" }}')); + $this->assertSame('Hello World!', BladeDownProcessor::render('[Blade]: {{ "Hello World!" }}')); } public function testItRendersBladeWithinMultilineMarkdown() { - $this->assertEquals( + $this->assertSame( "Foo\nHello World!\nBar", BladeDownProcessor::render("Foo\n[Blade]: {{ 'Hello World!' }}\nBar") @@ -36,25 +36,25 @@ public function testItRendersBladeViews() 'views/hello.blade.php' ), 'Hello World!'); - $this->assertEquals('Hello World!', BladeDownProcessor::render('[Blade]: @include("hello")')); + $this->assertSame('Hello World!', BladeDownProcessor::render('[Blade]: @include("hello")')); unlink(resource_path('views/hello.blade.php')); } public function testDirectiveIsCaseInsensitive() { - $this->assertEquals('Hello World!', BladeDownProcessor::render('[blade]: {{ "Hello World!" }}')); + $this->assertSame('Hello World!', BladeDownProcessor::render('[blade]: {{ "Hello World!" }}')); } public function testDirectiveIsIgnoredIfItIsNotAtTheStartOfALine() { - $this->assertEquals('Example: [Blade]: {{ "Hello World!" }}', + $this->assertSame('Example: [Blade]: {{ "Hello World!" }}', BladeDownProcessor::render('Example: [Blade]: {{ "Hello World!" }}')); } public function testItRendersBladeEchoSyntaxWithVariables() { - $this->assertEquals('Hello World!', BladeDownProcessor::render('[Blade]: {{ $foo }}', ['foo' => 'Hello World!'])); + $this->assertSame('Hello World!', BladeDownProcessor::render('[Blade]: {{ $foo }}', ['foo' => 'Hello World!'])); } public function testItRendersBladeViewsWithVariables() @@ -63,18 +63,18 @@ public function testItRendersBladeViewsWithVariables() 'views/hello.blade.php' ), 'Hello {{ $name }}!'); - $this->assertEquals('Hello John!', BladeDownProcessor::render('[Blade]: @include("hello", ["name" => "John"])')); + $this->assertSame('Hello John!', BladeDownProcessor::render('[Blade]: @include("hello", ["name" => "John"])')); unlink(resource_path('views/hello.blade.php')); } public function testPreprocessMethodExpandsShortcode() { - $this->assertEquals('', BladeDownProcessor::preprocess('[Blade]: {{ $foo }}')); + $this->assertSame('', BladeDownProcessor::preprocess('[Blade]: {{ $foo }}')); } public function testProcessMethodRendersShortcode() { - $this->assertEquals('Hello World!', BladeDownProcessor::postprocess('', ['foo' => 'Hello World!'])); + $this->assertSame('Hello World!', BladeDownProcessor::postprocess('', ['foo' => 'Hello World!'])); } } From 0c4597525cd2fb86111dea4d94f59ca6bc548e1c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:11:54 +0200 Subject: [PATCH 095/222] Remove extra newline --- .../framework/tests/Feature/Services/BladeDownProcessorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php b/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php index 003425477f9..d6e55a0bc56 100644 --- a/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php +++ b/packages/framework/tests/Feature/Services/BladeDownProcessorTest.php @@ -21,7 +21,6 @@ public function testItRendersBladeWithinMultilineMarkdown() { $this->assertSame( "Foo\nHello World!\nBar", - BladeDownProcessor::render("Foo\n[Blade]: {{ 'Hello World!' }}\nBar") ); } From f77f2e7e34c85c5cf2c5721b7d29b2dffe9bbfa9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:15:19 +0200 Subject: [PATCH 096/222] Use assert same instead of assert equals --- .../Feature/Services/DocumentationSidebarTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php index 54290a8e34d..103da971328 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()->items->first()->priority); + $this->assertSame(25, DocumentationSidebar::create()->items->first()->priority); } public function testSidebarItemPrioritySetInConfigOverridesFrontMatter() @@ -123,7 +123,7 @@ public function testSidebarItemPrioritySetInConfigOverridesFrontMatter() Config::set('docs.sidebar_order', ['foo']); - $this->assertEquals(25, DocumentationSidebar::create()->items->first()->priority); + $this->assertSame(25, DocumentationSidebar::create()->items->first()->priority); } public function testSidebarPrioritiesCanBeSetInBothFrontMatterAndConfig() @@ -153,7 +153,7 @@ public function testGroupCanBeSetInFrontMatter() { $this->makePage('foo', ['navigation.group' => 'bar']); - $this->assertEquals('bar', DocumentationSidebar::create()->items->first()->getGroup()); + $this->assertSame('bar', DocumentationSidebar::create()->items->first()->getGroup()); } public function testHasGroupsReturnsFalseWhenThereAreNoGroups() @@ -187,14 +187,14 @@ public function testHasGroupsReturnsTrueWhenThereAreMultipleGroupsMixedWithDefau public function testGetGroupsReturnsEmptyArrayWhenThereAreNoGroups() { - $this->assertEquals([], DocumentationSidebar::create()->getGroups()); + $this->assertSame([], DocumentationSidebar::create()->getGroups()); } public function testGetGroupsReturnsArrayOfGroupsWhenThereAreGroups() { $this->makePage('foo', ['navigation.group' => 'bar']); - $this->assertEquals(['bar'], DocumentationSidebar::create()->getGroups()); + $this->assertSame(['bar'], DocumentationSidebar::create()->getGroups()); } public function testGetGroupsReturnsArrayWithNoDuplicates() @@ -203,7 +203,7 @@ public function testGetGroupsReturnsArrayWithNoDuplicates() $this->makePage('bar', ['navigation.group' => 'bar']); $this->makePage('baz', ['navigation.group' => 'baz']); - $this->assertEquals(['bar', 'baz'], DocumentationSidebar::create()->getGroups()); + $this->assertSame(['bar', 'baz'], DocumentationSidebar::create()->getGroups()); } public function testGroupsAreSortedByLowestFoundPriorityInEachGroup() @@ -212,7 +212,7 @@ public function testGroupsAreSortedByLowestFoundPriorityInEachGroup() $this->makePage('bar', ['navigation.group' => 'bar', 'navigation.priority' => 200]); $this->makePage('baz', ['navigation.group' => 'baz', 'navigation.priority' => 10]); - $this->assertEquals(['baz', 'bar'], DocumentationSidebar::create()->getGroups()); + $this->assertSame(['baz', 'bar'], DocumentationSidebar::create()->getGroups()); } public function testGetItemsInGroupReturnsEmptyCollectionWhenThereAreNoItems() From 896d1ebc305976713b00783b11c50b7d9092597b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:16:21 +0200 Subject: [PATCH 097/222] Add code spacing --- .../tests/Feature/Services/DocumentationSidebarTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php index 103da971328..c9d6d86b8b1 100644 --- a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php +++ b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php @@ -306,6 +306,7 @@ public function testIsGroupActiveReturnsTrueFirstGroupOfIndexPage() $this->makePage('baz', ['navigation.group' => 'baz']); Render::setPage(DocumentationPage::get('index')); + $this->assertTrue(DocumentationSidebar::create()->isGroupActive('bar')); $this->assertFalse(DocumentationSidebar::create()->isGroupActive('foo')); $this->assertFalse(DocumentationSidebar::create()->isGroupActive('baz')); @@ -319,6 +320,7 @@ public function testIsGroupActiveReturnsTrueFirstSortedGroupOfIndexPage() $this->makePage('baz', ['navigation.group' => 'baz', 'navigation.priority' => 3]); Render::setPage(DocumentationPage::get('index')); + $this->assertTrue(DocumentationSidebar::create()->isGroupActive('foo')); $this->assertFalse(DocumentationSidebar::create()->isGroupActive('bar')); $this->assertFalse(DocumentationSidebar::create()->isGroupActive('baz')); @@ -332,6 +334,7 @@ public function testAutomaticIndexPageGroupExpansionRespectsCustomNavigationMenu $this->makePage('baz', ['navigation.group' => 'baz', 'navigation.priority' => 3]); Render::setPage(DocumentationPage::get('index')); + $this->assertFalse(DocumentationSidebar::create()->isGroupActive('foo')); $this->assertFalse(DocumentationSidebar::create()->isGroupActive('bar')); $this->assertTrue(DocumentationSidebar::create()->isGroupActive('baz')); @@ -409,6 +412,7 @@ public function testIndexPageAddedToSidebarWhenItIsTheOnlyPage() public function testIndexPageNotAddedToSidebarWhenOtherPagesExist() { $this->createTestFiles(1); + Filesystem::touch('_docs/index.md'); $sidebar = DocumentationSidebar::create(); From 76d453dff3733e941f3ff43b92fe5383f4963e99 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:16:50 +0200 Subject: [PATCH 098/222] Convert concatenation to string interpolation --- .../tests/Feature/Services/DocumentationSidebarTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php index c9d6d86b8b1..110597f682e 100644 --- a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php +++ b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php @@ -426,14 +426,14 @@ public function testIndexPageNotAddedToSidebarWhenOtherPagesExist() protected function createTestFiles(int $count = 5): void { for ($i = 0; $i < $count; $i++) { - Filesystem::touch('_docs/test-'.$i.'.md'); + Filesystem::touch("_docs/test-{$i}.md"); } } protected function makePage(string $name, ?array $matter = null): void { file_put_contents( - Hyde::path('_docs/'.$name.'.md'), + Hyde::path("_docs/{$name}.md"), (new ConvertsArrayToFrontMatter)->execute($matter ?? []) ); } From 002c3daf25bf5b3517cf29cb418c888f3f688dcf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:18:50 +0200 Subject: [PATCH 099/222] Simplify helper method parameter --- .../tests/Feature/Services/DocumentationSidebarTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php index 110597f682e..53f1c2f9925 100644 --- a/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php +++ b/packages/framework/tests/Feature/Services/DocumentationSidebarTest.php @@ -430,11 +430,11 @@ protected function createTestFiles(int $count = 5): void } } - protected function makePage(string $name, ?array $matter = null): void + protected function makePage(string $name, array $matter = []): void { file_put_contents( Hyde::path("_docs/{$name}.md"), - (new ConvertsArrayToFrontMatter)->execute($matter ?? []) + (new ConvertsArrayToFrontMatter)->execute($matter) ); } } From 9f89742762096e0ae6bf2868ea70c724d90cf24c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:27:02 +0200 Subject: [PATCH 100/222] Clean up and improve test --- .../Feature/Services/HydeSmartDocsTest.php | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/framework/tests/Feature/Services/HydeSmartDocsTest.php b/packages/framework/tests/Feature/Services/HydeSmartDocsTest.php index 0ee6fdec3bd..cdf2540614a 100644 --- a/packages/framework/tests/Feature/Services/HydeSmartDocsTest.php +++ b/packages/framework/tests/Feature/Services/HydeSmartDocsTest.php @@ -46,24 +46,27 @@ public function testClassCanHandleEmptyDocument() $this->assertEquals('', $article->renderBody()); } + public function testRenderedContentIsHtmlable() + { + $article = $this->makeArticle("# Header Content \n\n Body Content"); + + $this->assertInstanceOf(HtmlString::class, $article->renderHeader()); + $this->assertInstanceOf(HtmlString::class, $article->renderBody()); + $this->assertInstanceOf(HtmlString::class, $article->renderFooter()); + } + public function testCreateHelperCreatesNewInstanceAndProcessesIt() { $article = $this->makeArticle(); $this->assertInstanceOf(SemanticDocumentationArticle::class, $article); - $this->assertSame( - '

Hello world.

', - $article->renderBody()->toHtml() - ); + $this->assertEquals('

Hello world.

', $article->renderBody()); } public function testRenderHeaderReturnsTheExtractedHeader() { - $this->assertSame( - '

Foo

', - $this->makeArticle()->renderHeader()->toHtml() - ); + $this->assertSame('

Foo

', $this->makeArticle()->renderHeader()->toHtml()); } public function testRenderHeaderReturnsTheExtractedHeaderWithVaryingNewlines() @@ -108,10 +111,7 @@ public function testRenderBodyReturnsTheExtractedBodyWithVaryingNewlines() public function testRenderFooterIsEmptyByDefault() { - $this->assertSame( - '', - $this->makeArticle()->renderFooter()->toHtml() - ); + $this->assertSame('', $this->makeArticle()->renderFooter()->toHtml()); } public function testAddDynamicHeaderContentAddsSourceLinkWhenConditionsAreMet() @@ -119,7 +119,7 @@ public function testAddDynamicHeaderContentAddsSourceLinkWhenConditionsAreMet() config(['docs.source_file_location_base' => 'https://example.com/']); config(['docs.edit_source_link_position' => 'header']); - $this->assertEqualsIgnoringNewlinesAndIndentation(<<<'HTML' + $this->assertSameIgnoringNewlinesAndIndentation(<<<'HTML'

Foo

HTML, $this->makeArticle()->renderHeader()); } @@ -129,7 +129,7 @@ public function testEditSourceLinkIsAddedToFooterWhenConditionsAreMet() config(['docs.source_file_location_base' => 'https://example.com/']); config(['docs.edit_source_link_position' => 'footer']); - $this->assertEqualsIgnoringNewlinesAndIndentation(<<<'HTML' + $this->assertSameIgnoringNewlinesAndIndentation(<<<'HTML' HTML, $this->makeArticle()->renderFooter()); } @@ -141,11 +141,11 @@ public function testEditSourceLinkCanBeAddedToBothHeaderAndFooter() $article = $this->makeArticle(); - $this->assertEqualsIgnoringNewlinesAndIndentation(<<<'HTML' + $this->assertSameIgnoringNewlinesAndIndentation(<<<'HTML'

Foo

HTML, $article->renderHeader()); - $this->assertEqualsIgnoringNewlinesAndIndentation(<<<'HTML' + $this->assertSameIgnoringNewlinesAndIndentation(<<<'HTML' HTML, $article->renderFooter()); } @@ -156,7 +156,7 @@ public function testEditSourceLinkTextCanBeCustomizedInHeader() config(['docs.edit_source_link_position' => 'both']); config(['docs.edit_source_link_text' => 'Go to Source']); - $this->assertEqualsIgnoringNewlinesAndIndentation(<<<'HTML' + $this->assertSameIgnoringNewlinesAndIndentation(<<<'HTML'

Foo

HTML, $this->makeArticle()->renderHeader()); } @@ -167,7 +167,7 @@ public function testEditSourceLinkTextCanBeCustomizedInFooter() config(['docs.edit_source_link_position' => 'both']); config(['docs.edit_source_link_text' => 'Go to Source']); - $this->assertEqualsIgnoringNewlinesAndIndentation(<<<'HTML' + $this->assertSameIgnoringNewlinesAndIndentation(<<<'HTML' HTML, $this->makeArticle()->renderFooter()); } @@ -228,9 +228,9 @@ protected function makePage(string $sourceFileContents = "# Foo\n\nHello world." return DocumentationPage::parse('foo'); } - protected function assertEqualsIgnoringNewlinesAndIndentation(string $expected, HtmlString $actual): void + protected function assertSameIgnoringNewlinesAndIndentation(string $expected, HtmlString $actual): void { - $this->assertEquals( + $this->assertSame( $this->stripNewlinesAndIndentation($expected), $this->stripNewlinesAndIndentation($actual->toHtml()), ); From df3a1240132d0f30cad061192d74a6d184612899 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:33:24 +0200 Subject: [PATCH 101/222] Add code spacing --- .../framework/tests/Feature/Services/SitemapServiceTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/framework/tests/Feature/Services/SitemapServiceTest.php b/packages/framework/tests/Feature/Services/SitemapServiceTest.php index c21f16b677c..22f79ea16bb 100644 --- a/packages/framework/tests/Feature/Services/SitemapServiceTest.php +++ b/packages/framework/tests/Feature/Services/SitemapServiceTest.php @@ -22,6 +22,7 @@ protected function setUp(): void File::deleteDirectory(Hyde::path('_pages')); File::makeDirectory(Hyde::path('_pages')); + copy(Hyde::vendorPath('resources/views/homepages/welcome.blade.php'), Hyde::path('_pages/index.blade.php')); copy(Hyde::vendorPath('resources/views/pages/404.blade.php'), Hyde::path('_pages/404.blade.php')); } @@ -81,6 +82,7 @@ public function testGetXmlReturnsXmlString() { $service = new SitemapGenerator(); $service->generate(); + $xml = $service->getXml(); $this->assertIsString($xml); @@ -99,12 +101,14 @@ public function testUrlItemIsGeneratedCorrectly() { config(['hyde.pretty_urls' => false]); config(['hyde.url' => 'https://example.com']); + Filesystem::touch('_pages/0-test.blade.php'); $service = new SitemapGenerator(); $service->generate(); $url = $service->getXmlElement()->url[0]; + $this->assertEquals('https://example.com/0-test.html', $url->loc); $this->assertEquals('daily', $url->changefreq); $this->assertTrue(isset($url->lastmod)); @@ -116,6 +120,7 @@ public function testUrlItemIsGeneratedWithPrettyUrlsIfEnabled() { config(['hyde.pretty_urls' => true]); config(['hyde.url' => 'https://example.com']); + Filesystem::touch('_pages/0-test.blade.php'); $service = new SitemapGenerator(); @@ -130,6 +135,7 @@ public function testUrlItemIsGeneratedWithPrettyUrlsIfEnabled() public function testAllRouteTypesAreDiscovered() { config(['hyde.url' => 'foo']); + Filesystem::unlink(['_pages/index.blade.php', '_pages/404.blade.php']); $files = [ From 50eb5fc9f9f5746e20b9092637ab67182515a13e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:38:12 +0200 Subject: [PATCH 102/222] Better test type handling --- .../framework/tests/Feature/Services/RssFeedServiceTest.php | 5 ++++- .../framework/tests/Feature/Services/SitemapServiceTest.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php index 475fb7705d9..2d0a59621ac 100644 --- a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php +++ b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php @@ -1,9 +1,12 @@ assertInstanceOf('SimpleXMLElement', $service->getXmlElement()); + $this->assertInstanceOf(SimpleXMLElement::class, $service->getXmlElement()); } public function testXmlRootElementIsSetToRss20() diff --git a/packages/framework/tests/Feature/Services/SitemapServiceTest.php b/packages/framework/tests/Feature/Services/SitemapServiceTest.php index 22f79ea16bb..572879ab0d8 100644 --- a/packages/framework/tests/Feature/Services/SitemapServiceTest.php +++ b/packages/framework/tests/Feature/Services/SitemapServiceTest.php @@ -1,9 +1,12 @@ assertInstanceOf('SimpleXMLElement', $service->getXmlElement()); + $this->assertInstanceOf(SimpleXMLElement::class, $service->getXmlElement()); } public function testGenerateAddsDefaultPagesToXml() From db90323675401cc2acaa158bb5d22e1b6853b235 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:38:19 +0200 Subject: [PATCH 103/222] Code formatting --- .../framework/tests/Feature/Services/RssFeedServiceTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php index 2d0a59621ac..c2ba1c0e6c2 100644 --- a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php +++ b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php @@ -45,6 +45,7 @@ public function testXmlChannelElementHasRequiredElements() config(['hyde.rss.description' => 'Test Blog RSS Feed']); $service = new RssFeedGenerator(); + $this->assertTrue(property_exists($service->getXmlElement()->channel, 'title')); $this->assertTrue(property_exists($service->getXmlElement()->channel, 'link')); $this->assertTrue(property_exists($service->getXmlElement()->channel, 'description')); @@ -59,10 +60,12 @@ public function testXmlChannelElementHasAdditionalElements() config(['hyde.url' => 'https://example.com']); $service = new RssFeedGenerator(); + $this->assertTrue(property_exists($service->getXmlElement()->channel, 'link')); $this->assertEquals('https://example.com', $service->getXmlElement()->channel->link); $this->assertEquals('https://example.com/feed.xml', - $service->getXmlElement()->channel->children('atom', true)->link->attributes()->href); + $service->getXmlElement()->channel->children('atom', true)->link->attributes()->href + ); $this->assertTrue(property_exists($service->getXmlElement()->channel, 'language')); $this->assertTrue(property_exists($service->getXmlElement()->channel, 'generator')); From e96032963604611703813fa0ea39247e223c76f1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 21:49:21 +0200 Subject: [PATCH 104/222] Create temporary helper for property state assertions --- .../framework/tests/Feature/HydePageTest.php | 4 ++-- .../Feature/Services/RssFeedServiceTest.php | 18 +++++++++--------- packages/testing/src/TestCase.php | 7 +++++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/framework/tests/Feature/HydePageTest.php b/packages/framework/tests/Feature/HydePageTest.php index c8487693cd1..09affb6a14d 100644 --- a/packages/framework/tests/Feature/HydePageTest.php +++ b/packages/framework/tests/Feature/HydePageTest.php @@ -525,12 +525,12 @@ public function testAbstractMarkdownPageImplementsPageContract() public function testAbstractMarkdownPageHasMarkdownDocumentProperty() { - $this->assertTrue(property_exists(BaseMarkdownPage::class, 'markdown')); + $this->assertTrue_property_exists(BaseMarkdownPage::class, 'markdown'); } public function testAbstractMarkdownPageHasFileExtensionProperty() { - $this->assertTrue(property_exists(BaseMarkdownPage::class, 'fileExtension')); + $this->assertTrue_property_exists(BaseMarkdownPage::class, 'fileExtension'); } public function testAbstractMarkdownPageFileExtensionPropertyIsSetToMd() diff --git a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php index c2ba1c0e6c2..74ce51bb7d6 100644 --- a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php +++ b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php @@ -35,7 +35,7 @@ public function testXmlRootElementIsSetToRss20() public function testXmlElementHasChannelElement() { $service = new RssFeedGenerator(); - $this->assertTrue(property_exists($service->getXmlElement(), 'channel')); + $this->assertTrue_property_exists($service->getXmlElement(), 'channel'); } public function testXmlChannelElementHasRequiredElements() @@ -46,9 +46,9 @@ public function testXmlChannelElementHasRequiredElements() $service = new RssFeedGenerator(); - $this->assertTrue(property_exists($service->getXmlElement()->channel, 'title')); - $this->assertTrue(property_exists($service->getXmlElement()->channel, 'link')); - $this->assertTrue(property_exists($service->getXmlElement()->channel, 'description')); + $this->assertTrue_property_exists($service->getXmlElement()->channel, 'title'); + $this->assertTrue_property_exists($service->getXmlElement()->channel, 'link'); + $this->assertTrue_property_exists($service->getXmlElement()->channel, 'description'); $this->assertEquals('Test Blog', $service->getXmlElement()->channel->title); $this->assertEquals('https://example.com', $service->getXmlElement()->channel->link); @@ -61,15 +61,15 @@ public function testXmlChannelElementHasAdditionalElements() $service = new RssFeedGenerator(); - $this->assertTrue(property_exists($service->getXmlElement()->channel, 'link')); + $this->assertTrue_property_exists($service->getXmlElement()->channel, 'link'); $this->assertEquals('https://example.com', $service->getXmlElement()->channel->link); $this->assertEquals('https://example.com/feed.xml', $service->getXmlElement()->channel->children('atom', true)->link->attributes()->href ); - $this->assertTrue(property_exists($service->getXmlElement()->channel, 'language')); - $this->assertTrue(property_exists($service->getXmlElement()->channel, 'generator')); - $this->assertTrue(property_exists($service->getXmlElement()->channel, 'lastBuildDate')); + $this->assertTrue_property_exists($service->getXmlElement()->channel, 'language'); + $this->assertTrue_property_exists($service->getXmlElement()->channel, 'generator'); + $this->assertTrue_property_exists($service->getXmlElement()->channel, 'lastBuildDate'); } public function testXmlChannelDataCanBeCustomized() @@ -118,7 +118,7 @@ public function testMarkdownBlogPostsAreAddedToRssFeedThroughAutodiscovery() $this->assertEquals('Hyde', $item->children('dc', true)->creator); $this->assertEquals('test', $item->category); - $this->assertTrue(property_exists($item, 'enclosure')); + $this->assertTrue_property_exists($item, 'enclosure'); $this->assertEquals('https://example.com/media/rss-test.jpg', $item->enclosure->attributes()->url); $this->assertEquals('image/jpeg', $item->enclosure->attributes()->type); $this->assertEquals('8', $item->enclosure->attributes()->length); diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 9926306fb9d..f4304bbe3b7 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -69,4 +69,11 @@ protected function throwOnConsoleException(bool $throw = true): void { config(['app.throw_on_console_exception' => $throw]); } + + public function assertTrue_property_exists($object_or_class, string $property): bool + { + $this->assertTrue(property_exists($object_or_class, $property)); + + return true; + } } From a054cef68fdf01631ec595fdc8dc2dcdb4e4d178 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:02:39 +0200 Subject: [PATCH 105/222] Assert object has property --- packages/testing/src/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index f4304bbe3b7..1c411bc3be0 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -72,7 +72,7 @@ protected function throwOnConsoleException(bool $throw = true): void public function assertTrue_property_exists($object_or_class, string $property): bool { - $this->assertTrue(property_exists($object_or_class, $property)); + $this->assertObjectHasProperty($property, $object_or_class); return true; } From dab4eca80d2edf8eaf04772e17871129be732fb7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:02:55 +0200 Subject: [PATCH 106/222] Void method --- packages/testing/src/TestCase.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 1c411bc3be0..544aee0b2ed 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -70,10 +70,8 @@ protected function throwOnConsoleException(bool $throw = true): void config(['app.throw_on_console_exception' => $throw]); } - public function assertTrue_property_exists($object_or_class, string $property): bool + public function assertTrue_property_exists($object_or_class, string $property): void { $this->assertObjectHasProperty($property, $object_or_class); - - return true; } } From 7da2bb5935895180c4ace75fc6a332089a1d7630 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:03:10 +0200 Subject: [PATCH 107/222] Inline temporary method --- .../framework/tests/Feature/HydePageTest.php | 4 ++-- .../Feature/Services/RssFeedServiceTest.php | 18 +++++++++--------- packages/testing/src/TestCase.php | 5 ----- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/packages/framework/tests/Feature/HydePageTest.php b/packages/framework/tests/Feature/HydePageTest.php index 09affb6a14d..d954ef05a21 100644 --- a/packages/framework/tests/Feature/HydePageTest.php +++ b/packages/framework/tests/Feature/HydePageTest.php @@ -525,12 +525,12 @@ public function testAbstractMarkdownPageImplementsPageContract() public function testAbstractMarkdownPageHasMarkdownDocumentProperty() { - $this->assertTrue_property_exists(BaseMarkdownPage::class, 'markdown'); + $this->assertObjectHasProperty('markdown', BaseMarkdownPage::class); } public function testAbstractMarkdownPageHasFileExtensionProperty() { - $this->assertTrue_property_exists(BaseMarkdownPage::class, 'fileExtension'); + $this->assertObjectHasProperty('fileExtension', BaseMarkdownPage::class); } public function testAbstractMarkdownPageFileExtensionPropertyIsSetToMd() diff --git a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php index 74ce51bb7d6..ceac7b622c1 100644 --- a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php +++ b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php @@ -35,7 +35,7 @@ public function testXmlRootElementIsSetToRss20() public function testXmlElementHasChannelElement() { $service = new RssFeedGenerator(); - $this->assertTrue_property_exists($service->getXmlElement(), 'channel'); + $this->assertObjectHasProperty('channel', $service->getXmlElement()); } public function testXmlChannelElementHasRequiredElements() @@ -46,9 +46,9 @@ public function testXmlChannelElementHasRequiredElements() $service = new RssFeedGenerator(); - $this->assertTrue_property_exists($service->getXmlElement()->channel, 'title'); - $this->assertTrue_property_exists($service->getXmlElement()->channel, 'link'); - $this->assertTrue_property_exists($service->getXmlElement()->channel, 'description'); + $this->assertObjectHasProperty('title', $service->getXmlElement()->channel); + $this->assertObjectHasProperty('link', $service->getXmlElement()->channel); + $this->assertObjectHasProperty('description', $service->getXmlElement()->channel); $this->assertEquals('Test Blog', $service->getXmlElement()->channel->title); $this->assertEquals('https://example.com', $service->getXmlElement()->channel->link); @@ -61,15 +61,15 @@ public function testXmlChannelElementHasAdditionalElements() $service = new RssFeedGenerator(); - $this->assertTrue_property_exists($service->getXmlElement()->channel, 'link'); + $this->assertObjectHasProperty('link', $service->getXmlElement()->channel); $this->assertEquals('https://example.com', $service->getXmlElement()->channel->link); $this->assertEquals('https://example.com/feed.xml', $service->getXmlElement()->channel->children('atom', true)->link->attributes()->href ); - $this->assertTrue_property_exists($service->getXmlElement()->channel, 'language'); - $this->assertTrue_property_exists($service->getXmlElement()->channel, 'generator'); - $this->assertTrue_property_exists($service->getXmlElement()->channel, 'lastBuildDate'); + $this->assertObjectHasProperty('language', $service->getXmlElement()->channel); + $this->assertObjectHasProperty('generator', $service->getXmlElement()->channel); + $this->assertObjectHasProperty('lastBuildDate', $service->getXmlElement()->channel); } public function testXmlChannelDataCanBeCustomized() @@ -118,7 +118,7 @@ public function testMarkdownBlogPostsAreAddedToRssFeedThroughAutodiscovery() $this->assertEquals('Hyde', $item->children('dc', true)->creator); $this->assertEquals('test', $item->category); - $this->assertTrue_property_exists($item, 'enclosure'); + $this->assertObjectHasProperty('enclosure', $item); $this->assertEquals('https://example.com/media/rss-test.jpg', $item->enclosure->attributes()->url); $this->assertEquals('image/jpeg', $item->enclosure->attributes()->type); $this->assertEquals('8', $item->enclosure->attributes()->length); diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 544aee0b2ed..9926306fb9d 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -69,9 +69,4 @@ protected function throwOnConsoleException(bool $throw = true): void { config(['app.throw_on_console_exception' => $throw]); } - - public function assertTrue_property_exists($object_or_class, string $property): void - { - $this->assertObjectHasProperty($property, $object_or_class); - } } From 67dfcae40f5283b2516dca7f6e41cc08b71c8e4f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:05:47 +0200 Subject: [PATCH 108/222] Revert testing helper change in file --- packages/framework/tests/Feature/HydePageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/HydePageTest.php b/packages/framework/tests/Feature/HydePageTest.php index d954ef05a21..c8487693cd1 100644 --- a/packages/framework/tests/Feature/HydePageTest.php +++ b/packages/framework/tests/Feature/HydePageTest.php @@ -525,12 +525,12 @@ public function testAbstractMarkdownPageImplementsPageContract() public function testAbstractMarkdownPageHasMarkdownDocumentProperty() { - $this->assertObjectHasProperty('markdown', BaseMarkdownPage::class); + $this->assertTrue(property_exists(BaseMarkdownPage::class, 'markdown')); } public function testAbstractMarkdownPageHasFileExtensionProperty() { - $this->assertObjectHasProperty('fileExtension', BaseMarkdownPage::class); + $this->assertTrue(property_exists(BaseMarkdownPage::class, 'fileExtension')); } public function testAbstractMarkdownPageFileExtensionPropertyIsSetToMd() From 0ad2ac4c623328e757250014fb2a5227195d6b5a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:03:33 +0200 Subject: [PATCH 109/222] Sort imports --- packages/testing/src/TestCase.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 9926306fb9d..267468afeb7 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -4,17 +4,15 @@ namespace Hyde\Testing; -use function config; -use function file_get_contents; - -use Hyde\Facades\Features; use Hyde\Hyde; - -use function Hyde\normalize_newlines; - +use Hyde\Facades\Features; use Illuminate\View\Component; use LaravelZero\Framework\Testing\TestCase as BaseTestCase; +use function Hyde\normalize_newlines; +use function file_get_contents; +use function config; + abstract class TestCase extends BaseTestCase { use CreatesApplication; From 7fb0fe2bd394b71b9d7e887c1259f1ae43a97bb6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:12:34 +0200 Subject: [PATCH 110/222] Refactor and cleanup test --- .../Services/ValidationServiceTest.php | 75 +++++++++++++------ 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/packages/framework/tests/Feature/Services/ValidationServiceTest.php b/packages/framework/tests/Feature/Services/ValidationServiceTest.php index 74c487725d7..baff83b11c6 100644 --- a/packages/framework/tests/Feature/Services/ValidationServiceTest.php +++ b/packages/framework/tests/Feature/Services/ValidationServiceTest.php @@ -27,12 +27,12 @@ protected function setUp(): void $this->service = new ValidationService(); } - // Rather meta, but lets us know that the method assertions are correct, and gives us test coverage - protected function test(string $method, int $expectedStatusCode) + protected function testMethod(string $method, int $expectedStatusCode): void { $result = $this->service->run($method); + $this->assertInstanceOf(ValidationResult::class, $result); - $this->assertEquals($expectedStatusCode, $result->statusCode()); + $this->assertSame($expectedStatusCode, $result->statusCode()); } public function testChecksReturnsAnArrayOfValidationCheckMethods() @@ -49,112 +49,133 @@ public function testChecksReturnsAnArrayOfValidationCheckMethods() public function testCheckValidatorsCanRun() { - $this->test('check_validators_can_run', 0); + $this->testMethod('check_validators_can_run', 0); } public function testCheckSiteHasA404PageCanPass() { - $this->test('check_site_has_a_404_page', 0); + $this->testMethod('check_site_has_a_404_page', 0); } public function testCheckSiteHasA404PageCanFail() { rename(Hyde::path('_pages/404.blade.php'), Hyde::path('_pages/404.blade.php.bak')); - $this->test('check_site_has_a_404_page', 2); + + $this->testMethod('check_site_has_a_404_page', 2); + rename(Hyde::path('_pages/404.blade.php.bak'), Hyde::path('_pages/404.blade.php')); } public function testCheckDocumentationSiteHasAnIndexPageCanPass() { touch('_docs/index.md'); - $this->test('check_documentation_site_has_an_index_page', 0); + + $this->testMethod('check_documentation_site_has_an_index_page', 0); + unlink('_docs/index.md'); } public function testCheckDocumentationSiteHasAnIndexPageCanPassWithWarningWhenOnlyFindingReadme() { touch('_docs/README.md'); - $this->test('check_documentation_site_has_an_index_page', 2); + + $this->testMethod('check_documentation_site_has_an_index_page', 2); + $this->assertStringContainsString('a _docs/readme.md file was found', - $this->service->run('check_documentation_site_has_an_index_page')->tip()); + $this->service->run('check_documentation_site_has_an_index_page')->tip() + ); + unlink('_docs/README.md'); } public function testCheckDocumentationSiteHasAnIndexPageCanFail() { touch('_docs/foo.md'); - $this->test('check_documentation_site_has_an_index_page', 2); + + $this->testMethod('check_documentation_site_has_an_index_page', 2); + unlink('_docs/foo.md'); } public function testCheckDocumentationSiteHasAnIndexPageBeSkipped() { - $this->test('check_documentation_site_has_an_index_page', 1); + $this->testMethod('check_documentation_site_has_an_index_page', 1); } public function testCheckSiteHasAnIndexPageCanPass() { - $this->test('check_site_has_an_index_page', 0); + $this->testMethod('check_site_has_an_index_page', 0); } public function testCheckSiteHasAnIndexPageCanFail() { rename(Hyde::path('_pages/index.blade.php'), Hyde::path('_pages/index.blade.php.bak')); - $this->test('check_site_has_an_index_page', 2); + + $this->testMethod('check_site_has_an_index_page', 2); + rename(Hyde::path('_pages/index.blade.php.bak'), Hyde::path('_pages/index.blade.php')); } public function testCheckSiteHasAnAppCssStylesheetCanPass() { - $this->test('check_site_has_an_app_css_stylesheet', 0); + $this->testMethod('check_site_has_an_app_css_stylesheet', 0); } public function testCheckSiteHasAnAppCssStylesheetCanFail() { rename(Hyde::path('_media/app.css'), Hyde::path('_media/app.css.bak')); - $this->test('check_site_has_an_app_css_stylesheet', 2); + + $this->testMethod('check_site_has_an_app_css_stylesheet', 2); + rename(Hyde::path('_media/app.css.bak'), Hyde::path('_media/app.css')); } public function testCheckSiteHasABaseUrlSetCanPass() { config(['hyde.url' => 'https://example.com']); - $this->test('check_site_has_a_base_url_set', 0); + + $this->testMethod('check_site_has_a_base_url_set', 0); } public function testCheckSiteHasABaseUrlSetCanFail() { config(['hyde.url' => null]); - $this->test('check_site_has_a_base_url_set', 2); + + $this->testMethod('check_site_has_a_base_url_set', 2); } public function testCheckATorchlightApiTokenIsSetCanSkip() { config(['hyde.features' => []]); - $this->test('check_a_torchlight_api_token_is_set', 1); + + $this->testMethod('check_a_torchlight_api_token_is_set', 1); } public function testCheckATorchlightApiTokenIsSetCanPass() { config(['torchlight.token' => '12345']); - $this->test('check_a_torchlight_api_token_is_set', 0); + + $this->testMethod('check_a_torchlight_api_token_is_set', 0); } public function testCheckATorchlightApiTokenIsSetCanFail() { config(['torchlight.token' => null]); - $this->test('check_a_torchlight_api_token_is_set', 2); + + $this->testMethod('check_a_torchlight_api_token_is_set', 2); } public function testCheckForConflictsBetweenBladeAndMarkdownPagesCanPass() { - $this->test('check_for_conflicts_between_blade_and_markdown_pages', 0); + $this->testMethod('check_for_conflicts_between_blade_and_markdown_pages', 0); } public function testCheckForConflictsBetweenBladeAndMarkdownPagesCanFail() { Filesystem::touch('_pages/index.md'); - $this->test('check_for_conflicts_between_blade_and_markdown_pages', 2); + + $this->testMethod('check_for_conflicts_between_blade_and_markdown_pages', 2); + Filesystem::unlink('_pages/index.md'); } @@ -169,8 +190,10 @@ public function testValidationResultMessageReturnsMessage() public function testValidationResultPassedReturnsTrueWhenPassedIsTrue() { $result = new ValidationResult(); + $result->pass(); $this->assertTrue($result->passed()); + $result->fail(); $this->assertFalse($result->passed()); } @@ -178,8 +201,10 @@ public function testValidationResultPassedReturnsTrueWhenPassedIsTrue() public function testValidationResultFailedReturnsTrueWhenPassedIsFalse() { $result = new ValidationResult(); + $result->pass(); $this->assertFalse($result->failed()); + $result->fail(); $this->assertTrue($result->failed()); } @@ -187,16 +212,22 @@ public function testValidationResultFailedReturnsTrueWhenPassedIsFalse() public function testValidationResultSkippedReturnsTrueWhenSkippedIsTrue() { $result = new ValidationResult(); + $this->assertFalse($result->skipped()); + $result->skip(); + $this->assertTrue($result->skipped()); } public function testValidationResultTipReturnsMessageWhenSet() { $result = new ValidationResult(); + $this->assertFalse($result->tip()); + $result->withTip('foo'); + $this->assertEquals('foo', $result->tip()); } } From 9fbde3bcc8d6952947962c4157fc4da85d2d6401 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:14:56 +0200 Subject: [PATCH 111/222] Add code spacing --- .../framework/tests/Feature/Services/RssFeedServiceTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php index ceac7b622c1..0edbb20f93c 100644 --- a/packages/framework/tests/Feature/Services/RssFeedServiceTest.php +++ b/packages/framework/tests/Feature/Services/RssFeedServiceTest.php @@ -111,9 +111,11 @@ public function testMarkdownBlogPostsAreAddedToRssFeedThroughAutodiscovery() $this->assertCount(1, $service->getXmlElement()->channel->item); $item = $service->getXmlElement()->channel->item[0]; + $this->assertEquals('RSS', $item->title); $this->assertEquals('RSS description', $item->description); $this->assertEquals('https://example.com/posts/rss.html', $item->link); + $this->assertEquals(date(DATE_RSS, strtotime('2022-05-19T10:15:30+00:00')), $item->pubDate); $this->assertEquals('Hyde', $item->children('dc', true)->creator); $this->assertEquals('test', $item->category); @@ -142,6 +144,7 @@ public function testCanGenerateFeedHelperReturnsTrueIfHydeHasBaseUrl() { config(['hyde.url' => 'foo']); $this->file('_posts/foo.md'); + $this->assertTrue(Features::rss()); } @@ -149,6 +152,7 @@ public function testCanGenerateFeedHelperReturnsFalseIfHydeDoesNotHaveBaseUrl() { config(['hyde.url' => '']); $this->file('_posts/foo.md'); + $this->assertFalse(Features::rss()); } @@ -156,6 +160,7 @@ public function testCanGenerateFeedHelperReturnsFalseIfFeedsAreDisabledInConfig( { config(['hyde.url' => 'foo']); config(['hyde.rss.enabled' => false]); + $this->assertFalse(Features::rss()); } } From 886d457fc383662a5d242ff07993246c51b36a38 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:16:43 +0200 Subject: [PATCH 112/222] Update faulty test to match real type This is why you use assertSame for scalar types! --- packages/framework/tests/Unit/HydeFileHelpersTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/HydeFileHelpersTest.php b/packages/framework/tests/Unit/HydeFileHelpersTest.php index b5838e93b87..acae3322c4d 100644 --- a/packages/framework/tests/Unit/HydeFileHelpersTest.php +++ b/packages/framework/tests/Unit/HydeFileHelpersTest.php @@ -20,9 +20,9 @@ public function testCurrentPageReturnsCurrentPageViewProperty() $this->assertEquals('foo', Hyde::currentRouteKey()); } - public function testCurrentPageFallsBackToEmptyStringIfCurrentPageViewPropertyIsNotSet() + public function testCurrentPageFallsBackToNullStringIfCurrentPageViewPropertyIsNotSet() { - $this->assertEquals('', Hyde::currentRouteKey()); + $this->assertNull(Hyde::currentRouteKey()); } public function testCurrentRouteReturnsCurrentRouteViewProperty() From 27948de7b715508ee5673dbd1294fb15402ae6be Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:16:48 +0200 Subject: [PATCH 113/222] Use assert same instead of assert equals --- packages/framework/tests/Unit/HydeFileHelpersTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/HydeFileHelpersTest.php b/packages/framework/tests/Unit/HydeFileHelpersTest.php index acae3322c4d..7bb1974bf1d 100644 --- a/packages/framework/tests/Unit/HydeFileHelpersTest.php +++ b/packages/framework/tests/Unit/HydeFileHelpersTest.php @@ -17,7 +17,7 @@ class HydeFileHelpersTest extends TestCase public function testCurrentPageReturnsCurrentPageViewProperty() { Render::share('routeKey', 'foo'); - $this->assertEquals('foo', Hyde::currentRouteKey()); + $this->assertSame('foo', Hyde::currentRouteKey()); } public function testCurrentPageFallsBackToNullStringIfCurrentPageViewPropertyIsNotSet() @@ -28,7 +28,7 @@ public function testCurrentPageFallsBackToNullStringIfCurrentPageViewPropertyIsN public function testCurrentRouteReturnsCurrentRouteViewProperty() { Render::share('route', Routes::get('index')); - $this->assertEquals(Routes::get('index'), Hyde::currentRoute()); + $this->assertSame(Routes::get('index'), Hyde::currentRoute()); } public function testCurrentRouteFallsBackToNullIfCurrentRouteViewPropertyIsNotSet() From caaa9803e6449e899b012697177b3b8ab3bfef65 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:17:12 +0200 Subject: [PATCH 114/222] Add missing method annotation --- packages/framework/src/Hyde.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Hyde.php b/packages/framework/src/Hyde.php index a526cb0dd9d..07d82d968fd 100644 --- a/packages/framework/src/Hyde.php +++ b/packages/framework/src/Hyde.php @@ -46,6 +46,7 @@ * @method static string trimSlashes(string $string) * @method static HtmlString markdown(string $text, bool $stripIndentation = false) * @method static string currentPage() + * @method static string currentRouteKey() * @method static string getBasePath() * @method static string getSourceRoot() * @method static string getOutputDirectory() From a0ca7d46c2ccd7b9358a1b88aab01de92ddbd3db Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:18:02 +0200 Subject: [PATCH 115/222] Use assert same instead of assert equals --- packages/framework/tests/Unit/SchemaContractsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/SchemaContractsTest.php b/packages/framework/tests/Unit/SchemaContractsTest.php index 270c1f2ce5a..bf61f86d3da 100644 --- a/packages/framework/tests/Unit/SchemaContractsTest.php +++ b/packages/framework/tests/Unit/SchemaContractsTest.php @@ -96,7 +96,7 @@ public function testAllSchemasAreTested() $schemas = array_values($schemas); - $this->assertEquals(self::SCHEMAS, $schemas); + $this->assertSame(self::SCHEMAS, $schemas); } public function testAllSchemasExtendFrontMatterSchemaInterface() From 30cb896513fca1ab96b7be7865805c2594e1b3a6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:18:21 +0200 Subject: [PATCH 116/222] Add 'void' as the function's return type --- packages/framework/tests/Unit/SchemaContractsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/SchemaContractsTest.php b/packages/framework/tests/Unit/SchemaContractsTest.php index bf61f86d3da..72323cc5b88 100644 --- a/packages/framework/tests/Unit/SchemaContractsTest.php +++ b/packages/framework/tests/Unit/SchemaContractsTest.php @@ -128,7 +128,7 @@ public function testEachInterfaceOnlyHasOneSchema() } } - private function assertClassHasConstant(string $constant, string $schema) + private function assertClassHasConstant(string $constant, string $schema): void { $this->assertTrue( defined("$schema::$constant"), From d06ef09115799923ff775a3b43df6c1831d007ac Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:18:29 +0200 Subject: [PATCH 117/222] Protect testing helper --- packages/framework/tests/Unit/SchemaContractsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/SchemaContractsTest.php b/packages/framework/tests/Unit/SchemaContractsTest.php index 72323cc5b88..c4486c8ea70 100644 --- a/packages/framework/tests/Unit/SchemaContractsTest.php +++ b/packages/framework/tests/Unit/SchemaContractsTest.php @@ -128,7 +128,7 @@ public function testEachInterfaceOnlyHasOneSchema() } } - private function assertClassHasConstant(string $constant, string $schema): void + protected function assertClassHasConstant(string $constant, string $schema): void { $this->assertTrue( defined("$schema::$constant"), From 2f6f1647ce65fff125081773430ec21ff4964dee Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:22:29 +0200 Subject: [PATCH 118/222] Format comment --- packages/framework/tests/Unit/SchemaContractsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Unit/SchemaContractsTest.php b/packages/framework/tests/Unit/SchemaContractsTest.php index c4486c8ea70..2d78f740b47 100644 --- a/packages/framework/tests/Unit/SchemaContractsTest.php +++ b/packages/framework/tests/Unit/SchemaContractsTest.php @@ -15,6 +15,7 @@ /** * A state test to ensure the schemas can't be changed without breaking the tests. + * * This requires contributors to consider the impact of their changes as schema changes are rarely backwards compatible. * * @see \Hyde\Markdown\Contracts\FrontMatter\PageSchema From 40bab5b59ca7196d69b70200b41229e96abd1e3e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:22:37 +0200 Subject: [PATCH 119/222] Add spacing --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 1b08979d54f..5985e593f8e 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -41,6 +41,7 @@ protected function setUp(): void 'empty_output_directory' => false, 'generate_build_manifest' => false, ]]); + $this->createService(); } From a2f63c90a73e5c6c3af5ad69f4a282cce393aabb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:23:14 +0200 Subject: [PATCH 120/222] Make test method names clearer --- .../tests/Unit/BuildTaskServiceUnitTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 5985e593f8e..de420a675b4 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -146,13 +146,13 @@ public function testCanOverloadFrameworkTasks() $this->assertSame([GenerateSitemap::class], $this->service->getRegisteredTasks()); } - public function testSetOutputWithNull() + public function testCanSetOutputWithNull() { $this->service->setOutput(null); $this->markTestSuccessful(); } - public function testSetOutputWithOutputStyle() + public function testCanSetOutputWithOutputStyle() { $this->service->setOutput(Mockery::mock(OutputStyle::class)); $this->markTestSuccessful(); @@ -178,26 +178,26 @@ public function testGenerateSitemapExtendsPostBuildTask() $this->assertInstanceOf(PostBuildTask::class, new FrameworkGenerateSitemap()); } - public function testRunPreBuildTasks() + public function testCanRunPreBuildTasks() { $this->service->runPreBuildTasks(); $this->markTestSuccessful(); } - public function testRunPostBuildTasks() + public function testCanRunPostBuildTasks() { $this->service->runPostBuildTasks(); $this->markTestSuccessful(); } - public function testRunPreBuildTasksWithTasks() + public function testCanRunPreBuildTasksWithTasks() { $this->service->registerTask(TestPreBuildTask::class); $this->service->runPreBuildTasks(); $this->markTestSuccessful(); } - public function testRunPostBuildTasksWithTasks() + public function testCanRunPostBuildTasksWithTasks() { $this->service->registerTask(TestPostBuildTask::class); $this->service->runPostBuildTasks(); From 97fbdaaf9c4f9198f4710771e35be4c317ef4d4b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:26:14 +0200 Subject: [PATCH 121/222] Add clearer testing helper method --- .../tests/Unit/BuildTaskServiceUnitTest.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index de420a675b4..944c1f30f7a 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Unit; +use Closure; use Hyde\Foundation\HydeKernel; use Hyde\Foundation\Kernel\Filesystem; use Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest; @@ -148,14 +149,12 @@ public function testCanOverloadFrameworkTasks() public function testCanSetOutputWithNull() { - $this->service->setOutput(null); - $this->markTestSuccessful(); + $this->can(fn () => $this->service->setOutput(null)); } public function testCanSetOutputWithOutputStyle() { - $this->service->setOutput(Mockery::mock(OutputStyle::class)); - $this->markTestSuccessful(); + $this->can(fn () => $this->service->setOutput(Mockery::mock(OutputStyle::class))); } public function testGenerateBuildManifestExtendsPostBuildTask() @@ -180,28 +179,28 @@ public function testGenerateSitemapExtendsPostBuildTask() public function testCanRunPreBuildTasks() { - $this->service->runPreBuildTasks(); - $this->markTestSuccessful(); + $this->can($this->service->runPreBuildTasks(...)); } public function testCanRunPostBuildTasks() { - $this->service->runPostBuildTasks(); - $this->markTestSuccessful(); + $this->can($this->service->runPostBuildTasks(...)); } public function testCanRunPreBuildTasksWithTasks() { - $this->service->registerTask(TestPreBuildTask::class); - $this->service->runPreBuildTasks(); - $this->markTestSuccessful(); + $this->can(function () { + $this->service->registerTask(TestPreBuildTask::class); + $this->service->runPreBuildTasks(); + }); } public function testCanRunPostBuildTasksWithTasks() { - $this->service->registerTask(TestPostBuildTask::class); - $this->service->runPostBuildTasks(); - $this->markTestSuccessful(); + $this->can(function () { + $this->service->registerTask(TestPostBuildTask::class); + $this->service->runPostBuildTasks(); + }); } public function testRunPreBuildTasksCallsHandleMethods() @@ -309,6 +308,14 @@ protected function markTestSuccessful(): void $this->assertTrue(true); } + /** Assert that the given closure can be executed */ + protected function can(Closure $ability): void + { + $ability(); + + $this->markTestSuccessful(); + } + protected function createService(): BuildTaskService { $this->service = new BuildTaskService(); From ecf7f0c975c08b00d8a67a1b1fc17d43d6ba7e17 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:26:33 +0200 Subject: [PATCH 122/222] Inline helper method --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 944c1f30f7a..8b85861299d 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -303,17 +303,12 @@ public function testServiceFindsTasksInAppDirectory() self::setupKernel(); } - protected function markTestSuccessful(): void - { - $this->assertTrue(true); - } - /** Assert that the given closure can be executed */ protected function can(Closure $ability): void { $ability(); - $this->markTestSuccessful(); + $this->assertTrue(true); } protected function createService(): BuildTaskService From df9dcb576d33769be17087376db7501c3ff30250 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:27:04 +0200 Subject: [PATCH 123/222] Verify mockery expectations in teardown --- .../tests/Unit/BuildTaskServiceUnitTest.php | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 8b85861299d..c75cb662a0e 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -46,6 +46,13 @@ protected function setUp(): void $this->createService(); } + protected function tearDown(): void + { + parent::tearDown(); + + $this->verifyMockeryExpectations(); + } + public function testConstruct() { $this->assertInstanceOf(BuildTaskService::class, new BuildTaskService()); @@ -208,7 +215,7 @@ public function testRunPreBuildTasksCallsHandleMethods() $task = Mockery::mock(TestPreBuildTask::class)->makePartial()->shouldReceive('handle')->once()->getMock(); $this->service->registerTask($task); $this->service->runPreBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testRunPostBuildTasksCallsHandleMethods() @@ -216,7 +223,7 @@ public function testRunPostBuildTasksCallsHandleMethods() $task = Mockery::mock(TestPostBuildTask::class)->makePartial()->shouldReceive('handle')->once()->getMock(); $this->service->registerTask($task); $this->service->runPostBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testRunPreBuildTasksCallsRunMethods() @@ -224,7 +231,7 @@ public function testRunPreBuildTasksCallsRunMethods() $task = Mockery::mock(TestPreBuildTask::class)->makePartial()->shouldReceive('run')->once()->getMock(); $this->service->registerTask($task); $this->service->runPreBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testRunPostBuildTasksCallsRunMethods() @@ -232,7 +239,7 @@ public function testRunPostBuildTasksCallsRunMethods() $task = Mockery::mock(TestPostBuildTask::class)->makePartial()->shouldReceive('run')->once()->getMock(); $this->service->registerTask($task); $this->service->runPostBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testRunPreBuildTasksCallsRunMethodsWithNullWhenServiceHasNoOutput() @@ -240,7 +247,7 @@ public function testRunPreBuildTasksCallsRunMethodsWithNullWhenServiceHasNoOutpu $task = Mockery::mock(TestPreBuildTask::class)->makePartial()->shouldReceive('run')->with(null)->once()->getMock(); $this->service->registerTask($task); $this->service->runPreBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testRunPostBuildTasksCallsRunMethodsWithNullWhenServiceHasNoOutput() @@ -248,7 +255,7 @@ public function testRunPostBuildTasksCallsRunMethodsWithNullWhenServiceHasNoOutp $task = Mockery::mock(TestPostBuildTask::class)->makePartial()->shouldReceive('run')->with(null)->once()->getMock(); $this->service->registerTask($task); $this->service->runPostBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testRunPreBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutput() @@ -258,7 +265,7 @@ public function testRunPreBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutpu $this->service->setOutput($output); $this->service->registerTask($task); $this->service->runPreBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testRunPostBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutput() @@ -268,7 +275,7 @@ public function testRunPostBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutp $this->service->setOutput($output); $this->service->registerTask($task); $this->service->runPostBuildTasks(); - $this->verifyMockeryExpectations(); + } public function testServiceSearchesForTasksInAppDirectory() @@ -283,7 +290,7 @@ public function testServiceSearchesForTasksInAppDirectory() (new ReflectionClass($kernel))->getProperty('filesystem')->setValue($kernel, $filesystem); $this->createService(); - $this->verifyMockeryExpectations(); + self::setupKernel(); } @@ -299,7 +306,7 @@ public function testServiceFindsTasksInAppDirectory() (new ReflectionClass($kernel))->getProperty('filesystem')->setValue($kernel, $filesystem); $this->createService(); - $this->verifyMockeryExpectations(); + self::setupKernel(); } From 5a525f29358ee8eddf02360739e9e032eaa135ec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:27:44 +0200 Subject: [PATCH 124/222] Convert arrow functions to traditional closures --- .../framework/tests/Unit/BuildTaskServiceUnitTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index c75cb662a0e..5a92fce84ed 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -156,12 +156,16 @@ public function testCanOverloadFrameworkTasks() public function testCanSetOutputWithNull() { - $this->can(fn () => $this->service->setOutput(null)); + $this->can(function () { + $this->service->setOutput(null); + }); } public function testCanSetOutputWithOutputStyle() { - $this->can(fn () => $this->service->setOutput(Mockery::mock(OutputStyle::class))); + $this->can(function () { + $this->service->setOutput(Mockery::mock(OutputStyle::class)); + }); } public function testGenerateBuildManifestExtendsPostBuildTask() From d790db571a432573246a6956d05c2e5ecb243b3f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:28:35 +0200 Subject: [PATCH 125/222] Fix code spacing --- .../tests/Unit/BuildTaskServiceUnitTest.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 5a92fce84ed..e8ca9414128 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -217,6 +217,7 @@ public function testCanRunPostBuildTasksWithTasks() public function testRunPreBuildTasksCallsHandleMethods() { $task = Mockery::mock(TestPreBuildTask::class)->makePartial()->shouldReceive('handle')->once()->getMock(); + $this->service->registerTask($task); $this->service->runPreBuildTasks(); @@ -225,61 +226,61 @@ public function testRunPreBuildTasksCallsHandleMethods() public function testRunPostBuildTasksCallsHandleMethods() { $task = Mockery::mock(TestPostBuildTask::class)->makePartial()->shouldReceive('handle')->once()->getMock(); + $this->service->registerTask($task); $this->service->runPostBuildTasks(); - } public function testRunPreBuildTasksCallsRunMethods() { $task = Mockery::mock(TestPreBuildTask::class)->makePartial()->shouldReceive('run')->once()->getMock(); + $this->service->registerTask($task); $this->service->runPreBuildTasks(); - } public function testRunPostBuildTasksCallsRunMethods() { $task = Mockery::mock(TestPostBuildTask::class)->makePartial()->shouldReceive('run')->once()->getMock(); + $this->service->registerTask($task); $this->service->runPostBuildTasks(); - } public function testRunPreBuildTasksCallsRunMethodsWithNullWhenServiceHasNoOutput() { $task = Mockery::mock(TestPreBuildTask::class)->makePartial()->shouldReceive('run')->with(null)->once()->getMock(); + $this->service->registerTask($task); $this->service->runPreBuildTasks(); - } public function testRunPostBuildTasksCallsRunMethodsWithNullWhenServiceHasNoOutput() { $task = Mockery::mock(TestPostBuildTask::class)->makePartial()->shouldReceive('run')->with(null)->once()->getMock(); + $this->service->registerTask($task); $this->service->runPostBuildTasks(); - } public function testRunPreBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutput() { $output = Mockery::mock(OutputStyle::class)->makePartial(); $task = Mockery::mock(TestPreBuildTask::class)->makePartial()->shouldReceive('run')->with($output)->once()->getMock(); + $this->service->setOutput($output); $this->service->registerTask($task); $this->service->runPreBuildTasks(); - } public function testRunPostBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutput() { $output = Mockery::mock(OutputStyle::class)->makePartial(); $task = Mockery::mock(TestPostBuildTask::class)->makePartial()->shouldReceive('run')->with($output)->once()->getMock(); + $this->service->setOutput($output); $this->service->registerTask($task); $this->service->runPostBuildTasks(); - } public function testServiceSearchesForTasksInAppDirectory() From a250c994ffdb41250bbf4eb9ef61f61576dd3b53 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 14 Apr 2024 20:28:47 +0000 Subject: [PATCH 126/222] Apply fixes from StyleCI --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index e8ca9414128..718162dbf51 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -220,7 +220,6 @@ public function testRunPreBuildTasksCallsHandleMethods() $this->service->registerTask($task); $this->service->runPreBuildTasks(); - } public function testRunPostBuildTasksCallsHandleMethods() From 1641cbba9d1046ec0b7cfaf07102ce218692ab2d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:29:39 +0200 Subject: [PATCH 127/222] Remove kernel setup with no effect --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index e8ca9414128..72a9e1eef5e 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -295,8 +295,6 @@ public function testServiceSearchesForTasksInAppDirectory() (new ReflectionClass($kernel))->getProperty('filesystem')->setValue($kernel, $filesystem); $this->createService(); - - self::setupKernel(); } public function testServiceFindsTasksInAppDirectory() @@ -311,8 +309,6 @@ public function testServiceFindsTasksInAppDirectory() (new ReflectionClass($kernel))->getProperty('filesystem')->setValue($kernel, $filesystem); $this->createService(); - - self::setupKernel(); } /** Assert that the given closure can be executed */ From 5c401561b68e8e5fcae87052a3f51308f0b70f60 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:31:11 +0200 Subject: [PATCH 128/222] Extract helper method for repeated code --- .../tests/Unit/BuildTaskServiceUnitTest.php | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index d00dcaeb58e..b702f71ba83 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -284,28 +284,14 @@ public function testRunPostBuildTasksCallsRunMethodsWithOutputWhenServiceHasOutp public function testServiceSearchesForTasksInAppDirectory() { - $kernel = HydeKernel::getInstance(); - $filesystem = Mockery::mock(Filesystem::class, [$kernel]) - ->makePartial()->shouldReceive('smartGlob')->once() - ->with('app/Actions/*BuildTask.php', 0) - ->andReturn(collect())->getMock(); - - // Inject mock into Kernel (No better way to do this at the moment) - (new ReflectionClass($kernel))->getProperty('filesystem')->setValue($kernel, $filesystem); + $this->mockKernelFilesystem(); $this->createService(); } public function testServiceFindsTasksInAppDirectory() { - $kernel = HydeKernel::getInstance(); - $filesystem = Mockery::mock(Filesystem::class, [$kernel])->makePartial() - ->shouldReceive('smartGlob')->once() - ->with('app/Actions/*BuildTask.php', 0) - ->andReturn(collect())->getMock(); - - // Inject mock into Kernel - (new ReflectionClass($kernel))->getProperty('filesystem')->setValue($kernel, $filesystem); + $this->mockKernelFilesystem(); $this->createService(); } @@ -330,6 +316,17 @@ protected function verifyMockeryExpectations(): void $this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount()); Mockery::close(); } + + protected function mockKernelFilesystem(): void + { + $filesystem = Mockery::mock(Filesystem::class, [HydeKernel::getInstance()]) + ->makePartial()->shouldReceive('smartGlob')->once() + ->with('app/Actions/*BuildTask.php', 0) + ->andReturn(collect())->getMock(); + + // Inject mock into Kernel + (new ReflectionClass(HydeKernel::getInstance()))->getProperty('filesystem')->setValue(HydeKernel::getInstance(), $filesystem); + } } class InstantiableTestBuildTask extends BuildTask From 9bd9876356e5e346ff77b1ae94bb9ce80c5ac3a7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:33:04 +0200 Subject: [PATCH 129/222] Use fluent assertion syntax --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index b702f71ba83..bc6db22048d 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -286,14 +286,14 @@ public function testServiceSearchesForTasksInAppDirectory() { $this->mockKernelFilesystem(); - $this->createService(); + $this->can($this->createService(...)); } public function testServiceFindsTasksInAppDirectory() { $this->mockKernelFilesystem(); - $this->createService(); + $this->can($this->createService(...)); } /** Assert that the given closure can be executed */ From 43d78c971027194b405f1cde851d939118b061a9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:33:55 +0200 Subject: [PATCH 130/222] Actually assert that files are searched for and found --- .../tests/Unit/BuildTaskServiceUnitTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index bc6db22048d..4424391a1b7 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -287,13 +287,26 @@ public function testServiceSearchesForTasksInAppDirectory() $this->mockKernelFilesystem(); $this->can($this->createService(...)); + + $this->assertSame([], $this->service->getRegisteredTasks()); } public function testServiceFindsTasksInAppDirectory() { - $this->mockKernelFilesystem(); + $files = [ + 'app/Actions/GenerateBuildManifestBuildTask.php' => GenerateBuildManifest::class, + 'app/Actions/GenerateRssFeedBuildTask.php' => GenerateRssFeed::class, + 'app/Actions/GenerateSearchBuildTask.php' => GenerateSearch::class, + ]; + $this->mockKernelFilesystem($files); $this->can($this->createService(...)); + + $this->assertSame([ + 'Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest', + 'Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed', + 'Hyde\Framework\Actions\PostBuildTasks\GenerateSearch', + ], $this->service->getRegisteredTasks()); } /** Assert that the given closure can be executed */ @@ -317,12 +330,12 @@ protected function verifyMockeryExpectations(): void Mockery::close(); } - protected function mockKernelFilesystem(): void + protected function mockKernelFilesystem(array $files = []): void { $filesystem = Mockery::mock(Filesystem::class, [HydeKernel::getInstance()]) ->makePartial()->shouldReceive('smartGlob')->once() ->with('app/Actions/*BuildTask.php', 0) - ->andReturn(collect())->getMock(); + ->andReturn(collect($files))->getMock(); // Inject mock into Kernel (new ReflectionClass(HydeKernel::getInstance()))->getProperty('filesystem')->setValue(HydeKernel::getInstance(), $filesystem); From a148cc53772006de13ff50f1be7f1127d54f2ced Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:34:15 +0200 Subject: [PATCH 131/222] Formatting --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 4424391a1b7..66f53f4e069 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -327,6 +327,7 @@ protected function createService(): BuildTaskService protected function verifyMockeryExpectations(): void { $this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount()); + Mockery::close(); } From 466a9ed1b3666a7cfe56c622eab3d5825ab43c05 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:35:35 +0200 Subject: [PATCH 132/222] Reset the kernel instance --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 66f53f4e069..ebded9ecc85 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -51,6 +51,9 @@ protected function tearDown(): void parent::tearDown(); $this->verifyMockeryExpectations(); + + // Reset the kernel instance + self::needsKernel(); } public function testConstruct() From 6c9a6ac9ec8c9c6f0b54bcc4eb769f661e75577e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:37:27 +0200 Subject: [PATCH 133/222] Setup kernel instance --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index ebded9ecc85..81e5fa70a4c 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -53,7 +53,7 @@ protected function tearDown(): void $this->verifyMockeryExpectations(); // Reset the kernel instance - self::needsKernel(); + self::setupKernel(); } public function testConstruct() From e14b152bac84d5c65b0f645af6516fdb9af635e2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:40:59 +0200 Subject: [PATCH 134/222] Granularly reset kernel instance --- .../tests/Unit/BuildTaskServiceUnitTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 81e5fa70a4c..5fdd1539c6b 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -51,9 +51,6 @@ protected function tearDown(): void parent::tearDown(); $this->verifyMockeryExpectations(); - - // Reset the kernel instance - self::setupKernel(); } public function testConstruct() @@ -292,6 +289,8 @@ public function testServiceSearchesForTasksInAppDirectory() $this->can($this->createService(...)); $this->assertSame([], $this->service->getRegisteredTasks()); + + $this->resetKernelInstance(); } public function testServiceFindsTasksInAppDirectory() @@ -310,6 +309,8 @@ public function testServiceFindsTasksInAppDirectory() 'Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed', 'Hyde\Framework\Actions\PostBuildTasks\GenerateSearch', ], $this->service->getRegisteredTasks()); + + $this->resetKernelInstance(); } /** Assert that the given closure can be executed */ @@ -344,6 +345,11 @@ protected function mockKernelFilesystem(array $files = []): void // Inject mock into Kernel (new ReflectionClass(HydeKernel::getInstance()))->getProperty('filesystem')->setValue(HydeKernel::getInstance(), $filesystem); } + + protected function resetKernelInstance(): void + { + HydeKernel::setInstance(new HydeKernel()); + } } class InstantiableTestBuildTask extends BuildTask From fceb5c4613c109ce7acb24d2bef447199a6b3ca2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:44:12 +0200 Subject: [PATCH 135/222] Tap created instance to shorten helper --- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 5fdd1539c6b..628922c5c5b 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -323,9 +323,7 @@ protected function can(Closure $ability): void protected function createService(): BuildTaskService { - $this->service = new BuildTaskService(); - - return $this->service; + return tap(new BuildTaskService(), fn (BuildTaskService $service) => $this->service = $service); } protected function verifyMockeryExpectations(): void From 4565b501fbc673035007daf057ad2cb73b317a8a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:45:30 +0200 Subject: [PATCH 136/222] Extract testing helper trait --- .../tests/Unit/BuildTaskServiceUnitTest.php | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index 628922c5c5b..b045da0dccb 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -352,46 +352,36 @@ protected function resetKernelInstance(): void class InstantiableTestBuildTask extends BuildTask { - public function handle(): void - { - // - } + use VoidHandle; } class TestBuildTask extends PostBuildTask { - public function handle(): void - { - // - } + use VoidHandle; } class TestPreBuildTask extends PreBuildTask { - public function handle(): void - { - // - } + use VoidHandle; } class TestPostBuildTask extends PostBuildTask { - public function handle(): void - { - // - } + use VoidHandle; } class TestBuildTaskNotExtendingChildren extends BuildTask { - public function handle(): void - { - // - } + use VoidHandle; } /** Test class to test overloading */ class GenerateSitemap extends FrameworkGenerateSitemap +{ + use VoidHandle; +} + +trait VoidHandle { public function handle(): void { From 4b948df08ec6a792c08de68f5d82add1b5ce05f9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:45:34 +0200 Subject: [PATCH 137/222] Clarify test trait name --- .../tests/Unit/BuildTaskServiceUnitTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index b045da0dccb..dcfc10f9722 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -352,36 +352,36 @@ protected function resetKernelInstance(): void class InstantiableTestBuildTask extends BuildTask { - use VoidHandle; + use VoidHandleMethod; } class TestBuildTask extends PostBuildTask { - use VoidHandle; + use VoidHandleMethod; } class TestPreBuildTask extends PreBuildTask { - use VoidHandle; + use VoidHandleMethod; } class TestPostBuildTask extends PostBuildTask { - use VoidHandle; + use VoidHandleMethod; } class TestBuildTaskNotExtendingChildren extends BuildTask { - use VoidHandle; + use VoidHandleMethod; } /** Test class to test overloading */ class GenerateSitemap extends FrameworkGenerateSitemap { - use VoidHandle; + use VoidHandleMethod; } -trait VoidHandle +trait VoidHandleMethod { public function handle(): void { From a7ea042ff00ed7fddea551ef934bc5fc22c2d061 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:54:26 +0200 Subject: [PATCH 138/222] Use kernel state shorthand --- packages/framework/tests/Feature/CommandTest.php | 5 +---- .../framework/tests/Feature/Foundation/FilesystemTest.php | 5 +---- packages/framework/tests/Unit/BuildTaskServiceUnitTest.php | 5 +---- packages/framework/tests/Unit/CustomExceptionsTest.php | 5 +---- packages/framework/tests/Unit/DataCollectionUnitTest.php | 5 +---- packages/framework/tests/Unit/FeaturedImageUnitTest.php | 5 +---- 6 files changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/framework/tests/Feature/CommandTest.php b/packages/framework/tests/Feature/CommandTest.php index 68424a5ebf0..ffbf3ddbeca 100644 --- a/packages/framework/tests/Feature/CommandTest.php +++ b/packages/framework/tests/Feature/CommandTest.php @@ -17,10 +17,7 @@ */ class CommandTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - } + protected static bool $needsKernel = true; public static function tearDownAfterClass(): void { diff --git a/packages/framework/tests/Feature/Foundation/FilesystemTest.php b/packages/framework/tests/Feature/Foundation/FilesystemTest.php index a21c3ccd041..6c2c2811cd8 100644 --- a/packages/framework/tests/Feature/Foundation/FilesystemTest.php +++ b/packages/framework/tests/Feature/Foundation/FilesystemTest.php @@ -27,10 +27,7 @@ class FilesystemTest extends UnitTestCase protected Filesystem $filesystem; - public static function setUpBeforeClass(): void - { - self::needsKernel(); - } + protected static bool $needsKernel = true; protected function setUp(): void { diff --git a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php index dcfc10f9722..1581584a008 100644 --- a/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskServiceUnitTest.php @@ -31,10 +31,7 @@ class BuildTaskServiceUnitTest extends UnitTestCase { protected BuildTaskService $service; - public static function setUpBeforeClass(): void - { - self::needsKernel(); - } + protected static bool $needsKernel = true; protected function setUp(): void { diff --git a/packages/framework/tests/Unit/CustomExceptionsTest.php b/packages/framework/tests/Unit/CustomExceptionsTest.php index 5103307be25..684501c3b0c 100644 --- a/packages/framework/tests/Unit/CustomExceptionsTest.php +++ b/packages/framework/tests/Unit/CustomExceptionsTest.php @@ -21,10 +21,7 @@ */ class CustomExceptionsTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - } + protected static bool $needsKernel = true; public function testFileConflictExceptionWithDefaultMessage() { diff --git a/packages/framework/tests/Unit/DataCollectionUnitTest.php b/packages/framework/tests/Unit/DataCollectionUnitTest.php index 42ee13bcfce..fc4cfdea17b 100644 --- a/packages/framework/tests/Unit/DataCollectionUnitTest.php +++ b/packages/framework/tests/Unit/DataCollectionUnitTest.php @@ -18,10 +18,7 @@ */ class DataCollectionUnitTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - } + protected static bool $needsKernel = true; public function testClassHasStaticSourceDirectoryProperty() { diff --git a/packages/framework/tests/Unit/FeaturedImageUnitTest.php b/packages/framework/tests/Unit/FeaturedImageUnitTest.php index 3fae872b5e9..65d60985474 100644 --- a/packages/framework/tests/Unit/FeaturedImageUnitTest.php +++ b/packages/framework/tests/Unit/FeaturedImageUnitTest.php @@ -15,10 +15,7 @@ */ class FeaturedImageUnitTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - } + protected static bool $needsKernel = true; public function testCanConstruct() { From 122b2318522fda205338c42d6058e82ec34b65af Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:56:01 +0200 Subject: [PATCH 139/222] Use config state shorthand --- .../Feature/Actions/GeneratesSidebarTableOfContentsTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/Actions/GeneratesSidebarTableOfContentsTest.php b/packages/framework/tests/Feature/Actions/GeneratesSidebarTableOfContentsTest.php index cc4dc8b2e71..26c603b7b4d 100644 --- a/packages/framework/tests/Feature/Actions/GeneratesSidebarTableOfContentsTest.php +++ b/packages/framework/tests/Feature/Actions/GeneratesSidebarTableOfContentsTest.php @@ -14,10 +14,7 @@ */ class GeneratesSidebarTableOfContentsTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::mockConfig(); - } + protected static bool $needsConfig = true; public function testCanGenerateTableOfContents() { From 524e03ec23de3018ce77aa3e31fbd360a5fc97cf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:56:15 +0200 Subject: [PATCH 140/222] Use kernel and config state shorthands --- packages/framework/tests/Feature/HydeCoreExtensionTest.php | 7 ++----- packages/framework/tests/Unit/Facades/RouteFacadeTest.php | 7 ++----- .../tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php | 7 ++----- packages/framework/tests/Unit/FoundationFacadesTest.php | 7 ++----- packages/framework/tests/Unit/HydePageDataFactoryTest.php | 7 ++----- .../framework/tests/Unit/NavItemIsCurrentHelperTest.php | 7 ++----- 6 files changed, 12 insertions(+), 30 deletions(-) diff --git a/packages/framework/tests/Feature/HydeCoreExtensionTest.php b/packages/framework/tests/Feature/HydeCoreExtensionTest.php index 42859c6e968..4debb39d8d6 100644 --- a/packages/framework/tests/Feature/HydeCoreExtensionTest.php +++ b/packages/framework/tests/Feature/HydeCoreExtensionTest.php @@ -19,11 +19,8 @@ */ class HydeCoreExtensionTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - self::mockConfig(); - } + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; public function testClassExtendsExtensionClass() { diff --git a/packages/framework/tests/Unit/Facades/RouteFacadeTest.php b/packages/framework/tests/Unit/Facades/RouteFacadeTest.php index 70632f490ec..2921db7fe2d 100644 --- a/packages/framework/tests/Unit/Facades/RouteFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/RouteFacadeTest.php @@ -20,11 +20,8 @@ */ class RouteFacadeTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - self::mockConfig(); - } + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; public function testRouteFacadeAllMethodReturnsAllRoutes() { diff --git a/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php b/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php index 2c4ad10058a..b92c4b133fe 100644 --- a/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php +++ b/packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php @@ -12,11 +12,8 @@ */ class HyperlinkFormatHtmlPathTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - self::mockConfig(); - } + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; public function testHelperReturnsStringAsIsIfPrettyUrlsIsNotTrue() { diff --git a/packages/framework/tests/Unit/FoundationFacadesTest.php b/packages/framework/tests/Unit/FoundationFacadesTest.php index 96350f6fc30..fa56fe0742a 100644 --- a/packages/framework/tests/Unit/FoundationFacadesTest.php +++ b/packages/framework/tests/Unit/FoundationFacadesTest.php @@ -20,11 +20,8 @@ */ class FoundationFacadesTest extends UnitTestCase { - public static function setupBeforeClass(): void - { - self::needsKernel(); - self::mockConfig(); - } + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; public function testFilesFacade() { diff --git a/packages/framework/tests/Unit/HydePageDataFactoryTest.php b/packages/framework/tests/Unit/HydePageDataFactoryTest.php index fa7594dcec8..8c8f2a8676a 100644 --- a/packages/framework/tests/Unit/HydePageDataFactoryTest.php +++ b/packages/framework/tests/Unit/HydePageDataFactoryTest.php @@ -16,11 +16,8 @@ */ class HydePageDataFactoryTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - self::mockConfig(); - } + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; protected function tearDown(): void { diff --git a/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php b/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php index d9500006247..3f83394b217 100644 --- a/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php +++ b/packages/framework/tests/Unit/NavItemIsCurrentHelperTest.php @@ -20,11 +20,8 @@ */ class NavItemIsCurrentHelperTest extends UnitTestCase { - public static function setUpBeforeClass(): void - { - self::needsKernel(); - self::mockConfig(); - } + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; protected function tearDown(): void { From 36fe450a2d2bc59f618fb47a2aeadea86743f28f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:57:32 +0200 Subject: [PATCH 141/222] Clean up test --- .../tests/Unit/Facades/RouteFacadeTest.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/Facades/RouteFacadeTest.php b/packages/framework/tests/Unit/Facades/RouteFacadeTest.php index 2921db7fe2d..a63a9b7669f 100644 --- a/packages/framework/tests/Unit/Facades/RouteFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/RouteFacadeTest.php @@ -31,6 +31,7 @@ public function testRouteFacadeAllMethodReturnsAllRoutes() public function testGetOrFailThrowsExceptionIfRouteIsNotFound() { $this->expectException(RouteNotFoundException::class); + Routes::getOrFail('not-found'); } @@ -52,22 +53,28 @@ public function testGetFromReturnsNullIfRouteIsNotFound() public function testGetSupportsDotNotation() { Hyde::routes()->add(new Route(new MarkdownPost('foo'))); + $this->assertSame(Routes::get('posts/foo'), Routes::get('posts.foo')); } public function testCurrentReturnsCurrentRoute() { $route = new Route(new MarkdownPage('foo')); + Render::shouldReceive('getRoute')->andReturn($route); + $this->assertSame($route, Routes::current()); - Render::swap(new RenderData()); + + $this->resetMockInstance(); } public function testCurrentReturnsNullIfRouteIsNotFound() { Render::shouldReceive('getRoute')->andReturn(null); + $this->assertNull(Routes::current()); - Render::swap(new RenderData()); + + $this->resetMockInstance(); } public function testExistsForExistingRoute() @@ -79,4 +86,9 @@ public function testExistsForNonExistingRoute() { $this->assertFalse(Routes::exists('not-found')); } + + protected function resetMockInstance(): void + { + Render::swap(new RenderData()); + } } From 0328eba4d5f100a06dd60f64057862ed4b3d735d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:58:18 +0200 Subject: [PATCH 142/222] Inline evaluated true type --- packages/framework/tests/Feature/CommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/CommandTest.php b/packages/framework/tests/Feature/CommandTest.php index ffbf3ddbeca..ae4754961e5 100644 --- a/packages/framework/tests/Feature/CommandTest.php +++ b/packages/framework/tests/Feature/CommandTest.php @@ -188,7 +188,7 @@ public function testSafeHandleException() $condition = str_starts_with($message, 'Error: This is a test at '.__FILE__.':'); $this->assertTrue($condition); - return $condition; + return true; }); $command->setOutput($output); From 25d14b2ca81d65bb751e30c7b3727c2e079bcb3a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:59:29 +0200 Subject: [PATCH 143/222] Clean up test class --- packages/framework/tests/Feature/CommandTest.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/framework/tests/Feature/CommandTest.php b/packages/framework/tests/Feature/CommandTest.php index ae4754961e5..8cb4c8ec03c 100644 --- a/packages/framework/tests/Feature/CommandTest.php +++ b/packages/framework/tests/Feature/CommandTest.php @@ -182,7 +182,9 @@ public function testHandleCallsChildSafeHandle() public function testSafeHandleException() { self::mockConfig(); + $command = new SafeThrowingTestCommand(); + $output = Mockery::mock(\Illuminate\Console\OutputStyle::class); $output->shouldReceive('writeln')->once()->withArgs(function (string $message) { $condition = str_starts_with($message, 'Error: This is a test at '.__FILE__.':'); @@ -190,11 +192,10 @@ public function testSafeHandleException() return true; }); - $command->setOutput($output); - $code = $command->handle(); + $command->setOutput($output); - $this->assertSame(1, $code); + $this->assertSame(1, $command->handle()); } public function testCanEnableThrowOnException() @@ -203,13 +204,14 @@ public function testCanEnableThrowOnException() $this->expectExceptionMessage('This is a test'); self::mockConfig(['app.throw_on_console_exception' => true]); + $command = new SafeThrowingTestCommand(); + $output = Mockery::mock(\Illuminate\Console\OutputStyle::class); $output->shouldReceive('writeln')->once(); $command->setOutput($output); - $code = $command->handle(); - $this->assertSame(1, $code); + $this->assertSame(1, $command->handle()); } public function testAskForString() @@ -301,7 +303,7 @@ public function handle(): int return 0; } - public function setMockedOutput($output) + public function setMockedOutput($output): void { $this->output = $output; } From 2fd31c24112032d6e291bc4f8c94727be4115503 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 22:59:51 +0200 Subject: [PATCH 144/222] Normalize line order --- packages/framework/tests/Unit/FeaturedImageUnitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/FeaturedImageUnitTest.php b/packages/framework/tests/Unit/FeaturedImageUnitTest.php index 65d60985474..843583aef88 100644 --- a/packages/framework/tests/Unit/FeaturedImageUnitTest.php +++ b/packages/framework/tests/Unit/FeaturedImageUnitTest.php @@ -130,16 +130,16 @@ public function testFeaturedImageGetContentLengthWithNoSource() public function testCanConstructFeaturedImageWithRemoteSource() { $image = new FeaturedImage('http/foo', ...$this->defaultArguments()); - $this->assertInstanceOf(FeaturedImage::class, $image); + $this->assertInstanceOf(FeaturedImage::class, $image); $this->assertEquals('http/foo', $image->getSource()); } public function testCanConstructFeaturedImageWithHttps() { $image = new FeaturedImage('https/foo', ...$this->defaultArguments()); - $this->assertInstanceOf(FeaturedImage::class, $image); + $this->assertInstanceOf(FeaturedImage::class, $image); $this->assertEquals('https/foo', $image->getSource()); } From 20027cb9384a0604a756857eaf6053f9c8b9246e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 23:00:17 +0200 Subject: [PATCH 145/222] Use assert same for scalar types --- .../tests/Unit/FeaturedImageUnitTest.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/framework/tests/Unit/FeaturedImageUnitTest.php b/packages/framework/tests/Unit/FeaturedImageUnitTest.php index 843583aef88..53e82fba00e 100644 --- a/packages/framework/tests/Unit/FeaturedImageUnitTest.php +++ b/packages/framework/tests/Unit/FeaturedImageUnitTest.php @@ -25,43 +25,43 @@ public function testCanConstruct() public function testGetAltText() { $this->assertNull((new NullImage)->getAltText()); - $this->assertEquals('alt', (new FilledImage)->getAltText()); + $this->assertSame('alt', (new FilledImage)->getAltText()); } public function testGetTitleText() { $this->assertNull((new NullImage)->getTitleText()); - $this->assertEquals('title', (new FilledImage)->getTitleText()); + $this->assertSame('title', (new FilledImage)->getTitleText()); } public function testGetAuthorName() { $this->assertNull((new NullImage)->getAuthorName()); - $this->assertEquals('author', (new FilledImage)->getAuthorName()); + $this->assertSame('author', (new FilledImage)->getAuthorName()); } public function testGetAuthorUrl() { $this->assertNull((new NullImage)->getAuthorUrl()); - $this->assertEquals('authorUrl', (new FilledImage)->getAuthorUrl()); + $this->assertSame('authorUrl', (new FilledImage)->getAuthorUrl()); } public function testGetCopyrightText() { $this->assertNull((new NullImage)->getCopyrightText()); - $this->assertEquals('copyright', (new FilledImage)->getCopyrightText()); + $this->assertSame('copyright', (new FilledImage)->getCopyrightText()); } public function testGetLicenseName() { $this->assertNull((new NullImage)->getLicenseName()); - $this->assertEquals('license', (new FilledImage)->getLicenseName()); + $this->assertSame('license', (new FilledImage)->getLicenseName()); } public function testGetLicenseUrl() { $this->assertNull((new NullImage)->getLicenseUrl()); - $this->assertEquals('licenseUrl', (new FilledImage)->getLicenseUrl()); + $this->assertSame('licenseUrl', (new FilledImage)->getLicenseUrl()); } public function testHasAltText() @@ -108,14 +108,14 @@ public function testHasLicenseUrl() public function testGetType() { - $this->assertEquals('local', (new LocalImage)->getType()); - $this->assertEquals('remote', (new RemoteImage)->getType()); + $this->assertSame('local', (new LocalImage)->getType()); + $this->assertSame('remote', (new RemoteImage)->getType()); } public function testGetContentLength() { - $this->assertEquals(0, (new NullImage)->getContentLength()); - $this->assertEquals(0, (new FilledImage)->getContentLength()); + $this->assertSame(0, (new NullImage)->getContentLength()); + $this->assertSame(0, (new FilledImage)->getContentLength()); } public function testFeaturedImageGetContentLengthWithNoSource() @@ -124,7 +124,7 @@ public function testFeaturedImageGetContentLengthWithNoSource() $this->expectExceptionMessage('Featured image [_media/foo] not found.'); $image = new FeaturedImage('_media/foo', ...$this->defaultArguments()); - $this->assertEquals(0, $image->getContentLength()); + $this->assertSame(0, $image->getContentLength()); } public function testCanConstructFeaturedImageWithRemoteSource() @@ -132,7 +132,7 @@ public function testCanConstructFeaturedImageWithRemoteSource() $image = new FeaturedImage('http/foo', ...$this->defaultArguments()); $this->assertInstanceOf(FeaturedImage::class, $image); - $this->assertEquals('http/foo', $image->getSource()); + $this->assertSame('http/foo', $image->getSource()); } public function testCanConstructFeaturedImageWithHttps() @@ -140,7 +140,7 @@ public function testCanConstructFeaturedImageWithHttps() $image = new FeaturedImage('https/foo', ...$this->defaultArguments()); $this->assertInstanceOf(FeaturedImage::class, $image); - $this->assertEquals('https/foo', $image->getSource()); + $this->assertSame('https/foo', $image->getSource()); } protected function defaultArguments(): array From a38f19842a52592e8c418d3e6180c2ee0b8a2d6a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 23:02:57 +0200 Subject: [PATCH 146/222] Split out extra unit tests --- .../tests/Unit/FeaturedImageUnitTest.php | 90 +++++++++++++++---- 1 file changed, 75 insertions(+), 15 deletions(-) diff --git a/packages/framework/tests/Unit/FeaturedImageUnitTest.php b/packages/framework/tests/Unit/FeaturedImageUnitTest.php index 53e82fba00e..7a2757555b8 100644 --- a/packages/framework/tests/Unit/FeaturedImageUnitTest.php +++ b/packages/framework/tests/Unit/FeaturedImageUnitTest.php @@ -22,93 +22,153 @@ public function testCanConstruct() $this->assertInstanceOf(FeaturedImage::class, new FeaturedImage('foo')); } - public function testGetAltText() + public function testGetAltTextWithoutData() { $this->assertNull((new NullImage)->getAltText()); + } + + public function testGetAltTextWithData() + { $this->assertSame('alt', (new FilledImage)->getAltText()); } - public function testGetTitleText() + public function testGetTitleTextWithoutData() { $this->assertNull((new NullImage)->getTitleText()); + } + + public function testGetTitleTextWithData() + { $this->assertSame('title', (new FilledImage)->getTitleText()); } - public function testGetAuthorName() + public function testGetAuthorNameWithoutData() { $this->assertNull((new NullImage)->getAuthorName()); + } + + public function testGetAuthorNameWithData() + { $this->assertSame('author', (new FilledImage)->getAuthorName()); } - public function testGetAuthorUrl() + public function testGetAuthorUrlWithoutData() { $this->assertNull((new NullImage)->getAuthorUrl()); + } + + public function testGetAuthorUrlWithData() + { $this->assertSame('authorUrl', (new FilledImage)->getAuthorUrl()); } - public function testGetCopyrightText() + public function testGetCopyrightTextWithoutData() { $this->assertNull((new NullImage)->getCopyrightText()); + } + + public function testGetCopyrightTextWithData() + { $this->assertSame('copyright', (new FilledImage)->getCopyrightText()); } - public function testGetLicenseName() + public function testGetLicenseNameWithoutData() { $this->assertNull((new NullImage)->getLicenseName()); + } + + public function testGetLicenseNameWithData() + { $this->assertSame('license', (new FilledImage)->getLicenseName()); } - public function testGetLicenseUrl() + public function testGetLicenseUrlWithoutData() { $this->assertNull((new NullImage)->getLicenseUrl()); + } + + public function testGetLicenseUrlWithData() + { $this->assertSame('licenseUrl', (new FilledImage)->getLicenseUrl()); } - public function testHasAltText() + public function testHasAltTextWithoutData() { $this->assertFalse((new NullImage)->hasAltText()); + } + + public function testHasAltTextWithData() + { $this->assertTrue((new FilledImage)->hasAltText()); } - public function testHasTitleText() + public function testHasTitleTextWithoutData() { $this->assertFalse((new NullImage)->hasTitleText()); + } + + public function testHasTitleTextWithData() + { $this->assertTrue((new FilledImage)->hasTitleText()); } - public function testHasAuthorName() + public function testHasAuthorNameWithoutData() { $this->assertFalse((new NullImage)->hasAuthorName()); + } + + public function testHasAuthorNameWithData() + { $this->assertTrue((new FilledImage)->hasAuthorName()); } - public function testHasAuthorUrl() + public function testHasAuthorUrlWithoutData() { $this->assertFalse((new NullImage)->hasAuthorUrl()); + } + + public function testHasAuthorUrlWithData() + { $this->assertTrue((new FilledImage)->hasAuthorUrl()); } - public function testHasCopyrightText() + public function testHasCopyrightTextWithoutData() { $this->assertFalse((new NullImage)->hasCopyrightText()); + } + + public function testHasCopyrightTextWithData() + { $this->assertTrue((new FilledImage)->hasCopyrightText()); } - public function testHasLicenseName() + public function testHasLicenseNameWithoutData() { $this->assertFalse((new NullImage)->hasLicenseName()); + } + + public function testHasLicenseNameWithData() + { $this->assertTrue((new FilledImage)->hasLicenseName()); } - public function testHasLicenseUrl() + public function testHasLicenseUrlWithoutData() { $this->assertFalse((new NullImage)->hasLicenseUrl()); + } + + public function testHasLicenseUrlWithData() + { $this->assertTrue((new FilledImage)->hasLicenseUrl()); } - public function testGetType() + public function testGetTypeForLocalImage() { $this->assertSame('local', (new LocalImage)->getType()); + } + + public function testGetTypeForRemoteImage() + { $this->assertSame('remote', (new RemoteImage)->getType()); } From a2bd956225db85a5a27f4f69f62311fe21d3e8ce Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 14 Apr 2024 23:04:04 +0200 Subject: [PATCH 147/222] Convert helper method to constant --- .../framework/tests/Unit/FeaturedImageUnitTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/framework/tests/Unit/FeaturedImageUnitTest.php b/packages/framework/tests/Unit/FeaturedImageUnitTest.php index 7a2757555b8..f66cf054f78 100644 --- a/packages/framework/tests/Unit/FeaturedImageUnitTest.php +++ b/packages/framework/tests/Unit/FeaturedImageUnitTest.php @@ -17,6 +17,8 @@ class FeaturedImageUnitTest extends UnitTestCase { protected static bool $needsKernel = true; + protected const DEFAULT_ARGUMENTS = ['alt', 'title', 'author', 'authorUrl', 'copyright', 'license', 'licenseUrl']; + public function testCanConstruct() { $this->assertInstanceOf(FeaturedImage::class, new FeaturedImage('foo')); @@ -183,13 +185,13 @@ public function testFeaturedImageGetContentLengthWithNoSource() $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('Featured image [_media/foo] not found.'); - $image = new FeaturedImage('_media/foo', ...$this->defaultArguments()); + $image = new FeaturedImage('_media/foo', ...self::DEFAULT_ARGUMENTS); $this->assertSame(0, $image->getContentLength()); } public function testCanConstructFeaturedImageWithRemoteSource() { - $image = new FeaturedImage('http/foo', ...$this->defaultArguments()); + $image = new FeaturedImage('http/foo', ...self::DEFAULT_ARGUMENTS); $this->assertInstanceOf(FeaturedImage::class, $image); $this->assertSame('http/foo', $image->getSource()); @@ -197,16 +199,11 @@ public function testCanConstructFeaturedImageWithRemoteSource() public function testCanConstructFeaturedImageWithHttps() { - $image = new FeaturedImage('https/foo', ...$this->defaultArguments()); + $image = new FeaturedImage('https/foo', ...self::DEFAULT_ARGUMENTS); $this->assertInstanceOf(FeaturedImage::class, $image); $this->assertSame('https/foo', $image->getSource()); } - - protected function defaultArguments(): array - { - return ['alt', 'title', 'author', 'authorUrl', 'copyright', 'license', 'licenseUrl']; - } } class LocalImage extends FeaturedImage From 4eb46d3ba4880b1b5d7c3760fc7013b89ea46b4b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:07:01 +0200 Subject: [PATCH 148/222] Shorten test constant --- packages/framework/tests/Unit/FeaturedImageUnitTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Unit/FeaturedImageUnitTest.php b/packages/framework/tests/Unit/FeaturedImageUnitTest.php index f66cf054f78..5ea286739a7 100644 --- a/packages/framework/tests/Unit/FeaturedImageUnitTest.php +++ b/packages/framework/tests/Unit/FeaturedImageUnitTest.php @@ -17,7 +17,7 @@ class FeaturedImageUnitTest extends UnitTestCase { protected static bool $needsKernel = true; - protected const DEFAULT_ARGUMENTS = ['alt', 'title', 'author', 'authorUrl', 'copyright', 'license', 'licenseUrl']; + protected const ARGUMENTS = ['alt', 'title', 'author', 'authorUrl', 'copyright', 'license', 'licenseUrl']; public function testCanConstruct() { @@ -185,13 +185,13 @@ public function testFeaturedImageGetContentLengthWithNoSource() $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('Featured image [_media/foo] not found.'); - $image = new FeaturedImage('_media/foo', ...self::DEFAULT_ARGUMENTS); + $image = new FeaturedImage('_media/foo', ...self::ARGUMENTS); $this->assertSame(0, $image->getContentLength()); } public function testCanConstructFeaturedImageWithRemoteSource() { - $image = new FeaturedImage('http/foo', ...self::DEFAULT_ARGUMENTS); + $image = new FeaturedImage('http/foo', ...self::ARGUMENTS); $this->assertInstanceOf(FeaturedImage::class, $image); $this->assertSame('http/foo', $image->getSource()); @@ -199,7 +199,7 @@ public function testCanConstructFeaturedImageWithRemoteSource() public function testCanConstructFeaturedImageWithHttps() { - $image = new FeaturedImage('https/foo', ...self::DEFAULT_ARGUMENTS); + $image = new FeaturedImage('https/foo', ...self::ARGUMENTS); $this->assertInstanceOf(FeaturedImage::class, $image); $this->assertSame('https/foo', $image->getSource()); From b2777501eac147b3d2996e384e8492cc909bf341 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:19:01 +0200 Subject: [PATCH 149/222] Add missing return type --- packages/framework/src/Foundation/Kernel/PageCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Kernel/PageCollection.php b/packages/framework/src/Foundation/Kernel/PageCollection.php index 865b723383a..4739a17743b 100644 --- a/packages/framework/src/Foundation/Kernel/PageCollection.php +++ b/packages/framework/src/Foundation/Kernel/PageCollection.php @@ -49,7 +49,7 @@ protected function runExtensionHandlers(): void } /** @param class-string<\Hyde\Pages\Concerns\HydePage> $pageClass */ - protected static function parsePage(string $pageClass, string $path) + protected static function parsePage(string $pageClass, string $path): HydePage { return $pageClass::parse($pageClass::pathToIdentifier($path)); } From cbf64be906010e4b84eacd1c04c671bc154de315 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:20:41 +0200 Subject: [PATCH 150/222] Strongly type void return type --- .../Framework/Actions/PostBuildTasks/GenerateBuildManifest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php b/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php index df549f48d34..d5868157740 100644 --- a/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php +++ b/packages/framework/src/Framework/Actions/PostBuildTasks/GenerateBuildManifest.php @@ -77,7 +77,7 @@ protected function jsonEncodeOutput(Collection $pages): string ], JSON_PRETTY_PRINT); } - public function setOutput(OutputStyle $output) + public function setOutput(OutputStyle $output): void { // Disable output } From c254ec41dba95c0540aefaebfeac88732d4f775e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:22:27 +0200 Subject: [PATCH 151/222] Annotate contracted parameter type --- packages/publications/src/Models/PublicationType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/publications/src/Models/PublicationType.php b/packages/publications/src/Models/PublicationType.php index ae29dc6b114..fc3a31f1c3d 100644 --- a/packages/publications/src/Models/PublicationType.php +++ b/packages/publications/src/Models/PublicationType.php @@ -134,6 +134,7 @@ public function toArray(): array return $array; } + /** @param int $options */ public function toJson($options = JSON_PRETTY_PRINT): string { return json_encode($this->toArray(), $options); From f238842c7019330846d2b32266732a0e4cbaec14 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:26:05 +0200 Subject: [PATCH 152/222] Strongly type parameter type --- .../src/Commands/ValidatePublicationTypesCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/ValidatePublicationTypesCommand.php b/packages/publications/src/Commands/ValidatePublicationTypesCommand.php index 31de77058e1..26cbb56527a 100644 --- a/packages/publications/src/Commands/ValidatePublicationTypesCommand.php +++ b/packages/publications/src/Commands/ValidatePublicationTypesCommand.php @@ -125,7 +125,7 @@ protected function displayFieldDefinitionErrors(array $schemaFields): void } } - protected function outputSummary($timeStart): void + protected function outputSummary(float $timeStart): void { $this->newLine(); $this->info(sprintf('All done in %sms using %sMB peak memory!', From 7bdce6f15a413465597c9215f941b5b7313184a1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:31:51 +0200 Subject: [PATCH 153/222] Strongly type parameter type --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index c8de642489e..d4f24fb0f79 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -161,7 +161,7 @@ protected function getPageSize(): int ); } - protected function checkIfFieldIsDuplicate($name): bool + protected function checkIfFieldIsDuplicate(string $name): bool { if ($this->fields->where('name', $name)->count() > 0) { $this->error("Field name [$name] already exists!"); From 485fddc9e37fdec02a7f5674ee2e2eba122d7271 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:33:11 +0200 Subject: [PATCH 154/222] Shift return logic to split out null from void return --- .../publications/src/Commands/MakePublicationCommand.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationCommand.php b/packages/publications/src/Commands/MakePublicationCommand.php index bd55c179331..0c5e61a5dcf 100644 --- a/packages/publications/src/Commands/MakePublicationCommand.php +++ b/packages/publications/src/Commands/MakePublicationCommand.php @@ -151,14 +151,15 @@ protected function captureMediaFieldInput(PublicationFieldDefinition $field): ?P $mediaFiles = Publications::getMediaForType($this->publicationType); if ($mediaFiles->isEmpty()) { - return $this->handleEmptyMediaFilesCollection($field); + $this->handleEmptyMediaFilesCollection($field); + + return null; } return new PublicationFieldValue(PublicationFieldTypes::Media, $this->choice('Which file would you like to use?', $mediaFiles->toArray())); } - /** @return null */ - protected function handleEmptyMediaFilesCollection(PublicationFieldDefinition $field) + protected function handleEmptyMediaFilesCollection(PublicationFieldDefinition $field): void { $directory = sprintf('directory %s/%s/', Hyde::getMediaDirectory(), $this->publicationType->getIdentifier() @@ -172,7 +173,7 @@ protected function handleEmptyMediaFilesCollection(PublicationFieldDefinition $f $this->warn("Warning: No media files found in $directory"); if ($this->confirm('Would you like to skip this field?', true)) { // We could have a choice here, where 0 skips, and 1 reloads the media files - return null; + return; } else { throw new InvalidArgumentException('Unable to locate any media files for this publication type'); } From 2a41439f6c99e35cdb592cacbaff81b0812aea9e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:39:30 +0200 Subject: [PATCH 155/222] Convert concatenation to 'sprintf()' call --- .../src/Framework/Features/XmlGenerators/RssFeedGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index ca553194fbf..938f5ccfd2d 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -115,7 +115,7 @@ public static function getFilename(): string public static function getDescription(): string { - return Config::getString('hyde.rss.description', Site::name().' RSS Feed'); + return Config::getString('hyde.rss.description', sprintf('%s RSS Feed', Site::name())); } protected function getChannel(): SimpleXMLElement From cb0b3e6a6d25bde2707c0013917b488e05cb9d8e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:40:19 +0200 Subject: [PATCH 156/222] Split string in two strings and concatenation --- .../src/Framework/Features/XmlGenerators/RssFeedGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index 938f5ccfd2d..615e273aa57 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -33,8 +33,8 @@ public function generate(): static protected function constructBaseElement(): void { - $this->xmlElement = new SimpleXMLElement(' - '); + $this->xmlElement = new SimpleXMLElement('' + .''); $this->xmlElement->addChild('channel'); $this->addBaseChannelItems(); From 6b8cc0b263ca137368635734a751d28c1d0f051c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:42:48 +0200 Subject: [PATCH 157/222] Remove private properties that are never read --- .../src/Framework/Factories/HydePageDataFactory.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/framework/src/Framework/Factories/HydePageDataFactory.php b/packages/framework/src/Framework/Factories/HydePageDataFactory.php index 0b41b26b486..8360baeacdb 100644 --- a/packages/framework/src/Framework/Factories/HydePageDataFactory.php +++ b/packages/framework/src/Framework/Factories/HydePageDataFactory.php @@ -28,10 +28,7 @@ class HydePageDataFactory extends Concerns\PageDataFactory implements PageSchema protected readonly string $title; protected readonly ?NavigationData $navigation; - private readonly string $routeKey; - private readonly string $outputPath; private readonly string $identifier; - private readonly string $pageClass; private readonly Markdown|false $markdown; private readonly FrontMatter $matter; @@ -39,10 +36,7 @@ public function __construct(private readonly CoreDataObject $pageData) { $this->matter = $this->pageData->matter; $this->markdown = $this->pageData->markdown; - $this->pageClass = $this->pageData->pageClass; $this->identifier = $this->pageData->identifier; - $this->outputPath = $this->pageData->outputPath; - $this->routeKey = $this->pageData->routeKey; $this->title = $this->makeTitle(); $this->navigation = $this->makeNavigation(); From 3fe15544b75831d910d43fe381eb5073ef4a9e58 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:43:53 +0200 Subject: [PATCH 158/222] Annotate received type --- .../src/Framework/Factories/HydePageDataFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/HydePageDataFactory.php b/packages/framework/src/Framework/Factories/HydePageDataFactory.php index 8360baeacdb..4cfd5ed6ad6 100644 --- a/packages/framework/src/Framework/Factories/HydePageDataFactory.php +++ b/packages/framework/src/Framework/Factories/HydePageDataFactory.php @@ -95,6 +95,9 @@ private function findTitleFromParentIdentifier(): ?string protected function getMatter(string $key): string|null { - return $this->matter->get($key); + /** @var ?string $value */ + $value = $this->matter->get($key); + + return $value; } } From 6d10acb95b9d3d4f0716e9988ee68d4df0e83f4f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:46:53 +0200 Subject: [PATCH 159/222] Use the filesystem unlinking helper --- .../Framework/Actions/PreBuildTasks/CleanSiteDirectory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php index f00e37ce798..bb58830bac7 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php @@ -6,10 +6,10 @@ use Hyde\Hyde; use Hyde\Facades\Config; +use Hyde\Facades\Filesystem; use Hyde\Framework\Features\BuildTasks\PreBuildTask; use Illuminate\Support\Facades\File; -use function array_map; use function basename; use function glob; use function in_array; @@ -22,7 +22,7 @@ class CleanSiteDirectory extends PreBuildTask public function handle(): void { if ($this->isItSafeToCleanOutputDirectory()) { - array_map('unlink', glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE)); + Filesystem::unlink(glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE)); File::cleanDirectory(Hyde::siteMediaPath()); } } From 73afc607b5e5c200f1fff92da637df1b869b4da3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:49:50 +0200 Subject: [PATCH 160/222] Normalize filesystem calls --- .../src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php index bb58830bac7..849f077b7cb 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php @@ -8,7 +8,6 @@ use Hyde\Facades\Config; use Hyde\Facades\Filesystem; use Hyde\Framework\Features\BuildTasks\PreBuildTask; -use Illuminate\Support\Facades\File; use function basename; use function glob; @@ -23,7 +22,7 @@ public function handle(): void { if ($this->isItSafeToCleanOutputDirectory()) { Filesystem::unlink(glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE)); - File::cleanDirectory(Hyde::siteMediaPath()); + Filesystem::cleanDirectory(Hyde::siteMediaPath()); } } From fc05ff73ba3726e85016696627b83260e09fc47b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:50:47 +0200 Subject: [PATCH 161/222] Annotate the accessed matter value --- .../src/Framework/Factories/NavigationDataFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/NavigationDataFactory.php b/packages/framework/src/Framework/Factories/NavigationDataFactory.php index d9406d6f2ca..4cf3cda63ca 100644 --- a/packages/framework/src/Framework/Factories/NavigationDataFactory.php +++ b/packages/framework/src/Framework/Factories/NavigationDataFactory.php @@ -246,6 +246,9 @@ protected function offset(?int $value, int $offset): ?int protected function getMatter(string $key): string|null|int|bool { - return $this->matter->get($key); + /** @var string|null|int|bool $value */ + $value = $this->matter->get($key); + + return $value; } } From 16051dca10a26b2dde1ba989176e1f2146f3ac56 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 10:51:24 +0200 Subject: [PATCH 162/222] Annotate class string generics --- .../framework/src/Framework/Factories/NavigationDataFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/NavigationDataFactory.php b/packages/framework/src/Framework/Factories/NavigationDataFactory.php index 4cf3cda63ca..b8f115c0458 100644 --- a/packages/framework/src/Framework/Factories/NavigationDataFactory.php +++ b/packages/framework/src/Framework/Factories/NavigationDataFactory.php @@ -228,7 +228,7 @@ protected function getSubdirectoryConfiguration(): string return Config::getString('hyde.navigation.subdirectories', 'hidden'); } - /** @param class-string $class */ + /** @param class-string<\Hyde\Pages\Concerns\HydePage> $class */ protected function isInstanceOf(string $class): bool { return is_a($this->pageClass, $class, true); From f190cd5e6c6236586c24c4bcf8f793c348dc7697 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:35:15 +0200 Subject: [PATCH 163/222] Add tests for all cases --- .../tests/Feature/RenderHelperTest.php | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/RenderHelperTest.php b/packages/framework/tests/Feature/RenderHelperTest.php index b7d553eac4d..bfc7a248ad2 100644 --- a/packages/framework/tests/Feature/RenderHelperTest.php +++ b/packages/framework/tests/Feature/RenderHelperTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Pages\MarkdownPage; +use Hyde\Support\Models\Route; use Hyde\Support\Facades\Render; use Hyde\Support\Models\RenderData; use Hyde\Testing\TestCase; @@ -62,12 +63,33 @@ public function testShareToView() $this->assertSame($page->getRouteKey(), View::shared('routeKey')); } - public function testShare() + public function testShareRouteKey() { $this->assertNull(Render::getRouteKey()); - Render::share('routeKey', 'bar'); - $this->assertSame('bar', Render::getRouteKey()); + Render::share('routeKey', 'foo'); + + $this->assertSame('foo', Render::getRouteKey()); + } + + public function testShareRoute() + { + $this->assertNull(Render::getRoute()); + + $route = new Route(new MarkdownPage()); + Render::share('route', $route); + + $this->assertSame($route, Render::getRoute()); + } + + public function testSharePage() + { + $this->assertNull(Render::getPage()); + + $page = new MarkdownPage(); + Render::share('page', $page); + + $this->assertSame($page, Render::getPage()); } public function testShareInvalidProperty() From b6bb87e458e55c9f98a75c5de624ca71c65a1f15 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:32:08 +0200 Subject: [PATCH 164/222] Test sharing invalid type --- packages/framework/tests/Feature/RenderHelperTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/framework/tests/Feature/RenderHelperTest.php b/packages/framework/tests/Feature/RenderHelperTest.php index bfc7a248ad2..33edc3a1274 100644 --- a/packages/framework/tests/Feature/RenderHelperTest.php +++ b/packages/framework/tests/Feature/RenderHelperTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Feature; +use TypeError; use Hyde\Pages\MarkdownPage; use Hyde\Support\Models\Route; use Hyde\Support\Facades\Render; @@ -100,6 +101,14 @@ public function testShareInvalidProperty() Render::share('foo', 'bar'); } + public function testShareInvalidType() + { + $this->expectException(TypeError::class); + $this->expectExceptionMessage('Cannot assign string to property Hyde\Support\Models\RenderData::$route of type Hyde\Support\Models\Route'); + + Render::share('route', 'bar'); + } + public function testShareCascadesDataToView() { $this->assertNull(View::shared('routeKey')); From fc4ac44a36913768e01cc91f522c5621d972d817 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:37:01 +0200 Subject: [PATCH 165/222] Add additional test case --- packages/framework/tests/Feature/RenderHelperTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/framework/tests/Feature/RenderHelperTest.php b/packages/framework/tests/Feature/RenderHelperTest.php index 33edc3a1274..25e7bca2d17 100644 --- a/packages/framework/tests/Feature/RenderHelperTest.php +++ b/packages/framework/tests/Feature/RenderHelperTest.php @@ -102,6 +102,14 @@ public function testShareInvalidProperty() } public function testShareInvalidType() + { + $this->expectException(TypeError::class); + $this->expectExceptionMessage('Cannot assign array to property Hyde\Support\Models\RenderData::$route of type Hyde\Support\Models\Route'); + + Render::share('route', ['foo']); + } + + public function testShareInvalidTypeForProperty() { $this->expectException(TypeError::class); $this->expectExceptionMessage('Cannot assign string to property Hyde\Support\Models\RenderData::$route of type Hyde\Support\Models\Route'); From f1a27e0a67f9dc2f0b18b9209a23ce321e1c17da Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:41:05 +0200 Subject: [PATCH 166/222] Narrow down return mixed parameter type Method body does only allow these three types, so makes sense to have it in the parameter. This has the side effect of changing the exception message, but I don't think that's breaking. It is still a type error. --- packages/framework/src/Support/Models/RenderData.php | 2 +- packages/framework/tests/Feature/RenderHelperTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Support/Models/RenderData.php b/packages/framework/src/Support/Models/RenderData.php index 5570c7f28b7..9a7b6376f15 100644 --- a/packages/framework/src/Support/Models/RenderData.php +++ b/packages/framework/src/Support/Models/RenderData.php @@ -53,7 +53,7 @@ public function shareToView(): void View::share($this->toArray()); } - public function share(string $key, mixed $value): void + public function share(string $key, HydePage|Route|string $value): void { if (property_exists($this, $key)) { $this->{$key} = $value; diff --git a/packages/framework/tests/Feature/RenderHelperTest.php b/packages/framework/tests/Feature/RenderHelperTest.php index 25e7bca2d17..39a280a638e 100644 --- a/packages/framework/tests/Feature/RenderHelperTest.php +++ b/packages/framework/tests/Feature/RenderHelperTest.php @@ -104,7 +104,7 @@ public function testShareInvalidProperty() public function testShareInvalidType() { $this->expectException(TypeError::class); - $this->expectExceptionMessage('Cannot assign array to property Hyde\Support\Models\RenderData::$route of type Hyde\Support\Models\Route'); + $this->expectExceptionMessage('Hyde\Support\Models\RenderData::share(): Argument #2 ($value) must be of type Hyde\Pages\Concerns\HydePage|Hyde\Support\Models\Route|string, array given'); Render::share('route', ['foo']); } From a40611f6239fe2f67f81458c73a29201b0cae060 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:42:50 +0200 Subject: [PATCH 167/222] Refactor feature test to be unit test Makes it run in 80ms instead of 400ms. --- .../tests/Feature/RenderHelperTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/RenderHelperTest.php b/packages/framework/tests/Feature/RenderHelperTest.php index 39a280a638e..6dbf58c8347 100644 --- a/packages/framework/tests/Feature/RenderHelperTest.php +++ b/packages/framework/tests/Feature/RenderHelperTest.php @@ -4,21 +4,34 @@ namespace Hyde\Framework\Testing\Feature; +use Mockery; use TypeError; +use InvalidArgumentException; use Hyde\Pages\MarkdownPage; use Hyde\Support\Models\Route; +use Hyde\Testing\UnitTestCase; use Hyde\Support\Facades\Render; use Hyde\Support\Models\RenderData; -use Hyde\Testing\TestCase; use Illuminate\Support\Facades\View; -use InvalidArgumentException; +use Illuminate\View\Factory; /** * @covers \Hyde\Support\Models\RenderData * @covers \Hyde\Support\Facades\Render */ -class RenderHelperTest extends TestCase +class RenderHelperTest extends UnitTestCase { + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; + + protected function setUp(): void + { + parent::setUp(); + + Render::swap(new RenderData()); + View::swap(Mockery::mock(Factory::class)->makePartial()); + } + public function testSetAndGetPage() { $this->assertNull(Render::getPage()); From c495cfde94f29cf33c8fea3f61d0fa54e1f7a1f9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:43:08 +0200 Subject: [PATCH 168/222] Move unit test to unit namespace --- .../framework/tests/{Feature => Unit}/RenderHelperTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename packages/framework/tests/{Feature => Unit}/RenderHelperTest.php (99%) diff --git a/packages/framework/tests/Feature/RenderHelperTest.php b/packages/framework/tests/Unit/RenderHelperTest.php similarity index 99% rename from packages/framework/tests/Feature/RenderHelperTest.php rename to packages/framework/tests/Unit/RenderHelperTest.php index 6dbf58c8347..ee0cc280ecb 100644 --- a/packages/framework/tests/Feature/RenderHelperTest.php +++ b/packages/framework/tests/Unit/RenderHelperTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Feature; +namespace Hyde\Framework\Testing\Unit; use Mockery; use TypeError; -use InvalidArgumentException; use Hyde\Pages\MarkdownPage; +use Illuminate\View\Factory; +use InvalidArgumentException; use Hyde\Support\Models\Route; use Hyde\Testing\UnitTestCase; use Hyde\Support\Facades\Render; use Hyde\Support\Models\RenderData; use Illuminate\Support\Facades\View; -use Illuminate\View\Factory; /** * @covers \Hyde\Support\Models\RenderData From 006e3c054252ee7825e533485ce8d3375d599a47 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:46:12 +0200 Subject: [PATCH 169/222] Changed mixed type annotation to scalar Since this is loaded from a Yaml file I don't think it's possible to use other types here --- .../framework/src/Foundation/Internal/LoadYamlConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php b/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php index 833f47fb595..59a642503ba 100644 --- a/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php +++ b/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php @@ -46,7 +46,7 @@ protected function hasYamlConfigFile(): bool || file_exists(Hyde::path('hyde.yaml')); } - /** @return array */ + /** @return array> */ protected function getYaml(): array { return Arr::undot((array) Yaml::parse(file_get_contents($this->getFile()))); From e2f6e02b8e04de7869c8c6701106e47bb8633403 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:47:07 +0200 Subject: [PATCH 170/222] Simplify type annotation --- .../framework/src/Foundation/Internal/LoadYamlConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php b/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php index 59a642503ba..faf25ce3713 100644 --- a/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php +++ b/packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php @@ -46,7 +46,7 @@ protected function hasYamlConfigFile(): bool || file_exists(Hyde::path('hyde.yaml')); } - /** @return array> */ + /** @return array */ protected function getYaml(): array { return Arr::undot((array) Yaml::parse(file_get_contents($this->getFile()))); From 678778240c8cd5e80bf07bda067be844dd23d12a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:54:33 +0200 Subject: [PATCH 171/222] Narrow down return type for never null value --- .../framework/src/Framework/Factories/NavigationDataFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/NavigationDataFactory.php b/packages/framework/src/Framework/Factories/NavigationDataFactory.php index b8f115c0458..d440f72a92d 100644 --- a/packages/framework/src/Framework/Factories/NavigationDataFactory.php +++ b/packages/framework/src/Framework/Factories/NavigationDataFactory.php @@ -120,7 +120,7 @@ private function searchForHiddenInFrontMatter(): ?bool ?? $this->invert($this->getMatter('navigation.visible')); } - private function isPageHiddenInNavigationConfiguration(): ?bool + private function isPageHiddenInNavigationConfiguration(): bool { return in_array($this->routeKey, Config::getArray('hyde.navigation.exclude', ['404'])); } From d25d27401129786955ba0616708684109b726409 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 12:57:21 +0200 Subject: [PATCH 172/222] Annotate enum string type --- .../src/Framework/Factories/NavigationDataFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/NavigationDataFactory.php b/packages/framework/src/Framework/Factories/NavigationDataFactory.php index d440f72a92d..0da5a796fc8 100644 --- a/packages/framework/src/Framework/Factories/NavigationDataFactory.php +++ b/packages/framework/src/Framework/Factories/NavigationDataFactory.php @@ -182,7 +182,10 @@ private function searchForPriorityInNavigationConfig(): ?int return $this->parseNavigationPriorityConfig($config, 'routeKey'); } - /** @param array|array $config */ + /** + * @param array|array $config + * @param 'routeKey'|'identifier' $pageKeyName + */ private function parseNavigationPriorityConfig(array $config, string $pageKeyName): ?int { $pageKey = $this->{$pageKeyName}; From dc52c62589ff56e519c2d6e2ecb99786a362b882 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:01:39 +0200 Subject: [PATCH 173/222] Add type annotation for known string type --- .../framework/src/Framework/Factories/NavigationDataFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Factories/NavigationDataFactory.php b/packages/framework/src/Framework/Factories/NavigationDataFactory.php index 0da5a796fc8..dfcf96ca0dc 100644 --- a/packages/framework/src/Framework/Factories/NavigationDataFactory.php +++ b/packages/framework/src/Framework/Factories/NavigationDataFactory.php @@ -188,6 +188,7 @@ private function searchForPriorityInNavigationConfig(): ?int */ private function parseNavigationPriorityConfig(array $config, string $pageKeyName): ?int { + /** @var string $pageKey */ $pageKey = $this->{$pageKeyName}; // Check if the config entry is a flat array or a keyed array. From 61614259c9a2a6cb2926c51718eed46cb2182f40 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:04:04 +0200 Subject: [PATCH 174/222] Annotate accessed value --- .../src/Framework/Factories/BlogPostDataFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php index 2322375ea88..161477a98d9 100644 --- a/packages/framework/src/Framework/Factories/BlogPostDataFactory.php +++ b/packages/framework/src/Framework/Factories/BlogPostDataFactory.php @@ -113,6 +113,9 @@ private function makeDescriptionFromMarkdownBody(): string protected function getMatter(string $key): string|null|array { - return $this->matter->get($key); + /** @var string|null|array $value */ + $value = $this->matter->get($key); + + return $value; } } From cc921fc8f128c810cb131d2afa1566b3f0ad8443 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:06:08 +0200 Subject: [PATCH 175/222] Introduce local variable --- .../src/Framework/Factories/FeaturedImageFactory.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Factories/FeaturedImageFactory.php b/packages/framework/src/Framework/Factories/FeaturedImageFactory.php index a844ae1cf56..082c39aec66 100644 --- a/packages/framework/src/Framework/Factories/FeaturedImageFactory.php +++ b/packages/framework/src/Framework/Factories/FeaturedImageFactory.php @@ -91,6 +91,8 @@ protected static function normalizeLocalImagePath(string $path): string protected function getStringMatter(string $key): ?string { - return is_string($this->matter->get($key)) ? $this->matter->get($key) : null; + $value = $this->matter->get($key); + + return is_string($value) ? $value : null; } } From 3493a7922886018864749595a1cd51ef298220b1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:09:16 +0200 Subject: [PATCH 176/222] Add type annotation --- .../framework/src/Framework/Factories/FeaturedImageFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Factories/FeaturedImageFactory.php b/packages/framework/src/Framework/Factories/FeaturedImageFactory.php index 082c39aec66..f2eae0188a1 100644 --- a/packages/framework/src/Framework/Factories/FeaturedImageFactory.php +++ b/packages/framework/src/Framework/Factories/FeaturedImageFactory.php @@ -91,6 +91,7 @@ protected static function normalizeLocalImagePath(string $path): string protected function getStringMatter(string $key): ?string { + /** @var string|null $value */ $value = $this->matter->get($key); return is_string($value) ? $value : null; From 5639094d316965c72fe0473f7bd641bb3b872fd1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:12:56 +0200 Subject: [PATCH 177/222] Call method directly instead of with function I think this is more readable --- .../framework/src/Framework/Services/ValidationService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Services/ValidationService.php b/packages/framework/src/Framework/Services/ValidationService.php index 89486276ee8..61e3860f5d0 100644 --- a/packages/framework/src/Framework/Services/ValidationService.php +++ b/packages/framework/src/Framework/Services/ValidationService.php @@ -14,7 +14,6 @@ use Hyde\Support\Models\ValidationResult as Result; use function count; -use function call_user_func; use function get_class_methods; use function array_intersect; use function file_exists; @@ -40,7 +39,7 @@ public static function checks(): array public function run(string $check): Result { - return call_user_func([$this, $check], new Result); + return $this->{$check}(new Result); } public function check_validators_can_run(Result $result): Result From d8e17ee5c2004883c2c3c40ba79da824c3ad2c9c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:13:57 +0200 Subject: [PATCH 178/222] Use assert same instead of assert equals --- .../tests/Feature/Services/ValidationServiceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/Services/ValidationServiceTest.php b/packages/framework/tests/Feature/Services/ValidationServiceTest.php index baff83b11c6..d3210b43d1c 100644 --- a/packages/framework/tests/Feature/Services/ValidationServiceTest.php +++ b/packages/framework/tests/Feature/Services/ValidationServiceTest.php @@ -184,7 +184,7 @@ public function testCheckForConflictsBetweenBladeAndMarkdownPagesCanFail() public function testValidationResultMessageReturnsMessage() { $result = new ValidationResult(); - $this->assertEquals('Generic check', $result->message()); + $this->assertSame('Generic check', $result->message()); } public function testValidationResultPassedReturnsTrueWhenPassedIsTrue() @@ -228,6 +228,6 @@ public function testValidationResultTipReturnsMessageWhenSet() $result->withTip('foo'); - $this->assertEquals('foo', $result->tip()); + $this->assertSame('foo', $result->tip()); } } From 354ecd679308e5a77faa375746d00522729ab552 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:16:14 +0200 Subject: [PATCH 179/222] Tap result --- packages/framework/src/Framework/Services/ValidationService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Services/ValidationService.php b/packages/framework/src/Framework/Services/ValidationService.php index 61e3860f5d0..1fa366b688c 100644 --- a/packages/framework/src/Framework/Services/ValidationService.php +++ b/packages/framework/src/Framework/Services/ValidationService.php @@ -39,7 +39,7 @@ public static function checks(): array public function run(string $check): Result { - return $this->{$check}(new Result); + return tap(new Result, fn (Result $result): Result => $this->{$check}($result)); } public function check_validators_can_run(Result $result): Result From fca99681f9173cb504bf10c1eac569c4a12e37cf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:16:18 +0200 Subject: [PATCH 180/222] Revert "Tap result" This reverts commit 354ecd679308e5a77faa375746d00522729ab552. --- packages/framework/src/Framework/Services/ValidationService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Services/ValidationService.php b/packages/framework/src/Framework/Services/ValidationService.php index 1fa366b688c..61e3860f5d0 100644 --- a/packages/framework/src/Framework/Services/ValidationService.php +++ b/packages/framework/src/Framework/Services/ValidationService.php @@ -39,7 +39,7 @@ public static function checks(): array public function run(string $check): Result { - return tap(new Result, fn (Result $result): Result => $this->{$check}($result)); + return $this->{$check}(new Result); } public function check_validators_can_run(Result $result): Result From 24bbb1523ad098c4c6c4525cdc01c71990e5b6f9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:17:39 +0200 Subject: [PATCH 181/222] Extract variable to ensure return type --- .../framework/src/Framework/Services/ValidationService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Services/ValidationService.php b/packages/framework/src/Framework/Services/ValidationService.php index 61e3860f5d0..cda14ebd4e5 100644 --- a/packages/framework/src/Framework/Services/ValidationService.php +++ b/packages/framework/src/Framework/Services/ValidationService.php @@ -39,7 +39,10 @@ public static function checks(): array public function run(string $check): Result { - return $this->{$check}(new Result); + $result = new Result; + $this->{$check}($result); + + return $result; } public function check_validators_can_run(Result $result): Result From f8c7d74d2576d159ac5da1b30ee35197e512c76a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:22:12 +0200 Subject: [PATCH 182/222] Use better typed helper --- packages/framework/src/Console/Commands/BuildSiteCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index 263ca07c495..4f46b710c16 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -141,7 +141,7 @@ protected function runNodeCommand(string $command, string $message, ?string $act $output = shell_exec(sprintf( '%s%s', - (string) app()->environment() === 'testing' ? 'echo ' : '', + app()->environment('testing') ? 'echo ' : '', $command )); From 219c4a381f34f4a9e2ca243b80535bba3e3eb339 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:36:03 +0200 Subject: [PATCH 183/222] Refactor command to use the process facade --- .../framework/src/Console/Commands/BuildSiteCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index 4f46b710c16..78b00df71a2 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -10,11 +10,11 @@ use Hyde\Console\Concerns\Command; use Hyde\Framework\Services\BuildService; use Hyde\Framework\Services\BuildTaskService; +use Illuminate\Support\Facades\Process; use function memory_get_peak_usage; use function number_format; use function array_search; -use function shell_exec; use function microtime; use function sprintf; use function app; @@ -139,13 +139,13 @@ protected function runNodeCommand(string $command, string $message, ?string $act { $this->info($message.' This may take a second.'); - $output = shell_exec(sprintf( + $output = Process::command(sprintf( '%s%s', app()->environment('testing') ? 'echo ' : '', $command - )); + ))->run(); - $this->line($output ?? sprintf( + $this->line($output->output() ?? sprintf( 'Could not %s! Is NPM installed?', $actionMessage ?? 'run script' )); From 416862a3a17736ffda0beed936fa0c050cf9ef48 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:41:50 +0200 Subject: [PATCH 184/222] Refactor to fake processes --- .../framework/src/Console/Commands/BuildSiteCommand.php | 6 +----- .../framework/tests/Feature/StaticSiteServiceTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index 78b00df71a2..a51a9c149ad 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -139,11 +139,7 @@ protected function runNodeCommand(string $command, string $message, ?string $act { $this->info($message.' This may take a second.'); - $output = Process::command(sprintf( - '%s%s', - app()->environment('testing') ? 'echo ' : '', - $command - ))->run(); + $output = Process::command($command)->run(); $this->line($output->output() ?? sprintf( 'Could not %s! Is NPM installed?', diff --git a/packages/framework/tests/Feature/StaticSiteServiceTest.php b/packages/framework/tests/Feature/StaticSiteServiceTest.php index 7f3982b41ff..a88f4a5589c 100644 --- a/packages/framework/tests/Feature/StaticSiteServiceTest.php +++ b/packages/framework/tests/Feature/StaticSiteServiceTest.php @@ -9,6 +9,7 @@ use Hyde\Support\BuildWarnings; use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Process; /** * @covers \Hyde\Console\Commands\BuildSiteCommand @@ -22,6 +23,8 @@ protected function setUp(): void parent::setUp(); $this->resetSite(); + + Process::preventStrayProcesses(); } protected function tearDown(): void @@ -128,11 +131,17 @@ public function testPrintInitialInformationAllowsApiToBeDisabled() public function testNodeActionOutputs() { + Process::fake(); + $this->artisan('build --run-prettier --run-dev --run-prod') ->expectsOutput('Prettifying code! This may take a second.') ->expectsOutput('Building frontend assets for development! This may take a second.') ->expectsOutput('Building frontend assets for production! This may take a second.') ->assertExitCode(0); + + Process::assertRan(fn ($process) => $process->command === 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line'); + Process::assertRan(fn ($process) => $process->command === 'npm run dev'); + Process::assertRan(fn ($process) => $process->command === 'npm run prod'); } public function testPrettyUrlsOptionOutput() From 21d6625df1b6855bb1d3a14faff925d48b2fce65 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:47:10 +0200 Subject: [PATCH 185/222] Annotate parameter generics --- .../framework/src/Foundation/Internal/LoadConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Internal/LoadConfiguration.php b/packages/framework/src/Foundation/Internal/LoadConfiguration.php index db1b31e4090..167e9db1c9b 100644 --- a/packages/framework/src/Foundation/Internal/LoadConfiguration.php +++ b/packages/framework/src/Foundation/Internal/LoadConfiguration.php @@ -19,7 +19,7 @@ class LoadConfiguration extends BaseLoadConfiguration /** Get all the configuration files for the application. */ protected function getConfigurationFiles(Application $app): array { - return (array) tap(parent::getConfigurationFiles($app), function (array &$files) use ($app): void { + return (array) tap(/** @param array $files */ parent::getConfigurationFiles($app), function (array &$files) use ($app): void { // Inject our custom config file which is stored in `app/config.php`. $files['app'] ??= $app->basePath().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'config.php'; }); From e427be993678529df36650cb9b7a0444d8465bd2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:48:27 +0200 Subject: [PATCH 186/222] Fix type annotation location --- .../framework/src/Foundation/Internal/LoadConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Internal/LoadConfiguration.php b/packages/framework/src/Foundation/Internal/LoadConfiguration.php index 167e9db1c9b..591430ecd2f 100644 --- a/packages/framework/src/Foundation/Internal/LoadConfiguration.php +++ b/packages/framework/src/Foundation/Internal/LoadConfiguration.php @@ -19,7 +19,7 @@ class LoadConfiguration extends BaseLoadConfiguration /** Get all the configuration files for the application. */ protected function getConfigurationFiles(Application $app): array { - return (array) tap(/** @param array $files */ parent::getConfigurationFiles($app), function (array &$files) use ($app): void { + return (array) tap(parent::getConfigurationFiles($app), /** @param array $files */ function (array &$files) use ($app): void { // Inject our custom config file which is stored in `app/config.php`. $files['app'] ??= $app->basePath().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'config.php'; }); From f307f875f9c83ae72dc7479ebd719468ed2a3427 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:50:50 +0200 Subject: [PATCH 187/222] Introduce local variable --- packages/framework/src/Pages/Concerns/HydePage.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Pages/Concerns/HydePage.php b/packages/framework/src/Pages/Concerns/HydePage.php index 64711bfb4bc..b1512a4b92c 100644 --- a/packages/framework/src/Pages/Concerns/HydePage.php +++ b/packages/framework/src/Pages/Concerns/HydePage.php @@ -399,8 +399,10 @@ public function navigationMenuGroup(): ?string public function getCanonicalUrl(): ?string { - if (! empty($this->matter('canonicalUrl'))) { - return $this->matter('canonicalUrl'); + $value = $this->matter('canonicalUrl'); + + if (! empty($value)) { + return $value; } if (Hyde::hasSiteUrl() && ! empty($this->identifier)) { From bf2731d9896aa49efb47b45b8b13aab69b6216ce Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:51:27 +0200 Subject: [PATCH 188/222] Add type annotation --- packages/framework/src/Pages/Concerns/HydePage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Pages/Concerns/HydePage.php b/packages/framework/src/Pages/Concerns/HydePage.php index b1512a4b92c..af8348d132a 100644 --- a/packages/framework/src/Pages/Concerns/HydePage.php +++ b/packages/framework/src/Pages/Concerns/HydePage.php @@ -399,6 +399,7 @@ public function navigationMenuGroup(): ?string public function getCanonicalUrl(): ?string { + /** @var ?string $value */ $value = $this->matter('canonicalUrl'); if (! empty($value)) { From 8b662e493090fd49e480a81780a8b6e82f1f584b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:52:49 +0200 Subject: [PATCH 189/222] Add code spacing --- .../src/Framework/Features/XmlGenerators/RssFeedGenerator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index 615e273aa57..c51fa013fcb 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -92,6 +92,7 @@ protected function addBaseChannelItems(): void protected function addAtomLinkItem(): void { $atomLink = $this->getChannel()->addChild('atom:link', namespace: 'http://www.w3.org/2005/Atom'); + $atomLink->addAttribute('href', $this->escape(Hyde::url($this->getFilename()))); $atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('type', 'application/rss+xml'); From d056e92e91127c5c29e4e48803755520f0144ffb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:55:04 +0200 Subject: [PATCH 190/222] Add type assertion Might be cleaner than type annotation --- .../src/Framework/Features/XmlGenerators/RssFeedGenerator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index c51fa013fcb..ecb8e84da8a 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -121,6 +121,8 @@ public static function getDescription(): string protected function getChannel(): SimpleXMLElement { + assert($this->xmlElement->channel instanceof SimpleXMLElement); + return $this->xmlElement->channel; } } From 41207dbd3d684deb59db891210e5002773348ee8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:56:14 +0200 Subject: [PATCH 191/222] Import used functions --- .../src/Framework/Features/XmlGenerators/RssFeedGenerator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index ecb8e84da8a..3d3f3f0ff4f 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -16,6 +16,8 @@ use Hyde\Framework\Features\Blogging\Models\FeaturedImage; use function date; +use function assert; +use function sprintf; /** * @see https://validator.w3.org/feed/docs/rss2.html From 416e2cb0b4d4daf57eb12dd4f7fbc5f6d2783845 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:56:27 +0200 Subject: [PATCH 192/222] Add code spacing --- .../src/Framework/Features/XmlGenerators/RssFeedGenerator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index 3d3f3f0ff4f..258edc8c72f 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -46,6 +46,7 @@ protected function constructBaseElement(): void protected function addItem(MarkdownPost $post): void { $item = $this->getChannel()->addChild('item'); + $this->addChild($item, 'title', $post->title); $this->addChild($item, 'description', $post->description); @@ -73,6 +74,7 @@ protected function addDynamicItemData(SimpleXMLElement $item, MarkdownPost $post if (isset($post->image)) { $image = $item->addChild('enclosure'); + $image->addAttribute('url', Hyde::url($post->image->getSource())); $image->addAttribute('type', $this->getImageType($post->image)); $image->addAttribute('length', $this->getImageLength($post->image)); From 80a5ea6b8c064c06919edcc7dedd826ed6fee67f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:57:17 +0200 Subject: [PATCH 193/222] Implode long concatenated string --- .../Framework/Features/XmlGenerators/RssFeedGenerator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index 258edc8c72f..09ebc3db6d8 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -18,6 +18,7 @@ use function date; use function assert; use function sprintf; +use function implode; /** * @see https://validator.w3.org/feed/docs/rss2.html @@ -35,8 +36,11 @@ public function generate(): static protected function constructBaseElement(): void { - $this->xmlElement = new SimpleXMLElement('' - .''); + $this->xmlElement = new SimpleXMLElement(implode("\n", [ + '', + '', + ])); + $this->xmlElement->addChild('channel'); $this->addBaseChannelItems(); From 36b1a201a72630234db8935f7bac89bca9aae7a3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:58:55 +0200 Subject: [PATCH 194/222] Replace ternary expression with if/else block --- packages/framework/src/Markdown/Models/Markdown.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Markdown/Models/Markdown.php b/packages/framework/src/Markdown/Models/Markdown.php index d5696a1323d..f7b11417005 100644 --- a/packages/framework/src/Markdown/Models/Markdown.php +++ b/packages/framework/src/Markdown/Models/Markdown.php @@ -91,8 +91,10 @@ public static function fromFile(string $path): static */ public static function render(string $markdown, ?string $pageClass = null): string { - return $pageClass !== null - ? (new MarkdownService($markdown, $pageClass))->parse() - : (string) app(MarkdownConverter::class)->convert($markdown); + if ($pageClass !== null) { + return (new MarkdownService($markdown, $pageClass))->parse(); + } else { + return (string) app(MarkdownConverter::class)->convert($markdown); + } } } From 92def7b5e7ecc1ca91eaa2ad842f81c9cdcafad5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 13:59:30 +0200 Subject: [PATCH 195/222] Introduce type annotated variable --- packages/framework/src/Markdown/Models/Markdown.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Markdown/Models/Markdown.php b/packages/framework/src/Markdown/Models/Markdown.php index f7b11417005..568ae22be2e 100644 --- a/packages/framework/src/Markdown/Models/Markdown.php +++ b/packages/framework/src/Markdown/Models/Markdown.php @@ -94,7 +94,10 @@ public static function render(string $markdown, ?string $pageClass = null): stri if ($pageClass !== null) { return (new MarkdownService($markdown, $pageClass))->parse(); } else { - return (string) app(MarkdownConverter::class)->convert($markdown); + /** @var MarkdownConverter $converter */ + $converter = app(MarkdownConverter::class); + + return (string) $converter->convert($markdown); } } } From 86a8fc1d4396cdfd553f16499c81e548a03bb71c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:00:43 +0200 Subject: [PATCH 196/222] Introduce type annotated variable --- .../framework/src/Framework/Actions/BladeMatterParser.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/BladeMatterParser.php b/packages/framework/src/Framework/Actions/BladeMatterParser.php index 1f6c03f2530..0dd04ba0522 100644 --- a/packages/framework/src/Framework/Actions/BladeMatterParser.php +++ b/packages/framework/src/Framework/Actions/BladeMatterParser.php @@ -136,7 +136,11 @@ protected static function getValueWithType(string $value): mixed // This will cast integers, floats, and booleans to their respective types // Still working on a way to handle multidimensional arrays and objects - return json_decode($value) ?? $value; + + /** @var scalar|null $decoded */ + $decoded = json_decode($value); + + return $decoded ?? $value; } /** @return array */ From bdeac99ab44f95c47c5df6765589a85592298a6e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:01:53 +0200 Subject: [PATCH 197/222] Add spacing --- packages/framework/src/Framework/Actions/BladeMatterParser.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Actions/BladeMatterParser.php b/packages/framework/src/Framework/Actions/BladeMatterParser.php index 0dd04ba0522..bbe123b4e31 100644 --- a/packages/framework/src/Framework/Actions/BladeMatterParser.php +++ b/packages/framework/src/Framework/Actions/BladeMatterParser.php @@ -175,6 +175,7 @@ protected static function parseArrayString(string $string): array // Add key/value pair to array $key = (string) static::getValueWithType(trim(trim($pair[0]), "'")); $value = static::getValueWithType(trim(trim($pair[1]), "'")); + $array[$key] = $value; } From 1c085e2c23475c39bd7f3a0c1dd308481ae2e359 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:02:05 +0200 Subject: [PATCH 198/222] Add clarifying parentheses --- packages/framework/src/Framework/Actions/BladeMatterParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/BladeMatterParser.php b/packages/framework/src/Framework/Actions/BladeMatterParser.php index bbe123b4e31..2f2dcc6eb9c 100644 --- a/packages/framework/src/Framework/Actions/BladeMatterParser.php +++ b/packages/framework/src/Framework/Actions/BladeMatterParser.php @@ -157,7 +157,7 @@ protected static function parseArrayString(string $string): array } // Check if string is multidimensional (not yet supported) - if (substr_count($string, '[') > 1 || substr_count($string, ']') > 1) { + if ((substr_count($string, '[') > 1) || (substr_count($string, ']') > 1)) { throw new RuntimeException('Failed parsing BladeMatter array. Multidimensional arrays are not supported yet.'); } From 66fe0ae772898ffbfea5a7741d02d402ce1a1d64 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:03:42 +0200 Subject: [PATCH 199/222] Remove redundant argument --- packages/framework/tests/Feature/PaginatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PaginatorTest.php b/packages/framework/tests/Feature/PaginatorTest.php index cf4c10073bb..61c3d9444ae 100644 --- a/packages/framework/tests/Feature/PaginatorTest.php +++ b/packages/framework/tests/Feature/PaginatorTest.php @@ -22,7 +22,7 @@ public function testItCanBeInstantiated(): void public function testGetPaginatedPageCollection() { - $this->assertEquals(collect([]), (new Paginator())->getPaginatedItems()); + $this->assertEquals(collect(), (new Paginator())->getPaginatedItems()); } public function testGetPaginatedPageCollectionWithPages() From db5a0ea4a1aa2651ebb1330b92b99bb2429c02ab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:05:47 +0200 Subject: [PATCH 200/222] Clean up the test --- .../framework/tests/Feature/PaginatorTest.php | 67 ++++++++----------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/packages/framework/tests/Feature/PaginatorTest.php b/packages/framework/tests/Feature/PaginatorTest.php index 61c3d9444ae..41587d0f942 100644 --- a/packages/framework/tests/Feature/PaginatorTest.php +++ b/packages/framework/tests/Feature/PaginatorTest.php @@ -27,9 +27,7 @@ public function testGetPaginatedPageCollection() public function testGetPaginatedPageCollectionWithPages() { - $collection = (new Paginator( - range(1, 50), - ))->getPaginatedItems(); + $collection = (new Paginator(range(1, 50)))->getPaginatedItems(); $this->assertCount(2, $collection); $this->assertCount(25, $collection->first()); @@ -43,10 +41,7 @@ public function testGetPaginatedPageCollectionWithPages() public function testCollectionIsChunkedBySpecifiedSettingValue() { - $collection = (new Paginator( - range(1, 50), - 10) - )->getPaginatedItems(); + $collection = (new Paginator(range(1, 50), 10))->getPaginatedItems(); $this->assertCount(5, $collection); $this->assertCount(10, $collection->first()); @@ -66,11 +61,11 @@ public function testGetItemsForPageReturnsTheCorrectChunk() $this->assertCount(10, $paginator->setCurrentPage(4)->getItemsForPage()); $this->assertCount(10, $paginator->setCurrentPage(5)->getItemsForPage()); - $this->assertEquals(range(1, 10), $paginator->setCurrentPage(1)->getItemsForPage()->toArray()); - $this->assertEquals(array_combine(range(10, 19), range(11, 20)), $paginator->setCurrentPage(2)->getItemsForPage()->toArray()); - $this->assertEquals(array_combine(range(20, 29), range(21, 30)), $paginator->setCurrentPage(3)->getItemsForPage()->toArray()); - $this->assertEquals(array_combine(range(30, 39), range(31, 40)), $paginator->setCurrentPage(4)->getItemsForPage()->toArray()); - $this->assertEquals(array_combine(range(40, 49), range(41, 50)), $paginator->setCurrentPage(5)->getItemsForPage()->toArray()); + $this->assertSame(range(1, 10), $paginator->setCurrentPage(1)->getItemsForPage()->toArray()); + $this->assertSame(array_combine(range(10, 19), range(11, 20)), $paginator->setCurrentPage(2)->getItemsForPage()->toArray()); + $this->assertSame(array_combine(range(20, 29), range(21, 30)), $paginator->setCurrentPage(3)->getItemsForPage()->toArray()); + $this->assertSame(array_combine(range(30, 39), range(31, 40)), $paginator->setCurrentPage(4)->getItemsForPage()->toArray()); + $this->assertSame(array_combine(range(40, 49), range(41, 50)), $paginator->setCurrentPage(5)->getItemsForPage()->toArray()); } public function testCanGetCurrentPageNumber() @@ -83,12 +78,14 @@ public function testCanSetCurrentPageNumber() { $service = new Paginator(range(1, 50)); $service->setCurrentPage(2); + $this->assertSame(2, $service->currentPage()); } public function testSetCurrentPageNumberRequiresIntegerToBeGreaterThanNought() { $this->expectException(InvalidArgumentException::class); + $service = new Paginator(); $service->setCurrentPage(0); } @@ -96,16 +93,14 @@ public function testSetCurrentPageNumberRequiresIntegerToBeGreaterThanNought() public function testSetCurrentPageNumberRequiresIntegerToBeGreaterThanNought2() { $this->expectException(InvalidArgumentException::class); + $service = new Paginator(); $service->setCurrentPage(-1); } public function testSetCurrentPageNumberRequiresIntegerToBeLessThanTotalPages() { - $service = new Paginator( - range(1, 50), - 10 - ); + $service = new Paginator(range(1, 50), 10); $service->setCurrentPage(5); $this->assertSame(5, $service->currentPage()); @@ -117,11 +112,8 @@ public function testSetCurrentPageNumberRequiresIntegerToBeLessThanTotalPages() public function testCannotSetInvalidCurrentPageNumberInConstructor() { $this->expectException(InvalidArgumentException::class); - new Paginator( - range(1, 50), - 10, - currentPageNumber: 6 - ); + + new Paginator(range(1, 50), 10, currentPageNumber: 6); } public function testLastPageReturnsTheLastPageNumber() @@ -235,16 +227,13 @@ public function testNextNumberReturnsTheNextPageNumberWhenThereIsOne() public function testGetPageLinks() { - $this->assertSame( - [ - 1 => 'page-1.html', - 2 => 'page-2.html', - 3 => 'page-3.html', - 4 => 'page-4.html', - 5 => 'page-5.html', - ], - $this->makePaginator()->getPageLinks() - ); + $this->assertSame([ + 1 => 'page-1.html', + 2 => 'page-2.html', + 3 => 'page-3.html', + 4 => 'page-4.html', + 5 => 'page-5.html', + ], $this->makePaginator()->getPageLinks()); } public function testGetPageLinksWithBaseRoute() @@ -260,19 +249,18 @@ public function testGetPageLinksWithBaseRoute() } $paginator = new Paginator($pages, 2, paginationRouteBasename: 'pages'); - $this->assertSame( - [ - 1 => $pages[1]->getRoute(), - 2 => $pages[2]->getRoute(), - 3 => $pages[3]->getRoute(), - ], - $paginator->getPageLinks() - ); + + $this->assertSame([ + 1 => $pages[1]->getRoute(), + 2 => $pages[2]->getRoute(), + 3 => $pages[3]->getRoute(), + ], $paginator->getPageLinks()); } public function testFirstItemNumberOnPage() { $paginator = $this->makePaginator(); + $this->assertSame(1, $paginator->firstItemNumberOnPage()); $this->assertSame(11, $paginator->setCurrentPage(2)->firstItemNumberOnPage()); $this->assertSame(21, $paginator->setCurrentPage(3)->firstItemNumberOnPage()); @@ -280,6 +268,7 @@ public function testFirstItemNumberOnPage() $this->assertSame(41, $paginator->setCurrentPage(5)->firstItemNumberOnPage()); $paginator = $this->makePaginator(1, 100, 25); + $this->assertSame(1, $paginator->firstItemNumberOnPage()); $this->assertSame(26, $paginator->setCurrentPage(2)->firstItemNumberOnPage()); $this->assertSame(51, $paginator->setCurrentPage(3)->firstItemNumberOnPage()); From 39c29fb1bd89d45658dea5d1579efd111025d433 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:06:44 +0200 Subject: [PATCH 201/222] Add code newlines --- packages/framework/src/Support/Paginator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Support/Paginator.php b/packages/framework/src/Support/Paginator.php index 25692daa018..da2ec0d329c 100644 --- a/packages/framework/src/Support/Paginator.php +++ b/packages/framework/src/Support/Paginator.php @@ -77,7 +77,9 @@ public function getItemsForPage(): Collection public function getPageLinks(): array { $array = []; + $pageRange = range(1, $this->totalPages()); + if (isset($this->routeBasename)) { foreach ($pageRange as $number) { $array[$number] = Routes::get("$this->routeBasename/page-$number") ?? Hyde::formatLink("$this->routeBasename/page-$number"); From f1b5399df89b56cb81e7b354c1f6822a9d140739 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:08:09 +0200 Subject: [PATCH 202/222] Introduce type annotated variable --- packages/framework/src/Support/Paginator.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Support/Paginator.php b/packages/framework/src/Support/Paginator.php index da2ec0d329c..5fe84991747 100644 --- a/packages/framework/src/Support/Paginator.php +++ b/packages/framework/src/Support/Paginator.php @@ -71,7 +71,10 @@ public function getPaginatedItems(): Collection public function getItemsForPage(): Collection { - return $this->paginatedItems->get($this->currentPage - 1); + /** @var Collection $paginated */ + $paginated = $this->paginatedItems->get($this->currentPage - 1); + + return $paginated; } public function getPageLinks(): array From 8e10892e8f7161262036da17ee0856552c08a871 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:11:37 +0200 Subject: [PATCH 203/222] Add array generics to method annotation --- .../Concerns/Internal/ForwardsIlluminateFilesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php b/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php index fe6b98c0336..0a405873597 100644 --- a/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php +++ b/packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php @@ -59,7 +59,7 @@ * @method static bool isWritable(string $path) * @method static bool hasSameHash(string $firstFile, string $secondFile) * @method static bool isFile(string $file) - * @method static array glob(string $pattern, int $flags = 0) + * @method static array glob(string $pattern, int $flags = 0) * @method static SplFileInfo[] files(string $directory, bool $hidden = false) * @method static SplFileInfo[] allFiles(string $directory, bool $hidden = false) * @method static array directories(string $directory) From 8ce37cb13ddc7b94a5f82b6f642ed37beea68084 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:15:08 +0200 Subject: [PATCH 204/222] Refactor smart glob implementation --- packages/framework/src/Foundation/Kernel/Filesystem.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index 883663d3f31..a7adf98deaa 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -198,8 +198,9 @@ public function unlinkIfExists(string $path): bool /** @return \Illuminate\Support\Collection */ public function smartGlob(string $pattern, int $flags = 0): Collection { - return collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)) - ->map(fn (string $path): string => $this->pathToRelative($path)) - ->values(); + return collect(array_map( + fn (string $path): string => $this->pathToRelative($path), + \Hyde\Facades\Filesystem::glob($pattern, $flags) + )); } } From 6f1923b930663e5948501b8f0af0c77b9ace5010 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:16:35 +0200 Subject: [PATCH 205/222] Add null coalesce --- packages/framework/src/Foundation/Kernel/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index a7adf98deaa..decb5a0bca3 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -200,7 +200,7 @@ public function smartGlob(string $pattern, int $flags = 0): Collection { return collect(array_map( fn (string $path): string => $this->pathToRelative($path), - \Hyde\Facades\Filesystem::glob($pattern, $flags) + \Hyde\Facades\Filesystem::glob($pattern, $flags) ?? [] )); } } From 58c3775fa5eea03e9b3f51e7d4349a18b2812028 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:35:56 +0200 Subject: [PATCH 206/222] Change collection syntax --- packages/framework/src/Foundation/Kernel/Filesystem.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index decb5a0bca3..e89191687ac 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -16,7 +16,6 @@ use function array_map; use function is_string; use function is_array; -use function collect; use function str_starts_with; use function unslash; use function unlink; @@ -198,7 +197,7 @@ public function unlinkIfExists(string $path): bool /** @return \Illuminate\Support\Collection */ public function smartGlob(string $pattern, int $flags = 0): Collection { - return collect(array_map( + return new Collection(array_map( fn (string $path): string => $this->pathToRelative($path), \Hyde\Facades\Filesystem::glob($pattern, $flags) ?? [] )); From 83ffced02e9f8f0277bd4d6c5b553b7939cd2456 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:38:18 +0200 Subject: [PATCH 207/222] Introduce type annotated variable --- packages/framework/src/Foundation/Kernel/Filesystem.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index e89191687ac..363b8207ec4 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -197,9 +197,12 @@ public function unlinkIfExists(string $path): bool /** @return \Illuminate\Support\Collection */ public function smartGlob(string $pattern, int $flags = 0): Collection { - return new Collection(array_map( + /** @var \Illuminate\Support\Collection $collection */ + $collection = new Collection(array_map( fn (string $path): string => $this->pathToRelative($path), \Hyde\Facades\Filesystem::glob($pattern, $flags) ?? [] )); + + return $collection; } } From 87eaa59138a379b0f3df2ddfe2b6aa08e03ad512 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:42:18 +0200 Subject: [PATCH 208/222] Revert "Refactor smart glob implementation" This reverts commit 8ce37cb13ddc7b94a5f82b6f642ed37beea68084. --- packages/framework/src/Foundation/Kernel/Filesystem.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index 363b8207ec4..7bbad97fc16 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -198,10 +198,9 @@ public function unlinkIfExists(string $path): bool public function smartGlob(string $pattern, int $flags = 0): Collection { /** @var \Illuminate\Support\Collection $collection */ - $collection = new Collection(array_map( - fn (string $path): string => $this->pathToRelative($path), - \Hyde\Facades\Filesystem::glob($pattern, $flags) ?? [] - )); + $collection = collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)) + ->map(fn (string $path): string => $this->pathToRelative($path)) + ->values(); return $collection; } From 14b588f60f03aa5de4d57a56cf2b5bb696d56e18 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:43:05 +0200 Subject: [PATCH 209/222] Remove unnecessary values call We're not doing any filtering so we should not need to reset anything --- packages/framework/src/Foundation/Kernel/Filesystem.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index 7bbad97fc16..9a78bc243d4 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -199,8 +199,7 @@ public function smartGlob(string $pattern, int $flags = 0): Collection { /** @var \Illuminate\Support\Collection $collection */ $collection = collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)) - ->map(fn (string $path): string => $this->pathToRelative($path)) - ->values(); + ->map(fn (string $path): string => $this->pathToRelative($path)); return $collection; } From 6829426b69001257367ccdb2f3356e5615d3af78 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:45:31 +0200 Subject: [PATCH 210/222] Shift type annotation to base instance I think this will properly fix the Psalm type issue --- packages/framework/src/Foundation/Kernel/Filesystem.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index 9a78bc243d4..bd33996c8c0 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -198,9 +198,8 @@ public function unlinkIfExists(string $path): bool public function smartGlob(string $pattern, int $flags = 0): Collection { /** @var \Illuminate\Support\Collection $collection */ - $collection = collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)) - ->map(fn (string $path): string => $this->pathToRelative($path)); + $collection = collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)); - return $collection; + return $collection->map(fn (string $path): string => $this->pathToRelative($path)); } } From 2a5a9ea7420dfb0a9a375c9579980253cdf5e95e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:51:13 +0200 Subject: [PATCH 211/222] Rename local variable --- packages/framework/src/Foundation/Kernel/Filesystem.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index bd33996c8c0..97fa11bec30 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -197,9 +197,9 @@ public function unlinkIfExists(string $path): bool /** @return \Illuminate\Support\Collection */ public function smartGlob(string $pattern, int $flags = 0): Collection { - /** @var \Illuminate\Support\Collection $collection */ - $collection = collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)); + /** @var \Illuminate\Support\Collection $files */ + $files = collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)); - return $collection->map(fn (string $path): string => $this->pathToRelative($path)); + return $files->map(fn (string $path): string => $this->pathToRelative($path)); } } From 77e8127333c338b0a068664aebf3bd849f6c386b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 14:58:50 +0200 Subject: [PATCH 212/222] Remove old todo marker --- .../framework/src/Console/Commands/PublishHomepageCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/PublishHomepageCommand.php b/packages/framework/src/Console/Commands/PublishHomepageCommand.php index 50b7ddb9df6..6cec9d74f58 100644 --- a/packages/framework/src/Console/Commands/PublishHomepageCommand.php +++ b/packages/framework/src/Console/Commands/PublishHomepageCommand.php @@ -64,7 +64,7 @@ public function handle(): int Artisan::call('vendor:publish', [ '--tag' => $this->options[$selected]['group'] ?? $selected, - '--force' => true, // Todo add force state dynamically depending on existing file state + '--force' => true, ], ! $tagExists ? $this->output : null); if ($tagExists) { From 622072de39f19ead36010ce43640193eb4c53d49 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 15:00:45 +0200 Subject: [PATCH 213/222] Flip ternary expression operators --- .../framework/src/Console/Commands/PublishHomepageCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/PublishHomepageCommand.php b/packages/framework/src/Console/Commands/PublishHomepageCommand.php index 6cec9d74f58..04259c58fc4 100644 --- a/packages/framework/src/Console/Commands/PublishHomepageCommand.php +++ b/packages/framework/src/Console/Commands/PublishHomepageCommand.php @@ -65,7 +65,7 @@ public function handle(): int Artisan::call('vendor:publish', [ '--tag' => $this->options[$selected]['group'] ?? $selected, '--force' => true, - ], ! $tagExists ? $this->output : null); + ], $tagExists ? null : $this->output); if ($tagExists) { $this->infoComment("Published page [$selected]"); From 998c54d142f11984aabd3fd43b94aa763b8ab505 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 15:00:59 +0200 Subject: [PATCH 214/222] Comment code reasoning --- .../framework/src/Console/Commands/PublishHomepageCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/PublishHomepageCommand.php b/packages/framework/src/Console/Commands/PublishHomepageCommand.php index 04259c58fc4..61f49beb9c4 100644 --- a/packages/framework/src/Console/Commands/PublishHomepageCommand.php +++ b/packages/framework/src/Console/Commands/PublishHomepageCommand.php @@ -65,7 +65,7 @@ public function handle(): int Artisan::call('vendor:publish', [ '--tag' => $this->options[$selected]['group'] ?? $selected, '--force' => true, - ], $tagExists ? null : $this->output); + ], $tagExists ? null : $this->output); // If the tag doesn't exist, we pass the output to use the called command's error output. if ($tagExists) { $this->infoComment("Published page [$selected]"); From ebadfbf50c1852b13665fc028ce1565cb3bd4c50 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 15:08:54 +0200 Subject: [PATCH 215/222] Document why cache is not needed --- packages/framework/src/Framework/Services/ViewDiffService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Services/ViewDiffService.php b/packages/framework/src/Framework/Services/ViewDiffService.php index 1db349fd441..8edf7692cd7 100644 --- a/packages/framework/src/Framework/Services/ViewDiffService.php +++ b/packages/framework/src/Framework/Services/ViewDiffService.php @@ -18,6 +18,9 @@ * Helper methods to interact with the virtual filecache that is used to compare * published Blade views with the original Blade views in the Hyde Framework * so the user can be warned before overwriting their customizations. + * + * Since we currently never use this class more than one in the request cycle, + * there is no reason to cache the results of the file index in the instance. */ class ViewDiffService { From f3e3ee8114dab37825a5a7ff6d127272f4ebf1bc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 15:09:52 +0200 Subject: [PATCH 216/222] Call static methods statically --- .../tests/Feature/Services/ViewDiffServiceTest.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php b/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php index ae16dd1f3f6..e866db4aecf 100644 --- a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php +++ b/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php @@ -18,8 +18,7 @@ class ViewDiffServiceTest extends TestCase { public function testGetFilecache() { - $fileCacheService = new ViewDiffService(); - $fileCache = $fileCacheService->getViewFileHashIndex(); + $fileCache = ViewDiffService::getViewFileHashIndex(); $this->assertIsArray($fileCache); $this->assertArrayHasKey('resources/views/layouts/app.blade.php', $fileCache); @@ -29,8 +28,7 @@ public function testGetFilecache() public function testGetChecksums() { - $fileCacheService = new ViewDiffService(); - $checksums = $fileCacheService->getChecksums(); + $checksums = ViewDiffService::getChecksums(); $this->assertIsArray($checksums); $this->assertEquals(32, strlen($checksums[0])); @@ -38,17 +36,13 @@ public function testGetChecksums() public function testChecksumMatchesAny() { - $fileCacheService = new ViewDiffService(); - - $this->assertTrue($fileCacheService->checksumMatchesAny( + $this->assertTrue(ViewDiffService::checksumMatchesAny( unixsum_file(Hyde::vendorPath('resources/views/layouts/app.blade.php')) )); } public function testChecksumMatchesAnyFalse() { - $fileCacheService = new ViewDiffService(); - - $this->assertFalse($fileCacheService->checksumMatchesAny(unixsum('foo'))); + $this->assertFalse(ViewDiffService::checksumMatchesAny(unixsum('foo'))); } } From 755a0b6b207665046d2211071b7f1457e0537f8f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 15:10:15 +0200 Subject: [PATCH 217/222] Use assert same instead of assert equals --- .../framework/tests/Feature/Services/ViewDiffServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php b/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php index e866db4aecf..25f720b8b6f 100644 --- a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php +++ b/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php @@ -31,7 +31,7 @@ public function testGetChecksums() $checksums = ViewDiffService::getChecksums(); $this->assertIsArray($checksums); - $this->assertEquals(32, strlen($checksums[0])); + $this->assertSame(32, strlen($checksums[0])); } public function testChecksumMatchesAny() From f2dfab5d699886f44874b122e1d30672b93bade8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 15:12:27 +0200 Subject: [PATCH 218/222] Refactor test to use unit test case --- .../tests/Feature/Services/ViewDiffServiceTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php b/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php index 25f720b8b6f..6c556428f43 100644 --- a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php +++ b/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php @@ -4,9 +4,9 @@ namespace Hyde\Framework\Testing\Feature\Services; -use Hyde\Framework\Services\ViewDiffService; use Hyde\Hyde; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; +use Hyde\Framework\Services\ViewDiffService; use function Hyde\unixsum; use function Hyde\unixsum_file; @@ -14,8 +14,10 @@ /** * @covers \Hyde\Framework\Services\ViewDiffService */ -class ViewDiffServiceTest extends TestCase +class ViewDiffServiceTest extends UnitTestCase { + protected static bool $needsKernel = true; + public function testGetFilecache() { $fileCache = ViewDiffService::getViewFileHashIndex(); From d6d5a0e1a5322588314c4864e85d956db9526fc0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 15:12:46 +0200 Subject: [PATCH 219/222] Move test to unit namespace --- .../tests/{Feature/Services => Unit}/ViewDiffServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/framework/tests/{Feature/Services => Unit}/ViewDiffServiceTest.php (96%) diff --git a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php b/packages/framework/tests/Unit/ViewDiffServiceTest.php similarity index 96% rename from packages/framework/tests/Feature/Services/ViewDiffServiceTest.php rename to packages/framework/tests/Unit/ViewDiffServiceTest.php index 6c556428f43..fc0cbface66 100644 --- a/packages/framework/tests/Feature/Services/ViewDiffServiceTest.php +++ b/packages/framework/tests/Unit/ViewDiffServiceTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Feature\Services; +namespace Hyde\Framework\Testing\Unit; use Hyde\Hyde; use Hyde\Testing\UnitTestCase; From 3cb3c0ff353a787a1f62be3add79e2b1c2732669 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 16:02:58 +0200 Subject: [PATCH 220/222] Update link to be openable by PhpStorm --- monorepo/CodeIntelligence/CodeIntelligence.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monorepo/CodeIntelligence/CodeIntelligence.php b/monorepo/CodeIntelligence/CodeIntelligence.php index ffbff91f091..214b57096df 100644 --- a/monorepo/CodeIntelligence/CodeIntelligence.php +++ b/monorepo/CodeIntelligence/CodeIntelligence.php @@ -70,7 +70,7 @@ )); $this->line(); - $this->line('Dashboard page generated at '.OUTPUT_PATH.'/dashboard.html'); + $this->line('Dashboard page generated at file:///'.\Hyde\normalize_slashes(realpath(OUTPUT_PATH.'/dashboard.html'))); $this->line(); $this->info(sprintf('Time taken: %s. Memory used: %s', From cf2af145e9ea0178a1791086b09c5cc29240869e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 16:05:04 +0200 Subject: [PATCH 221/222] Clean up code --- monorepo/CodeIntelligence/CodeIntelligence.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/monorepo/CodeIntelligence/CodeIntelligence.php b/monorepo/CodeIntelligence/CodeIntelligence.php index 214b57096df..397ed662ac7 100644 --- a/monorepo/CodeIntelligence/CodeIntelligence.php +++ b/monorepo/CodeIntelligence/CodeIntelligence.php @@ -14,6 +14,8 @@ use Hyde\Foundation\HydeKernel; use Hyde\Markdown\Models\MarkdownDocument; +use function Hyde\normalize_slashes; + if (php_sapi_name() !== 'cli') { // Run the file and proxy the dashboard page for a live browser preview exec('php '.realpath(__FILE__).' 2>&1', $output, $returnCode); @@ -70,7 +72,7 @@ )); $this->line(); - $this->line('Dashboard page generated at file:///'.\Hyde\normalize_slashes(realpath(OUTPUT_PATH.'/dashboard.html'))); + $this->line(sprintf('Dashboard page generated at file:///%s', normalize_slashes(realpath(OUTPUT_PATH.'/dashboard.html')))); $this->line(); $this->info(sprintf('Time taken: %s. Memory used: %s', From 896e17c69fb5f821611d4002e891122f514184a3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 15 Apr 2024 16:12:34 +0200 Subject: [PATCH 222/222] Update outdated kernel access documentation --- docs/architecture-concepts/the-hydekernel.md | 2 +- packages/framework/src/Foundation/HydeKernel.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/architecture-concepts/the-hydekernel.md b/docs/architecture-concepts/the-hydekernel.md index 2f4e0d9b43f..1dcfa615456 100644 --- a/docs/architecture-concepts/the-hydekernel.md +++ b/docs/architecture-concepts/the-hydekernel.md @@ -41,7 +41,7 @@ app(HydeKernel::class)->version(); hyde()->version(); ``` -The Kernel instance is constructed in `bootstrap.php`, and is available globally as `$hyde`. +The Kernel instance is constructed and bound in the `app/bootstrap.php` file. ## The Kernel Lifecycle diff --git a/packages/framework/src/Foundation/HydeKernel.php b/packages/framework/src/Foundation/HydeKernel.php index 466a065bb85..1aa1ac0a43a 100644 --- a/packages/framework/src/Foundation/HydeKernel.php +++ b/packages/framework/src/Foundation/HydeKernel.php @@ -40,10 +40,9 @@ * The HydeKernel It is stored as a singleton in this class, and is bound into the * Laravel Application Service Container, and can be accessed in a few ways. * - * Commonly, you'll use the Hyde facade, but you can also use Dependency Injection + * Commonly, you'll use the Hyde facade to access it, but you can also use Dependency Injection * by type-hinting the HydeKernel::class, or use the hyde() function to get the Kernel. - * - * The Kernel instance is constructed in bootstrap.php, and is available globally as $hyde. + * The Kernel instance is constructed and bound in the app/bootstrap.php script. */ class HydeKernel implements SerializableContract {