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) -