From 5691b96027d45a16a5705e3860cdaee86bcbd48e Mon Sep 17 00:00:00 2001
From: github-actions
Date: Sat, 6 Jul 2024 14:10:24 +0000
Subject: [PATCH 01/28] Merge pull request #1791 from
hydephp/automatic-serialization-method
Update the `Serializable` trait to provide a default automatic `toArray` method https://github.com/hydephp/develop/commit/c2f9d5d396dd15c0dd1bb13b16d1778898e6aa84
---
src/Support/Concerns/Serializable.php | 9 +++++--
tests/Unit/SerializableTest.php | 35 +++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/Support/Concerns/Serializable.php b/src/Support/Concerns/Serializable.php
index f76c123f..e7992780 100644
--- a/src/Support/Concerns/Serializable.php
+++ b/src/Support/Concerns/Serializable.php
@@ -14,8 +14,13 @@
*/
trait Serializable
{
- /** @inheritDoc */
- abstract public function toArray(): array;
+ /** Default implementation to dynamically serialize all public properties. Can be overridden for increased control. */
+ public function toArray(): array
+ {
+ // Calling the function from a different scope means we only get the public properties.
+
+ return get_object_vars(...)->__invoke($this);
+ }
/** Recursively serialize Arrayables */
public function arraySerialize(): array
diff --git a/tests/Unit/SerializableTest.php b/tests/Unit/SerializableTest.php
index fde100a2..021f6a4a 100644
--- a/tests/Unit/SerializableTest.php
+++ b/tests/Unit/SerializableTest.php
@@ -53,6 +53,15 @@ public function testToJsonWithArrayable()
{
$this->assertSame('{"foo":"bar","arrayable":{"foo":"bar"}}', (new SerializableTestClassWithArrayable)->toJson());
}
+
+ public function testAutomaticallySerialization()
+ {
+ $this->assertSame([
+ 'foo' => 'foo',
+ 'bar' => 'bar',
+ 'baz' => ['baz' => 'baz'],
+ ], (new AutomaticallySerializableTestClass)->toArray());
+ }
}
class SerializableTestClass implements SerializableContract
@@ -82,3 +91,29 @@ public function toArray(): array
return ['foo' => 'bar'];
}
}
+
+class AutomaticallySerializableTestClass implements SerializableContract
+{
+ use Serializable;
+
+ public string $foo;
+ public string $bar;
+ public array $baz;
+
+ public string $uninitialized;
+
+ protected string $hidden;
+ private string $private;
+
+ public static string $static;
+
+ public function __construct()
+ {
+ $this->foo = 'foo';
+ $this->bar = 'bar';
+ $this->baz = ['baz' => 'baz'];
+ $this->hidden = 'hidden';
+ $this->private = 'private';
+ static::$static = 'static';
+ }
+}
From e1da1845f0f9bc96fffedfa2ea8e1e16b189a049 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Sat, 6 Jul 2024 14:18:10 +0000
Subject: [PATCH 02/28] Merge pull request #1793 from
hydephp/automatic-serialization-method
Extract helper method for automatic serialization https://github.com/hydephp/develop/commit/d2c74bf7d33c7f7d5868df9f5327688942d9796b
---
src/Support/Concerns/Serializable.php | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/Support/Concerns/Serializable.php b/src/Support/Concerns/Serializable.php
index e7992780..9fc66cb7 100644
--- a/src/Support/Concerns/Serializable.php
+++ b/src/Support/Concerns/Serializable.php
@@ -17,9 +17,7 @@ trait Serializable
/** Default implementation to dynamically serialize all public properties. Can be overridden for increased control. */
public function toArray(): array
{
- // Calling the function from a different scope means we only get the public properties.
-
- return get_object_vars(...)->__invoke($this);
+ return $this->automaticallySerialize();
}
/** Recursively serialize Arrayables */
@@ -39,4 +37,12 @@ public function toJson($options = 0): string
{
return json_encode($this->jsonSerialize(), $options);
}
+
+ /** Automatically serialize all public properties. */
+ protected function automaticallySerialize(): array
+ {
+ // Calling the function from a different scope means we only get the public properties.
+
+ return get_object_vars(...)->__invoke($this);
+ }
}
From 8e47c9ff0b2a5e714938f38895735010372f1b40 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Sat, 6 Jul 2024 18:44:06 +0000
Subject: [PATCH 03/28] Merge pull request #1794 from
hydephp/prepare-post-author-changes
[1.x] Update the post author class to prepare for the v2 overhaul https://github.com/hydephp/develop/commit/cc57e00e84a03953ed5fb881307aadfbab14b284
---
.../Features/Blogging/Models/PostAuthor.php | 13 +++++++++----
tests/Feature/MarkdownPostTest.php | 2 +-
tests/Unit/PostAuthorTest.php | 7 +++++++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/Framework/Features/Blogging/Models/PostAuthor.php b/src/Framework/Features/Blogging/Models/PostAuthor.php
index ac6b850b..35236438 100644
--- a/src/Framework/Features/Blogging/Models/PostAuthor.php
+++ b/src/Framework/Features/Blogging/Models/PostAuthor.php
@@ -8,6 +8,7 @@
use Hyde\Facades\Author;
use Hyde\Facades\Config;
use Illuminate\Support\Collection;
+use JetBrains\PhpStorm\Deprecated;
use function strtolower;
use function is_string;
@@ -26,7 +27,7 @@ class PostAuthor implements Stringable
/**
* The display name of the author.
*/
- public readonly ?string $name;
+ public readonly string $name;
/**
* The author's website URL.
@@ -48,7 +49,7 @@ class PostAuthor implements Stringable
public function __construct(string $username, ?string $name = null, ?string $website = null)
{
$this->username = $username;
- $this->name = $name;
+ $this->name = $name ?? $this->username;
$this->website = $website;
}
@@ -82,12 +83,16 @@ public static function all(): Collection
public function __toString(): string
{
- return $this->getName();
+ return $this->name;
}
+ /**
+ * @deprecated This is not needed as the name property can be accessed directly.
+ */
+ #[Deprecated(reason: 'Use the name property instead.', replacement: '%class%->name')]
public function getName(): string
{
- return $this->name ?? $this->username;
+ return $this->name;
}
/** @param array{username?: string, name?: string, website?: string} $data */
diff --git a/tests/Feature/MarkdownPostTest.php b/tests/Feature/MarkdownPostTest.php
index ef8c319d..f3f3b315 100644
--- a/tests/Feature/MarkdownPostTest.php
+++ b/tests/Feature/MarkdownPostTest.php
@@ -29,7 +29,7 @@ public function testConstructorCanCreateANewAuthorInstanceFromUsernameString()
$this->assertInstanceOf(PostAuthor::class, $post->author);
$this->assertSame('John Doe', $post->author->username);
- $this->assertNull($post->author->name);
+ $this->assertSame('John Doe', $post->author->name);
$this->assertNull($post->author->website);
}
diff --git a/tests/Unit/PostAuthorTest.php b/tests/Unit/PostAuthorTest.php
index c6c98a9c..503c59f5 100644
--- a/tests/Unit/PostAuthorTest.php
+++ b/tests/Unit/PostAuthorTest.php
@@ -134,6 +134,13 @@ public function testGetNameHelperReturnsUsernameIfNameIsNotSet()
$this->assertEquals('username', $author->getName());
}
+ public function testNameIsSetToUsernameIfNameIsNotSet()
+ {
+ $author = new PostAuthor('username');
+
+ $this->assertEquals('username', $author->name);
+ }
+
public function testToStringHelperReturnsTheName()
{
$author = new PostAuthor('username', 'John Doe');
From 3946c113e9e8d28560577f85c226c06d3f098d45 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Sat, 6 Jul 2024 18:48:35 +0000
Subject: [PATCH 04/28] Merge pull request #1795 from
hydephp/prepare-post-author-changes
Internal: Replace deprecated method usage https://github.com/hydephp/develop/commit/00fef196328658f2349a82961222f4ff24bb94ca
---
src/Framework/Features/XmlGenerators/RssFeedGenerator.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/src/Framework/Features/XmlGenerators/RssFeedGenerator.php
index 09ebc3db..b3abfab4 100644
--- a/src/Framework/Features/XmlGenerators/RssFeedGenerator.php
+++ b/src/Framework/Features/XmlGenerators/RssFeedGenerator.php
@@ -69,7 +69,7 @@ protected function addDynamicItemData(SimpleXMLElement $item, MarkdownPost $post
}
if (isset($post->author)) {
- $item->addChild('dc:creator', $post->author->getName(), 'http://purl.org/dc/elements/1.1/');
+ $item->addChild('dc:creator', $post->author->name, 'http://purl.org/dc/elements/1.1/');
}
if (isset($post->category)) {
From ec62f59667cc3a614f36b6d8e66c600c0e10cefe Mon Sep 17 00:00:00 2001
From: github-actions
Date: Sun, 7 Jul 2024 09:05:53 +0000
Subject: [PATCH 05/28] Merge pull request #1796 from
hydephp/improve-static-analysis
Internal: Improve test static analysis and improve tests https://github.com/hydephp/develop/commit/254bbe7254c98d4ef61006aedd37bc29a5feff22
---
.../Markdown/ShortcodeProcessorTest.php | 15 ++---
tests/Feature/Services/RssFeedServiceTest.php | 2 +-
tests/Feature/Support/ProjectFileTest.php | 6 +-
.../HyperlinkFileHelperRelativeLinkTest.php | 58 +++++++++----------
.../HyperlinkFormatHtmlPathTest.php | 28 ++++-----
tests/Unit/Pages/HtmlPageTest.php | 2 +-
tests/Unit/Pages/MarkdownPageTest.php | 5 +-
tests/Unit/Pages/MarkdownPostParserTest.php | 34 +++++------
tests/Unit/PostAuthorTest.php | 20 +++----
tests/Unit/Views/LinkComponentViewTest.php | 19 ++++--
10 files changed, 99 insertions(+), 90 deletions(-)
diff --git a/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php b/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php
index 195da02b..12660727 100644
--- a/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php
+++ b/tests/Feature/Services/Markdown/ShortcodeProcessorTest.php
@@ -25,21 +25,22 @@ public function testDiscoveredShortcodesAreUsedToProcessInput()
{
$processor = new ShortcodeProcessor('>info foo');
- $this->assertEquals('foo
',
- $processor->run());
+ $this->assertSame('foo
', $processor->run());
}
public function testStringWithoutShortcodeIsNotModified()
{
$processor = new ShortcodeProcessor('foo');
- $this->assertEquals('foo', $processor->run());
+ $this->assertSame('foo', $processor->run());
}
public function testProcessStaticShorthand()
{
- $this->assertEquals('foo
',
- ShortcodeProcessor::preprocess('>info foo'));
+ $this->assertSame(
+ 'foo
',
+ ShortcodeProcessor::preprocess('>info foo')
+ );
}
public function testShortcodesCanBeAddedToProcessor()
@@ -60,7 +61,7 @@ public static function resolve(string $input): string
});
$this->assertArrayHasKey('foo', $processor->getShortcodes());
- $this->assertEquals('bar', $processor->run());
+ $this->assertSame('bar', $processor->run());
}
public function testShortcodesCanBeAddedToProcessorUsingArray()
@@ -81,6 +82,6 @@ public static function resolve(string $input): string
}]);
$this->assertArrayHasKey('foo', $processor->getShortcodes());
- $this->assertEquals('bar', $processor->run());
+ $this->assertSame('bar', $processor->run());
}
}
diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php
index 832f9d2f..3dec761d 100644
--- a/tests/Feature/Services/RssFeedServiceTest.php
+++ b/tests/Feature/Services/RssFeedServiceTest.php
@@ -28,7 +28,7 @@ public function testServiceInstantiatesXmlElement()
public function testXmlRootElementIsSetToRss20()
{
$service = new RssFeedGenerator();
- $this->assertEquals('rss', $service->getXmlElement()->getName());
+ $this->assertSame('rss', $service->getXmlElement()->getName());
$this->assertEquals('2.0', $service->getXmlElement()->attributes()->version);
}
diff --git a/tests/Feature/Support/ProjectFileTest.php b/tests/Feature/Support/ProjectFileTest.php
index a33c0b73..892ae7ff 100644
--- a/tests/Feature/Support/ProjectFileTest.php
+++ b/tests/Feature/Support/ProjectFileTest.php
@@ -21,19 +21,19 @@ public function testCanConstruct()
$this->assertSame('foo', $file->path);
}
- public function can_make()
+ public function testCanMake()
{
$this->assertEquals(new ProjectFileTestClass('foo'), ProjectFileTestClass::make('foo'));
}
public function testCanConstructWithNestedPaths()
{
- $this->assertEquals('path/to/file.txt', ProjectFileTestClass::make('path/to/file.txt')->path);
+ $this->assertSame('path/to/file.txt', ProjectFileTestClass::make('path/to/file.txt')->path);
}
public function testAbsolutePathIsNormalizedToRelative()
{
- $this->assertEquals('foo', ProjectFileTestClass::make(Hyde::path('foo'))->path);
+ $this->assertSame('foo', ProjectFileTestClass::make(Hyde::path('foo'))->path);
}
public function testGetNameReturnsNameOfFile()
diff --git a/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php b/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php
index 869cd190..4aa4af46 100644
--- a/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php
+++ b/tests/Unit/Foundation/HyperlinkFileHelperRelativeLinkTest.php
@@ -29,126 +29,126 @@ protected function setUp(): void
public function testHelperReturnsStringAsIsIfCurrentIsNotSet()
{
- $this->assertEquals('foo/bar.html', Hyde::relativeLink('foo/bar.html'));
+ $this->assertSame('foo/bar.html', Hyde::relativeLink('foo/bar.html'));
}
public function testHelperInjectsProperNumberOfDoublesSlash()
{
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../foo.html', Hyde::relativeLink('foo.html'));
+ $this->assertSame('../foo.html', Hyde::relativeLink('foo.html'));
}
public function testHelperInjectsProperNumberOfDoublesSlashForDeeplyNestedPaths()
{
$this->mockCurrentPage('foo/bar/baz/qux.html');
- $this->assertEquals('../../../foo.html', Hyde::relativeLink('foo.html'));
+ $this->assertSame('../../../foo.html', Hyde::relativeLink('foo.html'));
}
public function testHelperHandlesDestinationWithoutFileExtension()
{
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../foo', Hyde::relativeLink('foo'));
+ $this->assertSame('../foo', Hyde::relativeLink('foo'));
}
public function testHelperHandlesCurrentWithoutFileExtension()
{
$this->mockCurrentPage('foo/bar');
- $this->assertEquals('../foo.html', Hyde::relativeLink('foo.html'));
+ $this->assertSame('../foo.html', Hyde::relativeLink('foo.html'));
}
public function testHelperHandlesCaseWithoutAnyFileExtensions()
{
$this->mockCurrentPage('foo/bar');
- $this->assertEquals('../foo', Hyde::relativeLink('foo'));
+ $this->assertSame('../foo', Hyde::relativeLink('foo'));
}
public function testHelperHandlesCaseWithMixedFileExtensions()
{
$this->mockCurrentPage('foo/bar.md');
- $this->assertEquals('../foo.md', Hyde::relativeLink('foo.md'));
+ $this->assertSame('../foo.md', Hyde::relativeLink('foo.md'));
$this->mockCurrentPage('foo/bar.txt');
- $this->assertEquals('../foo.txt', Hyde::relativeLink('foo.txt'));
+ $this->assertSame('../foo.txt', Hyde::relativeLink('foo.txt'));
}
public function testHelperHandlesDifferentFileExtensions()
{
$this->mockCurrentPage('foo/bar');
- $this->assertEquals('../foo.png', Hyde::relativeLink('foo.png'));
- $this->assertEquals('../foo.css', Hyde::relativeLink('foo.css'));
- $this->assertEquals('../foo.js', Hyde::relativeLink('foo.js'));
+ $this->assertSame('../foo.png', Hyde::relativeLink('foo.png'));
+ $this->assertSame('../foo.css', Hyde::relativeLink('foo.css'));
+ $this->assertSame('../foo.js', Hyde::relativeLink('foo.js'));
}
public function testHelperReturnsPrettyUrlIfEnabledAndDestinationIsAHtmlFile()
{
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../foo', Hyde::relativeLink('foo.html'));
+ $this->assertSame('../foo', Hyde::relativeLink('foo.html'));
}
public function testHelperMethodDoesNotRequireCurrentPathToBeHtmlToUsePrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo/bar');
- $this->assertEquals('../foo', Hyde::relativeLink('foo.html'));
+ $this->assertSame('../foo', Hyde::relativeLink('foo.html'));
}
public function testHelperReturnsDoesNotReturnPrettyUrlIfWhenEnabledButAndDestinationIsNotAHtmlFile()
{
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../foo.png', Hyde::relativeLink('foo.png'));
+ $this->assertSame('../foo.png', Hyde::relativeLink('foo.png'));
}
public function testHelperRewritesIndexWhenUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo.html');
- $this->assertEquals('./', Hyde::relativeLink('index.html'));
+ $this->assertSame('./', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../', Hyde::relativeLink('index.html'));
+ $this->assertSame('../', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar/baz.html');
- $this->assertEquals('../../', Hyde::relativeLink('index.html'));
+ $this->assertSame('../../', Hyde::relativeLink('index.html'));
}
public function testHelperDoesNotRewriteIndexWhenNotUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
$this->mockCurrentPage('foo.html');
- $this->assertEquals('index.html', Hyde::relativeLink('index.html'));
+ $this->assertSame('index.html', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../index.html', Hyde::relativeLink('index.html'));
+ $this->assertSame('../index.html', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar/baz.html');
- $this->assertEquals('../../index.html', Hyde::relativeLink('index.html'));
+ $this->assertSame('../../index.html', Hyde::relativeLink('index.html'));
}
public function testHelperRewritesDocumentationPageIndexWhenUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo.html');
- $this->assertEquals('docs/', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('docs/', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('docs.html');
- $this->assertEquals('docs/', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('docs/', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('../docs/', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('docs/foo.html');
- $this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('../docs/', Hyde::relativeLink('docs/index.html'));
}
public function testHelperDoesNotRewriteDocumentationPageIndexWhenNotUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
$this->mockCurrentPage('foo.html');
- $this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('docs/index.html', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('docs.html');
- $this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('docs/index.html', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('foo/bar.html');
- $this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('../docs/index.html', Hyde::relativeLink('docs/index.html'));
$this->mockCurrentPage('docs/foo.html');
- $this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html'));
+ $this->assertSame('../docs/index.html', Hyde::relativeLink('docs/index.html'));
}
public function testHelperDoesNotRewriteAlreadyProcessedLinks()
{
- $this->assertEquals('../foo', Hyde::relativeLink('../foo'));
+ $this->assertSame('../foo', Hyde::relativeLink('../foo'));
}
}
diff --git a/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php b/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php
index b92c4b13..3151a977 100644
--- a/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php
+++ b/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php
@@ -19,85 +19,85 @@ public function testHelperReturnsStringAsIsIfPrettyUrlsIsNotTrue()
{
self::mockConfig(['hyde.pretty_urls' => false]);
- $this->assertEquals('foo/bar.html', Hyde::formatLink('foo/bar.html'));
+ $this->assertSame('foo/bar.html', Hyde::formatLink('foo/bar.html'));
}
public function testHelperReturnsPrettyUrlIfPrettyUrlsIsTrue()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('foo/bar', Hyde::formatLink('foo/bar.html'));
+ $this->assertSame('foo/bar', Hyde::formatLink('foo/bar.html'));
}
public function testHelperRespectsAbsoluteUrls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
- $this->assertEquals('/foo/bar.html', Hyde::formatLink('/foo/bar.html'));
+ $this->assertSame('/foo/bar.html', Hyde::formatLink('/foo/bar.html'));
}
public function testHelperRespectsPrettyAbsoluteUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('/foo/bar', Hyde::formatLink('/foo/bar.html'));
+ $this->assertSame('/foo/bar', Hyde::formatLink('/foo/bar.html'));
}
public function testHelperRespectsRelativeUrls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
- $this->assertEquals('../foo/bar.html', Hyde::formatLink('../foo/bar.html'));
+ $this->assertSame('../foo/bar.html', Hyde::formatLink('../foo/bar.html'));
}
public function testHelperRespectsPrettyRelativeUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('../foo/bar', Hyde::formatLink('../foo/bar.html'));
+ $this->assertSame('../foo/bar', Hyde::formatLink('../foo/bar.html'));
}
public function testNonHtmlLinksAreNotModified()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg'));
+ $this->assertSame('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg'));
}
public function testHelperRespectsAbsoluteUrlsWithPrettyUrlsEnabled()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg'));
+ $this->assertSame('/foo/bar.jpg', Hyde::formatLink('/foo/bar.jpg'));
}
public function testHelperRewritesIndexWhenUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('/', Hyde::formatLink('index.html'));
+ $this->assertSame('/', Hyde::formatLink('index.html'));
}
public function testHelperDoesNotRewriteIndexWhenNotUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
- $this->assertEquals('index.html', Hyde::formatLink('index.html'));
+ $this->assertSame('index.html', Hyde::formatLink('index.html'));
}
public function testHelperRewritesDocumentationPageIndexWhenUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('docs/', Hyde::formatLink('docs/index.html'));
+ $this->assertSame('docs/', Hyde::formatLink('docs/index.html'));
}
public function testHelperDoesNotRewriteDocumentationPageIndexWhenNotUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
- $this->assertEquals('docs/index.html', Hyde::formatLink('docs/index.html'));
+ $this->assertSame('docs/index.html', Hyde::formatLink('docs/index.html'));
}
public function testHelpersRewritesArbitraryNestedIndexPagesWhenUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
- $this->assertEquals('foo/bar/', Hyde::formatLink('foo/bar/index.html'));
+ $this->assertSame('foo/bar/', Hyde::formatLink('foo/bar/index.html'));
}
public function testHelpersDoesNotRewriteArbitraryNestedIndexPagesWhenNotUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
- $this->assertEquals('foo/bar/index.html', Hyde::formatLink('foo/bar/index.html'));
+ $this->assertSame('foo/bar/index.html', Hyde::formatLink('foo/bar/index.html'));
}
}
diff --git a/tests/Unit/Pages/HtmlPageTest.php b/tests/Unit/Pages/HtmlPageTest.php
index 1551b7d2..f976cb44 100644
--- a/tests/Unit/Pages/HtmlPageTest.php
+++ b/tests/Unit/Pages/HtmlPageTest.php
@@ -18,7 +18,7 @@ public function testHtmlPageCanBeCompiled()
$page = new HtmlPage('foo');
- $this->assertEquals('bar', $page->compile());
+ $this->assertSame('bar', $page->compile());
}
public function testCompileMethodUsesContents()
diff --git a/tests/Unit/Pages/MarkdownPageTest.php b/tests/Unit/Pages/MarkdownPageTest.php
index 712ccdb8..ba28e199 100644
--- a/tests/Unit/Pages/MarkdownPageTest.php
+++ b/tests/Unit/Pages/MarkdownPageTest.php
@@ -27,9 +27,10 @@ public function testCreatedModelContainsExpectedData()
$this->file('_pages/test-page.md', "# Test Page \n Hello World!");
$page = MarkdownPage::parse('test-page');
- $this->assertEquals('Test Page', $page->title);
+ $this->assertSame('Test Page', $page->title);
+ $this->assertSame('test-page', $page->identifier);
+ $this->assertSame("# Test Page \n Hello World!", $page->markdown->body());
$this->assertEquals("# Test Page \n Hello World!", $page->markdown);
- $this->assertEquals('test-page', $page->identifier);
}
public function testCanRenderMarkdownPage()
diff --git a/tests/Unit/Pages/MarkdownPostParserTest.php b/tests/Unit/Pages/MarkdownPostParserTest.php
index c6b0d4f7..8c933156 100644
--- a/tests/Unit/Pages/MarkdownPostParserTest.php
+++ b/tests/Unit/Pages/MarkdownPostParserTest.php
@@ -4,12 +4,11 @@
namespace Hyde\Framework\Testing\Unit\Pages;
-use Hyde\Facades\Filesystem;
-use Hyde\Hyde;
use Hyde\Markdown\Models\FrontMatter;
use Hyde\Markdown\Models\Markdown;
use Hyde\Pages\MarkdownPost;
use Hyde\Testing\TestCase;
+use Hyde\Framework\Features\Blogging\Models\PostAuthor;
/**
* @see \Hyde\Framework\Testing\Feature\StaticSiteBuilderPostModuleTest for the compiler test.
@@ -20,28 +19,25 @@ protected function setUp(): void
{
parent::setUp();
- file_put_contents(Hyde::path('_posts/test-post.md'), '---
-title: My New Post
-category: blog
-author: Mr. Hyde
----
+ $this->file('_posts/test-post.md', <<<'MD'
+ ---
+ title: My New Post
+ category: blog
+ author: Mr. Hyde
+ ---
-# My New Post
+ # My New Post
-This is a post stub used in the automated tests
-');
- }
-
- protected function tearDown(): void
- {
- Filesystem::unlink('_posts/test-post.md');
+ This is a post stub used in the automated tests
- parent::tearDown();
+ MD
+ );
}
public function testCanParseMarkdownFile()
{
$post = MarkdownPost::parse('test-post');
+
$this->assertInstanceOf(MarkdownPost::class, $post);
$this->assertCount(3, $post->matter->toArray());
$this->assertInstanceOf(FrontMatter::class, $post->matter);
@@ -55,8 +51,10 @@ public function testCanParseMarkdownFile()
public function testParsedMarkdownPostContainsValidFrontMatter()
{
$post = MarkdownPost::parse('test-post');
- $this->assertEquals('My New Post', $post->data('title'));
+
+ $this->assertSame('My New Post', $post->data('title'));
+ $this->assertSame('blog', $post->data('category'));
$this->assertEquals('Mr. Hyde', $post->data('author'));
- $this->assertEquals('blog', $post->data('category'));
+ $this->assertInstanceOf(PostAuthor::class, $post->data('author'));
}
}
diff --git a/tests/Unit/PostAuthorTest.php b/tests/Unit/PostAuthorTest.php
index 503c59f5..4544ff6c 100644
--- a/tests/Unit/PostAuthorTest.php
+++ b/tests/Unit/PostAuthorTest.php
@@ -29,9 +29,9 @@ public function testCreateMethodAcceptsAllParameters()
{
$author = Author::create('foo', 'bar', 'https://example.com');
- $this->assertEquals('foo', $author->username);
- $this->assertEquals('bar', $author->name);
- $this->assertEquals('https://example.com', $author->website);
+ $this->assertSame('foo', $author->username);
+ $this->assertSame('bar', $author->name);
+ $this->assertSame('https://example.com', $author->website);
}
public function testGetOrCreateMethodCreatesNewAuthorModelFromString()
@@ -107,8 +107,8 @@ public function testGetMethodReturnsConfigDefinedAuthorByUsername()
$author = PostAuthor::get('foo');
$this->assertInstanceOf(PostAuthor::class, $author);
- $this->assertEquals('foo', $author->username);
- $this->assertEquals('bar', $author->name);
+ $this->assertSame('foo', $author->username);
+ $this->assertSame('bar', $author->name);
}
public function testGetMethodReturnsNewAuthorIfUsernameNotFoundInConfig()
@@ -117,34 +117,34 @@ public function testGetMethodReturnsNewAuthorIfUsernameNotFoundInConfig()
$author = PostAuthor::get('foo');
$this->assertInstanceOf(PostAuthor::class, $author);
- $this->assertEquals('foo', $author->username);
+ $this->assertSame('foo', $author->username);
}
public function testGetNameHelperReturnsNameIfSet()
{
$author = new PostAuthor('username', 'John Doe');
- $this->assertEquals('John Doe', $author->getName());
+ $this->assertSame('John Doe', $author->getName());
}
public function testGetNameHelperReturnsUsernameIfNameIsNotSet()
{
$author = new PostAuthor('username');
- $this->assertEquals('username', $author->getName());
+ $this->assertSame('username', $author->getName());
}
public function testNameIsSetToUsernameIfNameIsNotSet()
{
$author = new PostAuthor('username');
- $this->assertEquals('username', $author->name);
+ $this->assertSame('username', $author->name);
}
public function testToStringHelperReturnsTheName()
{
$author = new PostAuthor('username', 'John Doe');
- $this->assertEquals('John Doe', (string) $author);
+ $this->assertSame('John Doe', (string) $author);
}
}
diff --git a/tests/Unit/Views/LinkComponentViewTest.php b/tests/Unit/Views/LinkComponentViewTest.php
index 5fef3bb8..7d8839ac 100644
--- a/tests/Unit/Views/LinkComponentViewTest.php
+++ b/tests/Unit/Views/LinkComponentViewTest.php
@@ -16,21 +16,30 @@ class LinkComponentViewTest extends TestCase
{
public function testLinkComponentCanBeRendered()
{
- $this->assertEquals('bar ', rtrim(Blade::render('bar ')));
+ $this->assertSame(
+ 'bar ',
+ rtrim(Blade::render('bar '))
+ );
}
public function testLinkComponentCanBeRenderedWithRoute()
{
$route = Routes::get('index');
- $this->assertEquals('bar ', rtrim(
- Blade::render('bar ')));
+
+ $this->assertSame(
+ 'bar ',
+ rtrim(Blade::render('bar '))
+ );
}
public function testLinkComponentCanBeRenderedWithRouteForNestedPages()
{
Render::share('routeKey', 'foo/bar');
$route = Routes::get('index');
- $this->assertEquals('bar ', rtrim(
- Blade::render('bar ')));
+
+ $this->assertSame(
+ 'bar ',
+ rtrim(Blade::render('bar '))
+ );
}
}
From 7a0671565b6443a6f3d003add9fbf36734479c3b Mon Sep 17 00:00:00 2001
From: github-actions
Date: Mon, 8 Jul 2024 18:25:15 +0000
Subject: [PATCH 06/28] Merge pull request #1808 from
hydephp/update-testing-helpers
Internal: Improve testing helpers https://github.com/hydephp/develop/commit/faeaf9faad03f0067f4fc80ae46d2cc4204d8903
---
tests/Feature/BladeMatterParserTest.php | 8 ++--
tests/Feature/NavigationDataTest.php | 12 +++++-
tests/Feature/TypedConfigFacadeTest.php | 8 +++-
.../Feature/YamlConfigurationFeatureTest.php | 6 +--
tests/Unit/ServeCommandOptionsUnitTest.php | 2 +-
tests/Unit/TestingSupportHelpersMetaTest.php | 40 +++++++++++++++++++
6 files changed, 67 insertions(+), 9 deletions(-)
diff --git a/tests/Feature/BladeMatterParserTest.php b/tests/Feature/BladeMatterParserTest.php
index c7c07ca8..eac6d4a7 100644
--- a/tests/Feature/BladeMatterParserTest.php
+++ b/tests/Feature/BladeMatterParserTest.php
@@ -103,15 +103,17 @@ public function testGetValueWithType()
{
$this->assertSame('string', ParserTestClass::getValueWithType('string'));
$this->assertSame('string', ParserTestClass::getValueWithType('string'));
- $this->assertSame(true, ParserTestClass::getValueWithType('true'));
- $this->assertSame(false, ParserTestClass::getValueWithType('false'));
+
$this->assertSame(1, ParserTestClass::getValueWithType('1'));
$this->assertSame(0, ParserTestClass::getValueWithType('0'));
$this->assertSame(1.0, ParserTestClass::getValueWithType('1.0'));
$this->assertSame(0.0, ParserTestClass::getValueWithType('0.0'));
- $this->assertSame(null, ParserTestClass::getValueWithType('null'));
$this->assertSame(['foo' => 'bar'], ParserTestClass::getValueWithType('["foo" => "bar"]'));
$this->assertSame(['foo' => 'bar'], ParserTestClass::getValueWithType("['foo' => 'bar']"));
+
+ $this->assertTrue(ParserTestClass::getValueWithType('true'));
+ $this->assertFalse(ParserTestClass::getValueWithType('false'));
+ $this->assertNull(ParserTestClass::getValueWithType('null'));
}
public function testParseArrayString()
diff --git a/tests/Feature/NavigationDataTest.php b/tests/Feature/NavigationDataTest.php
index 1eaf47f6..de433810 100644
--- a/tests/Feature/NavigationDataTest.php
+++ b/tests/Feature/NavigationDataTest.php
@@ -35,8 +35,18 @@ public function testConstruct()
$this->assertSame('label', $navigationData->label);
$this->assertSame('group', $navigationData->group);
- $this->assertSame(true, $navigationData->hidden);
$this->assertSame(1, $navigationData->priority);
+ $this->assertTrue($navigationData->hidden);
+ }
+
+ public function testConstructWithDifferentData()
+ {
+ $navigationData = new NavigationData('label', 2, false);
+
+ $this->assertSame('label', $navigationData->label);
+ $this->assertSame(2, $navigationData->priority);
+ $this->assertFalse($navigationData->hidden);
+ $this->assertNull($navigationData->group);
}
public function testMake()
diff --git a/tests/Feature/TypedConfigFacadeTest.php b/tests/Feature/TypedConfigFacadeTest.php
index b313dc2d..dd5af604 100644
--- a/tests/Feature/TypedConfigFacadeTest.php
+++ b/tests/Feature/TypedConfigFacadeTest.php
@@ -30,6 +30,9 @@ public function testGetBool()
{
config(['foo' => true]);
$this->assertIsBool(Config::getBool('foo'));
+
+ config(['foo' => false]);
+ $this->assertIsBool(Config::getBool('foo'));
}
public function testGetInt()
@@ -56,7 +59,8 @@ public function testGetStringWithDefaultValue()
public function testGetBoolWithDefaultValue()
{
- $this->assertSame(true, Config::getBool('foo', true));
+ $this->assertTrue(Config::getBool('foo', true));
+ $this->assertFalse(Config::getBool('foo', false));
}
public function testGetIntWithDefaultValue()
@@ -82,6 +86,7 @@ public function testGetStringWithStrictMode()
public function testGetBoolWithStrictMode()
{
$this->runUnitTest(true, true, Config::getBool(...));
+ $this->runUnitTest(false, false, Config::getBool(...));
}
public function testGetIntWithStrictMode()
@@ -137,6 +142,7 @@ public function testGetStringWithString()
public function testGetBoolWithBool()
{
$this->runUnitTest(true, true, Config::getBool(...));
+ $this->runUnitTest(false, false, Config::getBool(...));
}
public function testGetIntWithInt()
diff --git a/tests/Feature/YamlConfigurationFeatureTest.php b/tests/Feature/YamlConfigurationFeatureTest.php
index 41362764..872c8ffb 100644
--- a/tests/Feature/YamlConfigurationFeatureTest.php
+++ b/tests/Feature/YamlConfigurationFeatureTest.php
@@ -43,13 +43,13 @@ public function testCanDefineHydeConfigSettingsInHydeYmlFile()
$this->assertSame('Test', config('hyde.name'));
$this->assertSame('http://localhost', config('hyde.url'));
- $this->assertSame(false, config('hyde.pretty_urls'));
- $this->assertSame(true, config('hyde.generate_sitemap'));
- $this->assertSame(true, config('hyde.rss.enabled'));
$this->assertSame('feed.xml', config('hyde.rss.filename'));
$this->assertSame('Test RSS Feed', config('hyde.rss.description'));
$this->assertSame('en', config('hyde.language'));
$this->assertSame('_site', config('hyde.output_directory'));
+ $this->assertTrue(config('hyde.generate_sitemap'));
+ $this->assertTrue(config('hyde.rss.enabled'));
+ $this->assertFalse(config('hyde.pretty_urls'));
}
public function testCanDefineMultipleConfigSettingsInHydeYmlFile()
diff --git a/tests/Unit/ServeCommandOptionsUnitTest.php b/tests/Unit/ServeCommandOptionsUnitTest.php
index 3c9c0a96..663367a2 100644
--- a/tests/Unit/ServeCommandOptionsUnitTest.php
+++ b/tests/Unit/ServeCommandOptionsUnitTest.php
@@ -210,7 +210,7 @@ public function testCheckArgvForOption()
$command = $this->getMock();
$this->assertSame('true', $command->checkArgvForOption('pretty-urls'));
- $this->assertSame(null, $command->checkArgvForOption('dashboard'));
+ $this->assertNull($command->checkArgvForOption('dashboard'));
$_SERVER = $serverBackup;
}
diff --git a/tests/Unit/TestingSupportHelpersMetaTest.php b/tests/Unit/TestingSupportHelpersMetaTest.php
index f4ca64f3..55abd8b7 100644
--- a/tests/Unit/TestingSupportHelpersMetaTest.php
+++ b/tests/Unit/TestingSupportHelpersMetaTest.php
@@ -8,6 +8,7 @@
use Hyde\Pages\InMemoryPage;
use Hyde\Testing\UnitTestCase;
use Hyde\Testing\MocksKernelFeatures;
+use Hyde\Testing\FluentTestingHelpers;
/**
* Meta test for internal testing helpers.
@@ -21,6 +22,7 @@
class TestingSupportHelpersMetaTest extends UnitTestCase
{
use MocksKernelFeatures;
+ use FluentTestingHelpers;
protected static bool $needsKernel = true;
protected static bool $needsConfig = true;
@@ -63,6 +65,44 @@ public function testWithPagesWhenSupplyingStrings()
$this->assertContainsOnlyInstancesOf(InMemoryPage::class, $this->kernel->pages());
}
+ public function testAssertAllSameAssertsAllValuesAreTheSame()
+ {
+ $string = 'foo';
+ $array = ['foo'];
+ $object = (object) ['foo' => 'bar'];
+
+ $this->assertAllSame($string, 'foo', 'foo');
+ $this->assertAllSame($array, $array, $array);
+ $this->assertAllSame($object, $object, $object);
+ }
+
+ public function testAssertAllSameFailsWhenValuesAreNotEqual()
+ {
+ $tests = [
+ ['foo', 'bar'],
+ [['foo'], ['bar']],
+ [(object) ['foo' => 'bar'], (object) ['foo' => 'baz']],
+ ];
+
+ foreach ($tests as $expected) {
+ try {
+ $this->assertAllSame(...$expected);
+ } catch (\PHPUnit\Framework\AssertionFailedError $exception) {
+ $this->assertStringContainsString('Failed asserting that two', $exception->getMessage());
+ $this->assertStringContainsString('are equal.', $exception->getMessage());
+ }
+ }
+ }
+
+ public function testAssertAllSameFailsWhenValuesAreNotIdentical()
+ {
+ try {
+ $this->assertAllSame((object) ['foo' => 'bar'], (object) ['foo' => 'bar']);
+ } catch (\PHPUnit\Framework\AssertionFailedError $exception) {
+ $this->assertSame('Failed asserting that two variables reference the same object.', $exception->getMessage());
+ }
+ }
+
protected function getPageIdentifiers()
{
return $this->kernel->pages()->keys()->all();
From 3e36d718f58894ee50139f367dbdb1029cfe31ea Mon Sep 17 00:00:00 2001
From: Caen De Silva
Date: Sat, 21 Dec 2024 17:30:46 +0100
Subject: [PATCH 07/28] Add coloring to make output easier to read
---
.github/bin/pick.php | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/.github/bin/pick.php b/.github/bin/pick.php
index f9a8d201..c4ca68d0 100644
--- a/.github/bin/pick.php
+++ b/.github/bin/pick.php
@@ -5,8 +5,9 @@
// Check if we have the correct number of arguments
if ($argc !== 3) {
- echo "Usage: php bin/pick.php \n";
- echo "Example: php bin/pick.php abc123 feature-branch\n";
+ echo "\033[31mError: Invalid number of arguments\033[0m\n";
+ echo "\033[1mUsage:\033[0m php bin/pick.php \n";
+ echo "\033[1mExample:\033[0m php bin/pick.php abc123 feature-branch\n";
exit(1);
}
@@ -16,23 +17,25 @@
// Create new branch from master
$checkoutCommand = "git checkout -b $branch master";
+echo "\033[36m> $checkoutCommand\033[0m\n";
exec($checkoutCommand, $output, $returnCode);
if ($returnCode !== 0) {
- echo "Error creating new branch: $branch\n";
+ echo "\033[31mError creating new branch: $branch\033[0m\n";
exit(1);
}
// Cherry-pick the commit
$cherryPickCommand = "git cherry-pick $hash";
+echo "\033[36m> $cherryPickCommand\033[0m\n";
exec($cherryPickCommand, $output, $returnCode);
if ($returnCode !== 0) {
- echo "Error cherry-picking commit: $hash\n";
+ echo "\033[31mError cherry-picking commit: $hash\033[0m\n";
exit(1);
}
-echo "Successfully created branch '$branch' and cherry-picked commit '$hash'\n";
+echo "\033[32mSuccessfully created branch '$branch' and cherry-picked commit '$hash'\033[0m\n";
// Get the commit message
$command = "git show $hash --pretty=format:\"%s%n%b\" -s";
@@ -47,8 +50,8 @@
$prNumber = $matches[1];
$title = trim($matches[2]);
- echo "\nSuggested PR format:\n";
- echo "Title: $title\n";
- echo "Description: Merges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
+ echo "\n\033[1mSuggested PR format:\033[0m\n";
+ echo "\033[1mTitle:\033[0m $title\n";
+ echo "\033[1mDescription:\033[0m Merges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
}
}
From 1c2b8b6fc6667268296e6bb8f622893d0c4eb5c4 Mon Sep 17 00:00:00 2001
From: Caen De Silva
Date: Sat, 21 Dec 2024 17:40:10 +0100
Subject: [PATCH 08/28] Commit message must be checked first for some reason
---
.github/bin/pick.php | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/.github/bin/pick.php b/.github/bin/pick.php
index c4ca68d0..15ab9f79 100644
--- a/.github/bin/pick.php
+++ b/.github/bin/pick.php
@@ -15,6 +15,25 @@
$hash = $argv[1];
$branch = $argv[2];
+// Get the commit message
+$command = "git show $hash --pretty=format:\"%s%n%b\" -s";
+exec($command, $output, $returnCode);
+
+if ($returnCode === 0 && !empty($output)) {
+ // Join output lines
+ $commitMessage = implode("\n", $output);
+
+ // Check if this matches the subrepo sync format
+ if (preg_match('/^Merge pull request #(\d+).*\n(.*?)https:\/\/github\.com\/hydephp\/develop\/commit/', $commitMessage, $matches)) {
+ $prNumber = $matches[1];
+ $title = trim($matches[2]);
+
+ $echo = "\n\033[1mSuggested PR format:\033[0m\n";
+ $echo .= "\033[1mTitle:\033[0m $title\n";
+ $echo .= "\033[1mDescription:\033[0m Merges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
+ }
+}
+
// Create new branch from master
$checkoutCommand = "git checkout -b $branch master";
echo "\033[36m> $checkoutCommand\033[0m\n";
@@ -37,21 +56,6 @@
echo "\033[32mSuccessfully created branch '$branch' and cherry-picked commit '$hash'\033[0m\n";
-// Get the commit message
-$command = "git show $hash --pretty=format:\"%s%n%b\" -s";
-exec($command, $output, $returnCode);
-
-if ($returnCode === 0 && !empty($output)) {
- // Join output lines
- $commitMessage = implode("\n", $output);
-
- // Check if this matches the subrepo sync format
- if (preg_match('/^Merge pull request #(\d+).*\n(.*?)https:\/\/github\.com\/hydephp\/develop\/commit/', $commitMessage, $matches)) {
- $prNumber = $matches[1];
- $title = trim($matches[2]);
-
- echo "\n\033[1mSuggested PR format:\033[0m\n";
- echo "\033[1mTitle:\033[0m $title\n";
- echo "\033[1mDescription:\033[0m Merges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
- }
+if (isset($echo)) {
+ echo $echo;
}
From e654f4d0393744991be64d3dda596a09e9dfb7a8 Mon Sep 17 00:00:00 2001
From: Caen De Silva
Date: Sat, 21 Dec 2024 17:44:18 +0100
Subject: [PATCH 09/28] Refactor and cleanup script
---
.github/bin/pick.php | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/.github/bin/pick.php b/.github/bin/pick.php
index 15ab9f79..fd14683f 100644
--- a/.github/bin/pick.php
+++ b/.github/bin/pick.php
@@ -6,8 +6,8 @@
// Check if we have the correct number of arguments
if ($argc !== 3) {
echo "\033[31mError: Invalid number of arguments\033[0m\n";
- echo "\033[1mUsage:\033[0m php bin/pick.php \n";
- echo "\033[1mExample:\033[0m php bin/pick.php abc123 feature-branch\n";
+ echo "\033[33mUsage:\033[0m php bin/pick.php \n";
+ echo "\033[33mExample:\033[0m php bin/pick.php abc123 feature-branch\n";
exit(1);
}
@@ -16,28 +16,24 @@
$branch = $argv[2];
// Get the commit message
-$command = "git show $hash --pretty=format:\"%s%n%b\" -s";
-exec($command, $output, $returnCode);
+exec("git show $hash --pretty=format:\"%s%n%b\" -s", $output, $returnCode);
if ($returnCode === 0 && !empty($output)) {
- // Join output lines
$commitMessage = implode("\n", $output);
-
+
// Check if this matches the subrepo sync format
if (preg_match('/^Merge pull request #(\d+).*\n(.*?)https:\/\/github\.com\/hydephp\/develop\/commit/', $commitMessage, $matches)) {
$prNumber = $matches[1];
$title = trim($matches[2]);
-
- $echo = "\n\033[1mSuggested PR format:\033[0m\n";
- $echo .= "\033[1mTitle:\033[0m $title\n";
- $echo .= "\033[1mDescription:\033[0m Merges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
+
+ $echo = "\n\033[33mSuggested PR format:\033[0m\n";
+ $echo .= "\033[33mTitle:\033[0m $title\n";
+ $echo .= "\033[33mDescription:\033[0m Merges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
}
}
// Create new branch from master
-$checkoutCommand = "git checkout -b $branch master";
-echo "\033[36m> $checkoutCommand\033[0m\n";
-exec($checkoutCommand, $output, $returnCode);
+exec("git checkout -b $branch master", $output, $returnCode);
if ($returnCode !== 0) {
echo "\033[31mError creating new branch: $branch\033[0m\n";
@@ -45,9 +41,7 @@
}
// Cherry-pick the commit
-$cherryPickCommand = "git cherry-pick $hash";
-echo "\033[36m> $cherryPickCommand\033[0m\n";
-exec($cherryPickCommand, $output, $returnCode);
+exec("git cherry-pick $hash", $output, $returnCode);
if ($returnCode !== 0) {
echo "\033[31mError cherry-picking commit: $hash\033[0m\n";
From c59fae7960c3e2cc3135f25a3a19fa81145cf639 Mon Sep 17 00:00:00 2001
From: Caen De Silva
Date: Sat, 21 Dec 2024 17:46:14 +0100
Subject: [PATCH 10/28] Pretendable script
---
.github/bin/pick.php | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/.github/bin/pick.php b/.github/bin/pick.php
index fd14683f..ab64b2dd 100644
--- a/.github/bin/pick.php
+++ b/.github/bin/pick.php
@@ -4,7 +4,7 @@
// Internal helper to speed up branching up cherry picked commits for pull requests
// Check if we have the correct number of arguments
-if ($argc !== 3) {
+if ($argc !== 3 && $argc !== 4) {
echo "\033[31mError: Invalid number of arguments\033[0m\n";
echo "\033[33mUsage:\033[0m php bin/pick.php \n";
echo "\033[33mExample:\033[0m php bin/pick.php abc123 feature-branch\n";
@@ -14,6 +14,7 @@
// Get arguments
$hash = $argv[1];
$branch = $argv[2];
+$pretend = $argv[3] === '--pretend';
// Get the commit message
exec("git show $hash --pretty=format:\"%s%n%b\" -s", $output, $returnCode);
@@ -33,7 +34,7 @@
}
// Create new branch from master
-exec("git checkout -b $branch master", $output, $returnCode);
+exec(($pretend ? 'echo ' : '') . "git checkout -b $branch master", $output, $returnCode);
if ($returnCode !== 0) {
echo "\033[31mError creating new branch: $branch\033[0m\n";
@@ -41,7 +42,7 @@
}
// Cherry-pick the commit
-exec("git cherry-pick $hash", $output, $returnCode);
+exec(($pretend ? 'echo ' : '') . "git cherry-pick $hash", $output, $returnCode);
if ($returnCode !== 0) {
echo "\033[31mError cherry-picking commit: $hash\033[0m\n";
From 08d221447c6c4bc47d3638b015e305e4a7cb6824 Mon Sep 17 00:00:00 2001
From: Caen De Silva
Date: Sat, 21 Dec 2024 17:51:48 +0100
Subject: [PATCH 11/28] Cleanup and make output easier to copy
---
.github/bin/pick.php | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/.github/bin/pick.php b/.github/bin/pick.php
index ab64b2dd..34ad6a24 100644
--- a/.github/bin/pick.php
+++ b/.github/bin/pick.php
@@ -6,7 +6,7 @@
// Check if we have the correct number of arguments
if ($argc !== 3 && $argc !== 4) {
echo "\033[31mError: Invalid number of arguments\033[0m\n";
- echo "\033[33mUsage:\033[0m php bin/pick.php \n";
+ echo "\033[33mUsage:\033[0m php bin/pick.php [--pretend]\n";
echo "\033[33mExample:\033[0m php bin/pick.php abc123 feature-branch\n";
exit(1);
}
@@ -27,9 +27,8 @@
$prNumber = $matches[1];
$title = trim($matches[2]);
- $echo = "\n\033[33mSuggested PR format:\033[0m\n";
- $echo .= "\033[33mTitle:\033[0m $title\n";
- $echo .= "\033[33mDescription:\033[0m Merges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
+ $printWhenDone = "\n\033[33mSuggested PR format: (Line 1: title, Line 2: description)\033[0m\n";
+ $printWhenDone .= "$title\nMerges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
}
}
@@ -51,6 +50,6 @@
echo "\033[32mSuccessfully created branch '$branch' and cherry-picked commit '$hash'\033[0m\n";
-if (isset($echo)) {
- echo $echo;
+if (isset($printWhenDone)) {
+ echo $printWhenDone;
}
From 2d24b50150c35c26f5b76e4bb864a78bc92b3c29 Mon Sep 17 00:00:00 2001
From: Caen De Silva
Date: Sat, 21 Dec 2024 17:57:14 +0100
Subject: [PATCH 12/28] Fix undefined array key
---
.github/bin/pick.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/bin/pick.php b/.github/bin/pick.php
index 34ad6a24..1db0145e 100644
--- a/.github/bin/pick.php
+++ b/.github/bin/pick.php
@@ -14,7 +14,7 @@
// Get arguments
$hash = $argv[1];
$branch = $argv[2];
-$pretend = $argv[3] === '--pretend';
+$pretend = ($argv[3] ?? false) === '--pretend';
// Get the commit message
exec("git show $hash --pretty=format:\"%s%n%b\" -s", $output, $returnCode);
From 88c20f406f84cf2dd0dd551b92206bd7177ee4de Mon Sep 17 00:00:00 2001
From: github-actions
Date: Wed, 10 Jul 2024 12:06:26 +0000
Subject: [PATCH 13/28] Merge pull request #1820 from
hydephp/normalize-documented-link
Normalize documented link in code documentation https://github.com/hydephp/develop/commit/f2b7f0177244f3299a4d07fe732e1be503bc4189
---
src/Facades/Author.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Facades/Author.php b/src/Facades/Author.php
index 16976036..d9bbbb89 100644
--- a/src/Facades/Author.php
+++ b/src/Facades/Author.php
@@ -18,7 +18,7 @@ class Author
* Construct a new Post Author. For Hyde to discover this author,
* you must call this method from your hyde.php config file.
*
- * @see https://hydephp.com/docs/1.x/customization.html#authors
+ * @see https://hydephp.com/docs/1.x/customization#authors
*
* @param string $username The username of the author. This is the key used to find authors in the config.
* @param string|null $name The optional display name of the author, leave blank to use the username.
From c9a061a5cd3c2daee66d346e5feef62706ebe1c0 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Wed, 10 Jul 2024 13:45:18 +0000
Subject: [PATCH 14/28] Merge pull request #1823 from
hydephp/add-new-hydestan-rules
Add new HydeStan rules and resolve code style issues https://github.com/hydephp/develop/commit/bb69818a469237ac01729ff1818c3ed9c4164d0b
---
src/Foundation/Concerns/HandlesFoundationCollections.php | 2 +-
src/Foundation/Facades/Files.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Foundation/Concerns/HandlesFoundationCollections.php b/src/Foundation/Concerns/HandlesFoundationCollections.php
index e9ef2625..3192ee0c 100644
--- a/src/Foundation/Concerns/HandlesFoundationCollections.php
+++ b/src/Foundation/Concerns/HandlesFoundationCollections.php
@@ -15,7 +15,7 @@
*/
trait HandlesFoundationCollections
{
- /** @return \Hyde\Foundation\Kernel\FileCollection */
+ /** @return \Hyde\Foundation\Kernel\FileCollection */
public function files(): FileCollection
{
$this->needsToBeBooted();
diff --git a/src/Foundation/Facades/Files.php b/src/Foundation/Facades/Files.php
index 39bbebb6..79d2acdc 100644
--- a/src/Foundation/Facades/Files.php
+++ b/src/Foundation/Facades/Files.php
@@ -13,7 +13,7 @@
*/
class Files extends Facade
{
- /** @return \Hyde\Foundation\Kernel\FileCollection */
+ /** @return \Hyde\Foundation\Kernel\FileCollection */
public static function getFacadeRoot(): FileCollection
{
return HydeKernel::getInstance()->files();
From bd9819d6f512fa671a22e8b143b8e7687ebd93d1 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Thu, 11 Jul 2024 20:27:49 +0000
Subject: [PATCH 15/28] Merge pull request #1829 from
hydephp/blade-view-formatting
Fix article excerpt indentation https://github.com/hydephp/develop/commit/9bfc91d3ac3e63a5a1de2ea0325e65252e78ae8e
---
resources/views/components/article-excerpt.blade.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/resources/views/components/article-excerpt.blade.php b/resources/views/components/article-excerpt.blade.php
index a3a42a73..666c628a 100644
--- a/resources/views/components/article-excerpt.blade.php
+++ b/resources/views/components/article-excerpt.blade.php
@@ -20,7 +20,7 @@
@endisset
@isset($post->author)
-
+
by
{{ $post->author->name ?? $post->author->username }}
From d407e1ce77ee58d3083c24e80777eb085b6cbc99 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Fri, 12 Jul 2024 10:32:17 +0000
Subject: [PATCH 16/28] Merge pull request #1832 from
hydephp/remove-extra-space-from-signature
Remove extra space from command signature https://github.com/hydephp/develop/commit/04ce285b096b546cb50a12b3dccc225abe592eec
---
src/Console/Commands/ChangeSourceDirectoryCommand.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Console/Commands/ChangeSourceDirectoryCommand.php b/src/Console/Commands/ChangeSourceDirectoryCommand.php
index 6bffde7f..2b9f8cee 100644
--- a/src/Console/Commands/ChangeSourceDirectoryCommand.php
+++ b/src/Console/Commands/ChangeSourceDirectoryCommand.php
@@ -27,7 +27,7 @@
class ChangeSourceDirectoryCommand extends Command
{
/** @var string */
- protected $signature = 'change:sourceDirectory {name : The new source directory name }';
+ protected $signature = 'change:sourceDirectory {name : The new source directory name}';
/** @var string */
protected $description = 'Change the source directory for your project';
From 3dcc82c5fab40d9d3c66c27e9e43568f6f84f2d0 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Wed, 17 Jul 2024 13:57:12 +0000
Subject: [PATCH 17/28] Merge pull request #1867 from
hydephp/serve-command-test
Refactor the serve command and add more unit tests for it https://github.com/hydephp/develop/commit/d69bd8fb2a4ced3fcab3ab3b553001ad3a633185
---
src/Console/Commands/ServeCommand.php | 17 +++++++++------
tests/Unit/ServeCommandOptionsUnitTest.php | 25 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/src/Console/Commands/ServeCommand.php b/src/Console/Commands/ServeCommand.php
index 5bb8ce0b..bcb8e11a 100644
--- a/src/Console/Commands/ServeCommand.php
+++ b/src/Console/Commands/ServeCommand.php
@@ -146,12 +146,7 @@ protected function checkArgvForOption(string $name): ?string
protected function openInBrowser(string $path = '/'): void
{
- $binary = match (PHP_OS_FAMILY) {
- 'Windows' => 'start',
- 'Darwin' => 'open',
- 'Linux' => 'xdg-open',
- default => null
- };
+ $binary = $this->getOpenCommand(PHP_OS_FAMILY);
$command = sprintf('%s http://%s:%d', $binary, $this->getHostSelection(), $this->getPortSelection());
$command = rtrim("$command/$path", '/');
@@ -164,4 +159,14 @@ protected function openInBrowser(string $path = '/'): void
$this->newLine();
}
}
+
+ protected function getOpenCommand(string $osFamily): ?string
+ {
+ return match ($osFamily) {
+ 'Windows' => 'start',
+ 'Darwin' => 'open',
+ 'Linux' => 'xdg-open',
+ default => null
+ };
+ }
}
diff --git a/tests/Unit/ServeCommandOptionsUnitTest.php b/tests/Unit/ServeCommandOptionsUnitTest.php
index 663367a2..f76d70e3 100644
--- a/tests/Unit/ServeCommandOptionsUnitTest.php
+++ b/tests/Unit/ServeCommandOptionsUnitTest.php
@@ -315,6 +315,26 @@ public function testOpenInBrowserThatFails()
$command->openInBrowser();
}
+ public function testGetOpenCommandForWindows()
+ {
+ $this->assertSame('start', $this->getMock()->getOpenCommand('Windows'));
+ }
+
+ public function testGetOpenCommandForDarwin()
+ {
+ $this->assertSame('open', $this->getMock()->getOpenCommand('Darwin'));
+ }
+
+ public function testGetOpenCommandForLinux()
+ {
+ $this->assertSame('xdg-open', $this->getMock()->getOpenCommand('Linux'));
+ }
+
+ public function testGetOpenCommandForUnknownOS()
+ {
+ $this->assertNull($this->getMock()->getOpenCommand('UnknownOS'));
+ }
+
protected function getTestRunnerBinary(): string
{
return match (PHP_OS_FAMILY) {
@@ -384,6 +404,11 @@ public function option($key = null)
{
return $this->input->getOption($key);
}
+
+ public function getOpenCommand(string $osFamily): ?string
+ {
+ return parent::getOpenCommand($osFamily);
+ }
}
class InputMock
From 1680f43c0447511c52adaf07afa0781861e41580 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Wed, 17 Jul 2024 17:12:32 +0000
Subject: [PATCH 18/28] Merge pull request #1868 from
hydephp/increase-type-coverage
Refactor code to increase code quality and type coverage https://github.com/hydephp/develop/commit/05dd78e499bfc77326079e0656641950f0caaa34
---
.../Concerns/BaseFoundationCollection.php | 5 +++++
.../Concerns/HandlesFoundationCollections.php | 3 ---
src/Foundation/Facades/Files.php | 1 -
src/Foundation/Facades/Pages.php | 1 -
src/Foundation/Facades/Routes.php | 2 --
.../Internal/LoadYamlConfiguration.php | 7 ++++++-
src/Foundation/Kernel/FileCollection.php | 7 ++-----
src/Foundation/Kernel/PageCollection.php | 7 ++-----
src/Foundation/Kernel/RouteCollection.php | 7 ++-----
src/Framework/Features/Metadata/MetadataBag.php | 17 +++++------------
10 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/src/Foundation/Concerns/BaseFoundationCollection.php b/src/Foundation/Concerns/BaseFoundationCollection.php
index c11dbe9c..0b97b626 100644
--- a/src/Foundation/Concerns/BaseFoundationCollection.php
+++ b/src/Foundation/Concerns/BaseFoundationCollection.php
@@ -13,6 +13,11 @@
/**
* Base class for the kernel auto-discovery collections.
*
+ * @template TKey of array-key
+ * @template TValue
+ *
+ * @extends \Illuminate\Support\Collection
+ *
* These collections are the heart of the discovery process.
*
* They are responsible for discovering the files, pages, and routes,
diff --git a/src/Foundation/Concerns/HandlesFoundationCollections.php b/src/Foundation/Concerns/HandlesFoundationCollections.php
index 3192ee0c..58b137ed 100644
--- a/src/Foundation/Concerns/HandlesFoundationCollections.php
+++ b/src/Foundation/Concerns/HandlesFoundationCollections.php
@@ -15,7 +15,6 @@
*/
trait HandlesFoundationCollections
{
- /** @return \Hyde\Foundation\Kernel\FileCollection */
public function files(): FileCollection
{
$this->needsToBeBooted();
@@ -23,7 +22,6 @@ public function files(): FileCollection
return $this->files;
}
- /** @return \Hyde\Foundation\Kernel\PageCollection */
public function pages(): PageCollection
{
$this->needsToBeBooted();
@@ -31,7 +29,6 @@ public function pages(): PageCollection
return $this->pages;
}
- /** @return \Hyde\Foundation\Kernel\RouteCollection */
public function routes(): RouteCollection
{
$this->needsToBeBooted();
diff --git a/src/Foundation/Facades/Files.php b/src/Foundation/Facades/Files.php
index 79d2acdc..65e78467 100644
--- a/src/Foundation/Facades/Files.php
+++ b/src/Foundation/Facades/Files.php
@@ -13,7 +13,6 @@
*/
class Files extends Facade
{
- /** @return \Hyde\Foundation\Kernel\FileCollection */
public static function getFacadeRoot(): FileCollection
{
return HydeKernel::getInstance()->files();
diff --git a/src/Foundation/Facades/Pages.php b/src/Foundation/Facades/Pages.php
index a06577b7..42b37c66 100644
--- a/src/Foundation/Facades/Pages.php
+++ b/src/Foundation/Facades/Pages.php
@@ -13,7 +13,6 @@
*/
class Pages extends Facade
{
- /** @return \Hyde\Foundation\Kernel\PageCollection */
public static function getFacadeRoot(): PageCollection
{
return HydeKernel::getInstance()->pages();
diff --git a/src/Foundation/Facades/Routes.php b/src/Foundation/Facades/Routes.php
index 1a211480..f82acc26 100644
--- a/src/Foundation/Facades/Routes.php
+++ b/src/Foundation/Facades/Routes.php
@@ -19,7 +19,6 @@
*/
class Routes extends Facade
{
- /** @return \Hyde\Foundation\Kernel\RouteCollection */
public static function getFacadeRoot(): RouteCollection
{
return HydeKernel::getInstance()->routes();
@@ -41,7 +40,6 @@ public static function getOrFail(string $routeKey): Route
return static::getFacadeRoot()->getRoute($routeKey);
}
- /** @return \Hyde\Foundation\Kernel\RouteCollection<\Hyde\Support\Models\Route> */
public static function all(): RouteCollection
{
return static::getFacadeRoot()->getRoutes();
diff --git a/src/Foundation/Internal/LoadYamlConfiguration.php b/src/Foundation/Internal/LoadYamlConfiguration.php
index d5d75acc..aae50195 100644
--- a/src/Foundation/Internal/LoadYamlConfiguration.php
+++ b/src/Foundation/Internal/LoadYamlConfiguration.php
@@ -26,6 +26,8 @@
class LoadYamlConfiguration
{
protected YamlConfigurationRepository $yaml;
+
+ /** @var array> */
protected array $config;
public function bootstrap(Application $app): void
@@ -33,7 +35,10 @@ public function bootstrap(Application $app): void
$this->yaml = $app->make(YamlConfigurationRepository::class);
if ($this->yaml->hasYamlConfigFile()) {
- tap($app->make('config'), function (Repository $config): void {
+ /** @var Repository $config */
+ $config = $app->make('config');
+
+ tap($config, function (Repository $config): void {
$this->config = $config->all();
$this->mergeParsedConfiguration();
})->set($this->config);
diff --git a/src/Foundation/Kernel/FileCollection.php b/src/Foundation/Kernel/FileCollection.php
index 5754c585..49c67e49 100644
--- a/src/Foundation/Kernel/FileCollection.php
+++ b/src/Foundation/Kernel/FileCollection.php
@@ -18,7 +18,7 @@
*
* @template T of \Hyde\Support\Filesystem\SourceFile
*
- * @template-extends \Hyde\Foundation\Concerns\BaseFoundationCollection
+ * @extends \Hyde\Foundation\Concerns\BaseFoundationCollection
*
* @property array $items The files in the collection.
*
@@ -71,10 +71,7 @@ public function getFile(string $path): SourceFile
return $this->get($path) ?? throw new FileNotFoundException($path);
}
- /**
- * @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass
- * @return \Hyde\Foundation\Kernel\FileCollection
- */
+ /** @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass */
public function getFiles(?string $pageClass = null): FileCollection
{
return $pageClass ? $this->filter(function (SourceFile $file) use ($pageClass): bool {
diff --git a/src/Foundation/Kernel/PageCollection.php b/src/Foundation/Kernel/PageCollection.php
index 4739a177..4cc4d85e 100644
--- a/src/Foundation/Kernel/PageCollection.php
+++ b/src/Foundation/Kernel/PageCollection.php
@@ -14,7 +14,7 @@
*
* @template T of \Hyde\Pages\Concerns\HydePage
*
- * @template-extends \Hyde\Foundation\Concerns\BaseFoundationCollection
+ * @extends \Hyde\Foundation\Concerns\BaseFoundationCollection
*
* @property array $items The pages in the collection.
*
@@ -59,10 +59,7 @@ public function getPage(string $sourcePath): HydePage
return $this->get($sourcePath) ?? throw new FileNotFoundException($sourcePath);
}
- /**
- * @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass
- * @return \Hyde\Foundation\Kernel\PageCollection
- */
+ /** @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass */
public function getPages(?string $pageClass = null): PageCollection
{
return $pageClass ? $this->filter(function (HydePage $page) use ($pageClass): bool {
diff --git a/src/Foundation/Kernel/RouteCollection.php b/src/Foundation/Kernel/RouteCollection.php
index a93b8eab..fe71995a 100644
--- a/src/Foundation/Kernel/RouteCollection.php
+++ b/src/Foundation/Kernel/RouteCollection.php
@@ -15,7 +15,7 @@
*
* @template T of \Hyde\Support\Models\Route
*
- * @template-extends \Hyde\Foundation\Concerns\BaseFoundationCollection
+ * @extends \Hyde\Foundation\Concerns\BaseFoundationCollection
*
* @property array $items The routes in the collection.
*
@@ -53,10 +53,7 @@ public function getRoute(string $routeKey): Route
return $this->get($routeKey) ?? throw new RouteNotFoundException($routeKey);
}
- /**
- * @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass
- * @return \Hyde\Foundation\Kernel\RouteCollection
- */
+ /** @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass */
public function getRoutes(?string $pageClass = null): RouteCollection
{
return $pageClass ? $this->filter(function (Route $route) use ($pageClass): bool {
diff --git a/src/Framework/Features/Metadata/MetadataBag.php b/src/Framework/Features/Metadata/MetadataBag.php
index ff8a036d..51e55491 100644
--- a/src/Framework/Features/Metadata/MetadataBag.php
+++ b/src/Framework/Features/Metadata/MetadataBag.php
@@ -54,26 +54,19 @@ public function get(): array
public function add(MetadataElementContract|string $element): static
{
- return match (true) {
- $element instanceof LinkElement => $this->addElement('links', $element),
- $element instanceof MetadataElement => $this->addElement('metadata', $element),
- $element instanceof OpenGraphElement => $this->addElement('properties', $element),
+ match (true) {
+ $element instanceof LinkElement => $this->links[$element->uniqueKey()] = $element,
+ $element instanceof MetadataElement => $this->metadata[$element->uniqueKey()] = $element,
+ $element instanceof OpenGraphElement => $this->properties[$element->uniqueKey()] = $element,
default => $this->addGenericElement((string) $element),
};
- }
-
- protected function addElement(string $type, MetadataElementContract $element): static
- {
- $this->{$type}[$element->uniqueKey()] = $element;
return $this;
}
- protected function addGenericElement(string $element): static
+ protected function addGenericElement(string $element): void
{
$this->generics[] = $element;
-
- return $this;
}
/** @return array */
From 745f620e0d56ab86fd6833f5ac2e58bc430c165a Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 11:05:18 +0000
Subject: [PATCH 19/28] Merge pull request #1879 from
hydephp/hide-the-torchlight-install-command
Hide the Torchlight install command https://github.com/hydephp/develop/commit/7c7c76c2a8c8d13317fa6ac82581a1ddcc4f1f12
---
config/commands.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/config/commands.php b/config/commands.php
index d15ac8b7..eff75e1b 100644
--- a/config/commands.php
+++ b/config/commands.php
@@ -59,6 +59,7 @@
Symfony\Component\Console\Command\DumpCompletionCommand::class,
Symfony\Component\Console\Command\HelpCommand::class,
\Hyde\Console\Commands\DebugCommand::class,
+ \Torchlight\Commands\Install::class,
],
/*
From 465d18c783bc67f7ddbba23680966ccb9348c061 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 13:30:14 +0000
Subject: [PATCH 20/28] Merge pull request #1880 from
hydephp/fix-404-home-page-link
Update 404 page home link fallback to lead to the domain root https://github.com/hydephp/develop/commit/3d28ddbafa3b629ff289f4072c57be93c439fa86
---
resources/views/pages/404.blade.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/resources/views/pages/404.blade.php b/resources/views/pages/404.blade.php
index ce28c79b..7a4328b1 100644
--- a/resources/views/pages/404.blade.php
+++ b/resources/views/pages/404.blade.php
@@ -31,7 +31,7 @@
Sorry, the page you are looking for could not be found.
-
+
Go Home
From ac3322fde9282052774f9b5c8de31eb9ae18bbcc Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 13:49:31 +0000
Subject: [PATCH 21/28] Merge pull request #1881 from
hydephp/register-hidden-cache-clear-command
Register the cache clear command https://github.com/hydephp/develop/commit/92aafc5b8ade41bf25793ad0a645dc898694b9bc
---
config/commands.php | 1 +
.../Commands/CacheClearCommandTest.php | 27 +++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 tests/Feature/Commands/CacheClearCommandTest.php
diff --git a/config/commands.php b/config/commands.php
index d15ac8b7..bb0496ff 100644
--- a/config/commands.php
+++ b/config/commands.php
@@ -58,6 +58,7 @@
NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
Symfony\Component\Console\Command\DumpCompletionCommand::class,
Symfony\Component\Console\Command\HelpCommand::class,
+ \Illuminate\Cache\Console\ClearCommand::class,
\Hyde\Console\Commands\DebugCommand::class,
],
diff --git a/tests/Feature/Commands/CacheClearCommandTest.php b/tests/Feature/Commands/CacheClearCommandTest.php
new file mode 100644
index 00000000..318beef1
--- /dev/null
+++ b/tests/Feature/Commands/CacheClearCommandTest.php
@@ -0,0 +1,27 @@
+ 'bar');
+
+ $this->assertSame('bar', Cache::get('foo'));
+
+ $this->artisan('cache:clear')
+ ->expectsOutputToContain('Application cache cleared successfully.')
+ ->assertExitCode(0);
+
+ $this->assertNull(Cache::get('foo'));
+ }
+}
From 17763234f5f22866fee7a4c671366fcbb1861806 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 15:01:46 +0000
Subject: [PATCH 22/28] Clarify code comment
https://github.com/hydephp/develop/commit/4546ca9c9a07d56d17ab30a75c6f08686be2bfc9
---
src/Markdown/Contracts/FrontMatter/PageSchema.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Markdown/Contracts/FrontMatter/PageSchema.php b/src/Markdown/Contracts/FrontMatter/PageSchema.php
index ac8eed79..5700b57f 100644
--- a/src/Markdown/Contracts/FrontMatter/PageSchema.php
+++ b/src/Markdown/Contracts/FrontMatter/PageSchema.php
@@ -13,7 +13,7 @@ interface PageSchema extends FrontMatterSchema
{
public const PAGE_SCHEMA = [
'title' => 'string',
- 'canonicalUrl' => 'string', // While not present in the page data, it is supported as a front matter key for the accessor data source.
+ 'canonicalUrl' => 'string', // While not present in the page data as a property, it is used for the accessor method, which reads this value from the front matter.
'navigation' => NavigationSchema::NAVIGATION_SCHEMA,
];
}
From 99e6cd60829ba69f6745c902ce3d152a526d0bb6 Mon Sep 17 00:00:00 2001
From: Caen De Silva
Date: Sat, 21 Dec 2024 18:13:36 +0100
Subject: [PATCH 23/28] Generate automatic command
---
.github/bin/pick.php | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/.github/bin/pick.php b/.github/bin/pick.php
index 1db0145e..c0303b09 100644
--- a/.github/bin/pick.php
+++ b/.github/bin/pick.php
@@ -26,9 +26,12 @@
if (preg_match('/^Merge pull request #(\d+).*\n(.*?)https:\/\/github\.com\/hydephp\/develop\/commit/', $commitMessage, $matches)) {
$prNumber = $matches[1];
$title = trim($matches[2]);
+ $body = "Merges pull request https://github.com/hydephp/develop/pull/$prNumber";
- $printWhenDone = "\n\033[33mSuggested PR format: (Line 1: title, Line 2: description)\033[0m\n";
- $printWhenDone .= "$title\nMerges pull request https://github.com/hydephp/develop/pull/$prNumber\n";
+ $printWhenDone = "\n\033[33mSuggested PR format: (Line 1: title, Line 2: description, Line 3: command)\033[0m\n";
+ $printWhenDone .= "$title\n$body\n";
+
+ $printWhenDone .= "\033[37mgh pr create --title \"$title\" --body \"$body\"\033[0m\n";
}
}
From 0527115bbacc080c2be82da957a04c57170f3760 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 14:12:12 +0000
Subject: [PATCH 24/28] Merge pull request #1882 from
hydephp/normalize-protocol-relative-url-handling
Normalize protocol relative URL handling https://github.com/hydephp/develop/commit/aa06e42f72fec3e08a4e6a936f2b0e6a0d519384
---
src/Foundation/Kernel/Hyperlinks.php | 12 ++++++--
.../Factories/FeaturedImageFactory.php | 3 +-
.../Blogging/Models/FeaturedImage.php | 13 ++++++--
.../Features/Metadata/PageMetadataBag.php | 4 +--
tests/Feature/Foundation/HyperlinksTest.php | 30 +++++++++++++++++++
5 files changed, 54 insertions(+), 8 deletions(-)
diff --git a/src/Foundation/Kernel/Hyperlinks.php b/src/Foundation/Kernel/Hyperlinks.php
index c73e3186..2a94165d 100644
--- a/src/Foundation/Kernel/Hyperlinks.php
+++ b/src/Foundation/Kernel/Hyperlinks.php
@@ -115,7 +115,7 @@ public function mediaLink(string $destination, bool $validate = false): string
*/
public function asset(string $name, bool $preferQualifiedUrl = false): string
{
- if (str_starts_with($name, 'http')) {
+ if (static::isRemote($name)) {
return $name;
}
@@ -151,7 +151,7 @@ public function url(string $path = ''): string
{
$path = $this->formatLink(trim($path, '/'));
- if (str_starts_with($path, 'http')) {
+ if (static::isRemote($path)) {
return $path;
}
@@ -177,4 +177,12 @@ public function route(string $key): ?Route
{
return $this->kernel->routes()->get($key);
}
+
+ /**
+ * Determine if the given URL is a remote link.
+ */
+ public static function isRemote(string $url): bool
+ {
+ return str_starts_with($url, 'http') || str_starts_with($url, '//');
+ }
}
diff --git a/src/Framework/Factories/FeaturedImageFactory.php b/src/Framework/Factories/FeaturedImageFactory.php
index 2ecbbf27..4c2fdb01 100644
--- a/src/Framework/Factories/FeaturedImageFactory.php
+++ b/src/Framework/Factories/FeaturedImageFactory.php
@@ -8,6 +8,7 @@
use RuntimeException;
use Illuminate\Support\Str;
use Hyde\Markdown\Models\FrontMatter;
+use Hyde\Foundation\Kernel\Hyperlinks;
use Hyde\Framework\Features\Blogging\Models\FeaturedImage;
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;
@@ -72,7 +73,7 @@ protected function makeSource(): string
throw new RuntimeException(sprintf('No featured image source was found in "%s"', $this->filePath ?? 'unknown file'));
}
- if (FeaturedImage::isRemote($value)) {
+ if (Hyperlinks::isRemote($value)) {
return $value;
}
diff --git a/src/Framework/Features/Blogging/Models/FeaturedImage.php b/src/Framework/Features/Blogging/Models/FeaturedImage.php
index a8dcb492..ebb3522c 100644
--- a/src/Framework/Features/Blogging/Models/FeaturedImage.php
+++ b/src/Framework/Features/Blogging/Models/FeaturedImage.php
@@ -9,7 +9,9 @@
use Hyde\Facades\Config;
use Illuminate\Support\Str;
use Hyde\Support\BuildWarnings;
+use JetBrains\PhpStorm\Deprecated;
use Illuminate\Support\Facades\Http;
+use Hyde\Foundation\Kernel\Hyperlinks;
use Hyde\Framework\Exceptions\FileNotFoundException;
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;
@@ -19,7 +21,6 @@
use function filesize;
use function sprintf;
use function key;
-use function str_starts_with;
/**
* Object representation of a blog post's featured image.
@@ -63,7 +64,7 @@ public function __construct(
protected readonly ?string $licenseUrl = null,
protected readonly ?string $copyrightText = null
) {
- $this->type = self::isRemote($source) ? self::TYPE_REMOTE : self::TYPE_LOCAL;
+ $this->type = Hyperlinks::isRemote($source) ? self::TYPE_REMOTE : self::TYPE_LOCAL;
$this->source = $this->setSource($source);
}
@@ -241,8 +242,14 @@ protected function getContentLengthForRemoteImage(): int
return 0;
}
+ /**
+ * @codeCoverageIgnore Deprecated method.
+ *
+ * @deprecated This method will be removed in v2.0. Please use `Hyperlinks::isRemote` instead.
+ */
+ #[Deprecated(reason: 'Replaced by the \Hyde\Foundation\Kernel\Hyperlinks::isRemote method', replacement: '\Hyde\Foundation\Kernel\Hyperlinks::isRemote(%parametersList%)', since: '1.8.0')]
public static function isRemote(string $source): bool
{
- return str_starts_with($source, 'http') || str_starts_with($source, '//');
+ return Hyperlinks::isRemote($source);
}
}
diff --git a/src/Framework/Features/Metadata/PageMetadataBag.php b/src/Framework/Features/Metadata/PageMetadataBag.php
index 3aad1667..efada5ec 100644
--- a/src/Framework/Features/Metadata/PageMetadataBag.php
+++ b/src/Framework/Features/Metadata/PageMetadataBag.php
@@ -7,8 +7,8 @@
use Hyde\Facades\Meta;
use Hyde\Pages\Concerns\HydePage;
use Hyde\Pages\MarkdownPost;
+use Hyde\Foundation\Kernel\Hyperlinks;
-use function str_starts_with;
use function substr_count;
use function str_repeat;
@@ -77,7 +77,7 @@ protected function resolveImageLink(string $image): string
{
// Since this is run before the page is rendered, we don't have the currentPage property.
// So we need to run some of the same calculations here to resolve the image path link.
- return str_starts_with($image, 'http') ? $image
+ return Hyperlinks::isRemote($image) ? $image
: str_repeat('../', substr_count(MarkdownPost::outputDirectory().'/'.$this->page->identifier, '/')).$image;
}
}
diff --git a/tests/Feature/Foundation/HyperlinksTest.php b/tests/Feature/Foundation/HyperlinksTest.php
index 390a383a..3234e7cd 100644
--- a/tests/Feature/Foundation/HyperlinksTest.php
+++ b/tests/Feature/Foundation/HyperlinksTest.php
@@ -127,4 +127,34 @@ public function testRouteHelperWithInvalidRoute()
{
$this->assertNull($this->class->route('foo'));
}
+
+ public function testIsRemoteWithHttpUrl()
+ {
+ $this->assertTrue(Hyperlinks::isRemote('http://example.com'));
+ }
+
+ public function testIsRemoteWithHttpsUrl()
+ {
+ $this->assertTrue(Hyperlinks::isRemote('https://example.com'));
+ }
+
+ public function testIsRemoteWithProtocolRelativeUrl()
+ {
+ $this->assertTrue(Hyperlinks::isRemote('//example.com'));
+ }
+
+ public function testIsRemoteWithRelativeUrl()
+ {
+ $this->assertFalse(Hyperlinks::isRemote('/path/to/resource'));
+ }
+
+ public function testIsRemoteWithAbsoluteLocalPath()
+ {
+ $this->assertFalse(Hyperlinks::isRemote('/var/www/html/index.php'));
+ }
+
+ public function testIsRemoteWithEmptyString()
+ {
+ $this->assertFalse(Hyperlinks::isRemote(''));
+ }
}
From d54ea721448e2c792f2d5f02eadb8de27d41bee6 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 15:27:33 +0000
Subject: [PATCH 25/28] Merge pull request #1885 from
hydephp/cleanup-canonical-page-helper-method
Cleanup the canonical URL helper method https://github.com/hydephp/develop/commit/c4f48343a6152d6b158f8d9b3fdb55b6691aac34
---
src/Pages/Concerns/HydePage.php | 7 +++++++
tests/Unit/Pages/BladePageUnitTest.php | 14 +++++++++++++-
tests/Unit/Pages/DocumentationPageUnitTest.php | 14 +++++++++++++-
tests/Unit/Pages/HtmlPageUnitTest.php | 14 +++++++++++++-
tests/Unit/Pages/InMemoryPageUnitTest.php | 14 +++++++++++++-
tests/Unit/Pages/MarkdownPageUnitTest.php | 14 +++++++++++++-
tests/Unit/Pages/MarkdownPostUnitTest.php | 14 +++++++++++++-
7 files changed, 85 insertions(+), 6 deletions(-)
diff --git a/src/Pages/Concerns/HydePage.php b/src/Pages/Concerns/HydePage.php
index fb741358..08a730ea 100644
--- a/src/Pages/Concerns/HydePage.php
+++ b/src/Pages/Concerns/HydePage.php
@@ -397,6 +397,13 @@ public function navigationMenuGroup(): ?string
return $this->navigation->group;
}
+ /**
+ * Get the canonical URL for the page to use in the ` ` tag.
+ *
+ * It can be explicitly set in the front matter using the `canonicalUrl` key,
+ * otherwise it will be generated based on the site URL and the output path,
+ * unless there is no configured base URL, leading to this returning null.
+ */
public function getCanonicalUrl(): ?string
{
/** @var ?string $value */
diff --git a/tests/Unit/Pages/BladePageUnitTest.php b/tests/Unit/Pages/BladePageUnitTest.php
index f15f4292..14cec200 100644
--- a/tests/Unit/Pages/BladePageUnitTest.php
+++ b/tests/Unit/Pages/BladePageUnitTest.php
@@ -182,6 +182,18 @@ public function testMatter()
public function testGetCanonicalUrl()
{
- $this->markTestSkipped('Not yet implemented');
+ $page = new BladePage('foo');
+ $this->assertNull($page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com']);
+
+ $this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);
+
+ $this->assertSame('https://example.com/foo', $page->getCanonicalUrl());
+
+ $page = new BladePage('foo', ['canonicalUrl' => 'foo']);
+ $this->assertSame('foo', $page->getCanonicalUrl());
}
}
diff --git a/tests/Unit/Pages/DocumentationPageUnitTest.php b/tests/Unit/Pages/DocumentationPageUnitTest.php
index b1ea51dd..53aa35a7 100644
--- a/tests/Unit/Pages/DocumentationPageUnitTest.php
+++ b/tests/Unit/Pages/DocumentationPageUnitTest.php
@@ -205,6 +205,18 @@ public function testSave()
public function testGetCanonicalUrl()
{
- $this->markTestSkipped('Not yet implemented');
+ $page = new DocumentationPage('foo');
+ $this->assertNull($page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com']);
+
+ $this->assertSame('https://example.com/docs/foo.html', $page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);
+
+ $this->assertSame('https://example.com/docs/foo', $page->getCanonicalUrl());
+
+ $page = new DocumentationPage('foo', ['canonicalUrl' => 'foo']);
+ $this->assertSame('foo', $page->getCanonicalUrl());
}
}
diff --git a/tests/Unit/Pages/HtmlPageUnitTest.php b/tests/Unit/Pages/HtmlPageUnitTest.php
index ac9f12cd..4603f594 100644
--- a/tests/Unit/Pages/HtmlPageUnitTest.php
+++ b/tests/Unit/Pages/HtmlPageUnitTest.php
@@ -220,6 +220,18 @@ public function testMatter()
public function testGetCanonicalUrl()
{
- $this->markTestSkipped('Not yet implemented');
+ $page = new HtmlPage('foo');
+ $this->assertNull($page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com']);
+
+ $this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);
+
+ $this->assertSame('https://example.com/foo', $page->getCanonicalUrl());
+
+ $page = new HtmlPage('foo', ['canonicalUrl' => 'foo']);
+ $this->assertSame('foo', $page->getCanonicalUrl());
}
}
diff --git a/tests/Unit/Pages/InMemoryPageUnitTest.php b/tests/Unit/Pages/InMemoryPageUnitTest.php
index 6c913084..acfb0da0 100644
--- a/tests/Unit/Pages/InMemoryPageUnitTest.php
+++ b/tests/Unit/Pages/InMemoryPageUnitTest.php
@@ -224,6 +224,18 @@ public function testMatter()
public function testGetCanonicalUrl()
{
- $this->markTestSkipped('Not yet implemented');
+ $page = new InMemoryPage('foo');
+ $this->assertNull($page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com']);
+
+ $this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);
+
+ $this->assertSame('https://example.com/foo', $page->getCanonicalUrl());
+
+ $page = new InMemoryPage('foo', ['canonicalUrl' => 'foo']);
+ $this->assertSame('foo', $page->getCanonicalUrl());
}
}
diff --git a/tests/Unit/Pages/MarkdownPageUnitTest.php b/tests/Unit/Pages/MarkdownPageUnitTest.php
index 1c04e970..1c45d018 100644
--- a/tests/Unit/Pages/MarkdownPageUnitTest.php
+++ b/tests/Unit/Pages/MarkdownPageUnitTest.php
@@ -233,6 +233,18 @@ public function testSave()
public function testGetCanonicalUrl()
{
- $this->markTestSkipped('Not yet implemented');
+ $page = new MarkdownPage('foo');
+ $this->assertNull($page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com']);
+
+ $this->assertSame('https://example.com/foo.html', $page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);
+
+ $this->assertSame('https://example.com/foo', $page->getCanonicalUrl());
+
+ $page = new MarkdownPage('foo', ['canonicalUrl' => 'foo']);
+ $this->assertSame('foo', $page->getCanonicalUrl());
}
}
diff --git a/tests/Unit/Pages/MarkdownPostUnitTest.php b/tests/Unit/Pages/MarkdownPostUnitTest.php
index ade5e74b..7768d9c2 100644
--- a/tests/Unit/Pages/MarkdownPostUnitTest.php
+++ b/tests/Unit/Pages/MarkdownPostUnitTest.php
@@ -233,6 +233,18 @@ public function testSave()
public function testGetCanonicalUrl()
{
- $this->markTestSkipped('Not yet implemented');
+ $page = new MarkdownPost('foo');
+ $this->assertNull($page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com']);
+
+ $this->assertSame('https://example.com/posts/foo.html', $page->getCanonicalUrl());
+
+ self::mockConfig(['hyde.url' => 'https://example.com', 'hyde.pretty_urls' => true]);
+
+ $this->assertSame('https://example.com/posts/foo', $page->getCanonicalUrl());
+
+ $page = new MarkdownPost('foo', ['canonicalUrl' => 'foo']);
+ $this->assertSame('foo', $page->getCanonicalUrl());
}
}
From 471964f3fad8f2a32d01699dfc68fa583e643556 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 15:52:41 +0000
Subject: [PATCH 26/28] Merge pull request #1884 from
hydephp/support-setting-root-page-meta-description-in-front-matter
Support setting page descriptions in front matter for all page types https://github.com/hydephp/develop/commit/c415837087623ede0ebb72262383f01210977eed
---
.../Features/Metadata/PageMetadataBag.php | 6 +-
.../Contracts/FrontMatter/PageSchema.php | 3 +-
tests/Feature/MetadataTest.php | 56 ++++++++++++++++++-
tests/Feature/Views/MetadataViewTest.php | 27 +++++++++
tests/Unit/SchemaContractsTest.php | 1 +
5 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/src/Framework/Features/Metadata/PageMetadataBag.php b/src/Framework/Features/Metadata/PageMetadataBag.php
index efada5ec..f150adcb 100644
--- a/src/Framework/Features/Metadata/PageMetadataBag.php
+++ b/src/Framework/Features/Metadata/PageMetadataBag.php
@@ -34,6 +34,11 @@ protected function addDynamicPageMetadata(HydePage $page): void
$this->add(Meta::link('canonical', $page->getCanonicalUrl()));
}
+ if ($page->has('description')) {
+ $this->add(Meta::name('description', $page->data('description')));
+ $this->add(Meta::property('description', $page->data('description')));
+ }
+
if ($page->has('title')) {
$this->add(Meta::name('twitter:title', $page->title()));
$this->add(Meta::property('title', $page->title()));
@@ -46,7 +51,6 @@ protected function addDynamicPageMetadata(HydePage $page): void
protected function addMetadataForMarkdownPost(MarkdownPost $page): void
{
- $this->addPostMetadataIfExists($page, 'description');
$this->addPostMetadataIfExists($page, 'author');
$this->addPostMetadataIfExists($page, 'category', 'keywords');
diff --git a/src/Markdown/Contracts/FrontMatter/PageSchema.php b/src/Markdown/Contracts/FrontMatter/PageSchema.php
index 5700b57f..2875b10d 100644
--- a/src/Markdown/Contracts/FrontMatter/PageSchema.php
+++ b/src/Markdown/Contracts/FrontMatter/PageSchema.php
@@ -13,7 +13,8 @@ interface PageSchema extends FrontMatterSchema
{
public const PAGE_SCHEMA = [
'title' => 'string',
- 'canonicalUrl' => 'string', // While not present in the page data as a property, it is used for the accessor method, which reads this value from the front matter.
+ 'description' => 'string', // For values. It is used by the automatic page metadata generator, which reads this value from the front matter.
+ 'canonicalUrl' => 'string', // While not present in the page data as a property, it is used by the accessor method, which reads this value from the front matter.
'navigation' => NavigationSchema::NAVIGATION_SCHEMA,
];
}
diff --git a/tests/Feature/MetadataTest.php b/tests/Feature/MetadataTest.php
index c5b31be5..a9273baa 100644
--- a/tests/Feature/MetadataTest.php
+++ b/tests/Feature/MetadataTest.php
@@ -5,6 +5,8 @@
namespace Hyde\Framework\Testing\Feature;
use Hyde\Facades\Meta;
+use Hyde\Pages\BladePage;
+use Hyde\Pages\DocumentationPage;
use Hyde\Framework\Features\Metadata\Elements\LinkElement;
use Hyde\Framework\Features\Metadata\Elements\MetadataElement;
use Hyde\Framework\Features\Metadata\Elements\OpenGraphElement;
@@ -271,16 +273,66 @@ public function testDoesNotAddTwitterAndOpenGraphTitleWhenNoTitleIsSet()
public function testAddsDescriptionWhenDescriptionIsSetInPost()
{
- $page = MarkdownPost::make(matter: ['description' => 'My Description']);
+ $page = new MarkdownPost(matter: ['description' => 'My Description']);
$this->assertPageHasMetadata($page, ' ');
+ $this->assertPageHasMetadata($page, ' ');
}
public function testDoesNotAddDescriptionWhenDescriptionIsNotSetInPost()
{
$page = new MarkdownPost();
- $this->assertPageDoesNotHaveMetadata($page, ' ');
+ $this->assertPageDoesNotHaveMetadata($page, ' assertPageDoesNotHaveMetadata($page, ' 'My Page Description']);
+
+ $this->assertPageHasMetadata($page, ' ');
+ $this->assertPageHasMetadata($page, ' ');
+ }
+
+ public function testDoesNotAddDescriptionWhenDescriptionIsNotSetInMarkdownPage()
+ {
+ $page = new MarkdownPage();
+
+ $this->assertPageDoesNotHaveMetadata($page, ' assertPageDoesNotHaveMetadata($page, ' 'My Page Description']);
+
+ $this->assertPageHasMetadata($page, ' ');
+ $this->assertPageHasMetadata($page, ' ');
+ }
+
+ public function testDoesNotAddDescriptionWhenDescriptionIsNotSetInBladePage()
+ {
+ $page = new BladePage();
+
+ $this->assertPageDoesNotHaveMetadata($page, ' assertPageDoesNotHaveMetadata($page, ' 'My Page Description']);
+
+ $this->assertPageHasMetadata($page, ' ');
+ $this->assertPageHasMetadata($page, ' ');
+ }
+
+ public function testDoesNotAddDescriptionWhenDescriptionIsNotSetInDocumentationPage()
+ {
+ $page = new DocumentationPage();
+
+ $this->assertPageDoesNotHaveMetadata($page, ' assertPageDoesNotHaveMetadata($page, ' ',
' ',
' ',
+ ' ',
' ',
' ',
' ',
@@ -233,6 +234,7 @@ public function testCanonicalUrlTagsAreNotAddedWhenCanonicalUrlIsNotSet()
' ',
' ',
' ',
+ ' ',
' ',
' ',
' ',
@@ -265,4 +267,29 @@ public function testCanonicalUrlTagsAreNotAddedWhenCanonicalUrlIsNotSet()
$this->assertStringNotContainsString($text, $contents);
}
}
+
+ public function testMetadataTagsInMarkdownPageWithDescription()
+ {
+ $this->file('_pages/test-page.md', <<<'MARKDOWN'
+ ---
+ title: "My Page Title"
+ description: "My page description"
+ ---
+
+ ## Welcome to My Page
+
+ This is a test page with a description.
+ MARKDOWN
+ );
+ $this->build('_pages/test-page.md');
+
+ $this->assertSee('test-page', array_merge($this->getDefaultTags(), [
+ 'HydePHP - My Page Title ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ]));
+ }
}
diff --git a/tests/Unit/SchemaContractsTest.php b/tests/Unit/SchemaContractsTest.php
index 2d78f740..97fba6b8 100644
--- a/tests/Unit/SchemaContractsTest.php
+++ b/tests/Unit/SchemaContractsTest.php
@@ -36,6 +36,7 @@ public function testSchemasAreNotAccidentallyChanged()
{
$this->assertSame([
'title' => 'string',
+ 'description' => 'string',
'canonicalUrl' => 'string',
'navigation' => NavigationSchema::NAVIGATION_SCHEMA,
], PageSchema::PAGE_SCHEMA);
From 285aee1907074cd2ea038de4fc0cca593ecdbc68 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 16:01:41 +0000
Subject: [PATCH 27/28] Merge pull request #1886 from hydephp/code-cleanup
Clean up and refactor code https://github.com/hydephp/develop/commit/31e3730c731e145a2a9432f452e8a01260e4150d
---
.../Features/Metadata/PageMetadataBag.php | 8 ++-
tests/Feature/MetadataTest.php | 68 +++++++++----------
2 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/src/Framework/Features/Metadata/PageMetadataBag.php b/src/Framework/Features/Metadata/PageMetadataBag.php
index efada5ec..4b560383 100644
--- a/src/Framework/Features/Metadata/PageMetadataBag.php
+++ b/src/Framework/Features/Metadata/PageMetadataBag.php
@@ -77,7 +77,11 @@ protected function resolveImageLink(string $image): string
{
// Since this is run before the page is rendered, we don't have the currentPage property.
// So we need to run some of the same calculations here to resolve the image path link.
- return Hyperlinks::isRemote($image) ? $image
- : str_repeat('../', substr_count(MarkdownPost::outputDirectory().'/'.$this->page->identifier, '/')).$image;
+ return Hyperlinks::isRemote($image) ? $image : $this->calculatePathTraversal().$image;
+ }
+
+ private function calculatePathTraversal(): string
+ {
+ return str_repeat('../', substr_count(MarkdownPost::outputDirectory().'/'.$this->page->identifier, '/'));
}
}
diff --git a/tests/Feature/MetadataTest.php b/tests/Feature/MetadataTest.php
index c5b31be5..358d5bb6 100644
--- a/tests/Feature/MetadataTest.php
+++ b/tests/Feature/MetadataTest.php
@@ -195,7 +195,7 @@ public function testDynamicMetadataOverridesConfigDefinedMetadata()
Meta::name('twitter:title', 'bar'),
]]);
- $page = MarkdownPage::make(matter: ['title' => 'baz']);
+ $page = new MarkdownPage(matter: ['title' => 'baz']);
$this->assertEquals([
'metadata:twitter:title' => Meta::name('twitter:title', 'HydePHP - baz'),
@@ -207,7 +207,7 @@ public function testDoesNotAddCanonicalLinkWhenBaseUrlIsNotSet()
{
$this->withoutSiteUrl();
- $page = MarkdownPage::make('bar');
+ $page = new MarkdownPage('bar');
$this->assertStringNotContainsString(' metadata->render());
}
@@ -216,7 +216,7 @@ public function testDoesNotAddCanonicalLinkWhenIdentifierIsNotSet()
{
config(['hyde.url' => 'foo']);
- $page = MarkdownPage::make();
+ $page = new MarkdownPage();
$this->assertStringNotContainsString(' metadata->render());
}
@@ -225,7 +225,7 @@ public function testAddsCanonicalLinkWhenBaseUrlAndIdentifierIsSet()
{
config(['hyde.url' => 'foo']);
- $page = MarkdownPage::make('bar');
+ $page = new MarkdownPage('bar');
$this->assertStringContainsString(' ', $page->metadata->render());
}
@@ -235,7 +235,7 @@ public function testCanonicalLinkUsesCleanUrlSetting()
config(['hyde.url' => 'foo']);
config(['hyde.pretty_urls' => true]);
- $page = MarkdownPage::make('bar');
+ $page = new MarkdownPage('bar');
$this->assertStringContainsString(' ', $page->metadata->render());
}
@@ -244,7 +244,7 @@ public function testCanOverrideCanonicalLinkWithFrontMatter()
{
config(['hyde.url' => 'foo']);
- $page = MarkdownPage::make('bar', [
+ $page = new MarkdownPage('bar', [
'canonicalUrl' => 'canonical',
]);
@@ -253,7 +253,7 @@ public function testCanOverrideCanonicalLinkWithFrontMatter()
public function testAddsTwitterAndOpenGraphTitleWhenTitleIsSet()
{
- $page = MarkdownPage::make(matter: ['title' => 'Foo Bar']);
+ $page = new MarkdownPage(matter: ['title' => 'Foo Bar']);
$this->assertSame(
' '."\n".
@@ -264,7 +264,7 @@ public function testAddsTwitterAndOpenGraphTitleWhenTitleIsSet()
public function testDoesNotAddTwitterAndOpenGraphTitleWhenNoTitleIsSet()
{
- $page = MarkdownPage::make(matter: ['title' => null]);
+ $page = new MarkdownPage(matter: ['title' => null]);
$this->assertSame('', $page->metadata->render());
}
@@ -285,7 +285,7 @@ public function testDoesNotAddDescriptionWhenDescriptionIsNotSetInPost()
public function testAddsAuthorWhenAuthorIsSetInPost()
{
- $page = MarkdownPost::make(matter: ['author' => 'My Author']);
+ $page = new MarkdownPost(matter: ['author' => 'My Author']);
$this->assertPageHasMetadata($page, ' ');
}
@@ -294,12 +294,12 @@ public function testDoesNotAddAuthorWhenAuthorIsNotSetInPost()
{
$page = new MarkdownPost();
- $this->assertPageDoesNotHaveMetadata($page, ' ');
+ $this->assertPageDoesNotHaveMetadata($page, ' 'My Category']);
+ $page = new MarkdownPost(matter: ['category' => 'My Category']);
$this->assertPageHasMetadata($page, ' ');
}
@@ -308,12 +308,12 @@ public function testDoesNotAddKeywordsWhenCategoryIsNotSetInPost()
{
$page = new MarkdownPost();
- $this->assertPageDoesNotHaveMetadata($page, ' ');
+ $this->assertPageDoesNotHaveMetadata($page, ' 'example.html']);
+ $page = new MarkdownPost(matter: ['canonicalUrl' => 'example.html']);
$this->assertPageHasMetadata($page, ' ');
}
@@ -322,19 +322,19 @@ public function testDoesNotAddUrlPropertyWhenCanonicalUrlIsNotSetInPost()
{
$page = new MarkdownPost();
- $this->assertPageDoesNotHaveMetadata($page, ' ');
+ $this->assertPageDoesNotHaveMetadata($page, ' null]);
+ $page = new MarkdownPost(matter: ['canonicalUrl' => null]);
- $this->assertPageDoesNotHaveMetadata($page, ' ');
+ $this->assertPageDoesNotHaveMetadata($page, ' 'My Title']);
+ $page = new MarkdownPost(matter: ['title' => 'My Title']);
$this->assertPageHasMetadata($page, ' ');
}
@@ -348,7 +348,7 @@ public function testDoesNotAddTitlePropertyWhenTitleIsNotSetInPost()
public function testAddsPublishedTimePropertyWhenDateIsSetInPost()
{
- $page = MarkdownPost::make(matter: ['date' => '2022-01-01']);
+ $page = new MarkdownPost(matter: ['date' => '2022-01-01']);
$this->assertPageHasMetadata($page, ' ');
}
@@ -356,12 +356,12 @@ public function testAddsPublishedTimePropertyWhenDateIsSetInPost()
public function testDoesNotAddPublishedTimePropertyWhenDateIsNotSetInPost()
{
$page = new MarkdownPost();
- $this->assertPageDoesNotHaveMetadata($page, ' ');
+ $this->assertPageDoesNotHaveMetadata($page, ' 'image.jpg']);
+ $page = new MarkdownPost(matter: ['image' => 'image.jpg']);
$this->assertPageHasMetadata($page, ' ');
}
@@ -369,26 +369,26 @@ public function testAddsImagePropertyWhenImageIsSetInPost()
public function testDoesNotAddImagePropertyWhenImageIsNotSetInPost()
{
$page = new MarkdownPost();
- $this->assertPageDoesNotHaveMetadata($page, ' ');
+ $this->assertPageDoesNotHaveMetadata($page, ' assertPageHasMetadata($page, ' ');
}
public function testDynamicPostMetaPropertiesReturnsBaseArrayWhenInitializedWithEmptyFrontMatter()
{
- $page = MarkdownPost::make();
+ $page = new MarkdownPost();
$this->assertSame(' ', $page->metadata->render());
}
public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedImageSetToString()
{
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'image' => 'foo.jpg',
]);
@@ -397,7 +397,7 @@ public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedIm
public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelative()
{
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'image' => 'foo.jpg',
]);
@@ -406,7 +406,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelati
public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelativeForNestedPosts()
{
- $page = MarkdownPost::make('foo/bar', matter: [
+ $page = new MarkdownPost('foo/bar', matter: [
'image' => 'foo.jpg',
]);
@@ -417,7 +417,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelati
{
MarkdownPost::setOutputDirectory('_posts/foo');
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'image' => 'foo.jpg',
]);
@@ -428,7 +428,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatIsAlwaysRelati
{
MarkdownPost::setOutputDirectory('_posts/foo');
- $page = MarkdownPost::make('bar/baz', matter: [
+ $page = new MarkdownPost('bar/baz', matter: [
'image' => 'foo.jpg',
]);
@@ -439,7 +439,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatUsesTheConfigu
{
Hyde::setMediaDirectory('assets');
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'image' => 'foo.jpg',
]);
@@ -448,7 +448,7 @@ public function testDynamicPostMetaPropertiesContainsImageLinkThatUsesTheConfigu
public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedImageSetToArrayWithPath()
{
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'image' => [
'source' => 'foo.jpg',
],
@@ -459,7 +459,7 @@ public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedIm
public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedImageSetToArrayWithUrl()
{
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'image' => [
'source' => 'https://example.com/foo.jpg',
],
@@ -470,7 +470,7 @@ public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedIm
public function testDynamicPostAuthorReturnsAuthorNameWhenAuthorSetToArrayUsingUsername()
{
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'author' => [
'username' => 'username',
],
@@ -481,7 +481,7 @@ public function testDynamicPostAuthorReturnsAuthorNameWhenAuthorSetToArrayUsingU
public function testDynamicPostAuthorReturnsAuthorNameWhenAuthorSetToArrayUsingName()
{
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'author' => [
'name' => 'Name',
],
@@ -492,7 +492,7 @@ public function testDynamicPostAuthorReturnsAuthorNameWhenAuthorSetToArrayUsingN
public function testNoAuthorIsSetWhenAuthorSetToArrayWithoutNameOrUsername()
{
- $page = MarkdownPost::make(matter: [
+ $page = new MarkdownPost(matter: [
'author' => [],
]);
From 9baf0012837ffeffd0ee85fc618ddc330f768546 Mon Sep 17 00:00:00 2001
From: github-actions
Date: Tue, 23 Jul 2024 16:58:18 +0000
Subject: [PATCH 28/28] Merge pull request #1889 from
hydephp/fix-hardcoded-metadata-url-assembly
Fix URL metadata for blog posts not using customized post output directories https://github.com/hydephp/develop/commit/cf71a76f70e2296dad090336f1b825c45c64b986
---
resources/views/components/article-excerpt.blade.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/resources/views/components/article-excerpt.blade.php b/resources/views/components/article-excerpt.blade.php
index 666c628a..311b26e8 100644
--- a/resources/views/components/article-excerpt.blade.php
+++ b/resources/views/components/article-excerpt.blade.php
@@ -1,8 +1,8 @@
@php /** @var \Hyde\Pages\MarkdownPost $post */ @endphp
- @if(Hyde::hasSiteUrl())
-
+ @if($post->getCanonicalUrl())
+
@endif