From 7efde93840f39df7f2ab02845ffdcaa457b49e1c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 12:53:05 +0100 Subject: [PATCH 01/44] Update deprecation message --- packages/testing/src/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 0cb042c9f06..866c6a5f6b6 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -48,7 +48,7 @@ protected function tearDown(): void parent::tearDown(); } - /** @deprecated as it's probably better to do this via the object constructor */ + /** @deprecated Will be removed as it's no longer part of the main package. */ protected function setupTestPublication(string $directory = 'test-publication') { Filesystem::copy('tests/fixtures/test-publication-schema.json', "$directory/schema.json"); From bbdcef547738d2849761538073294810c6601733 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 12:57:45 +0100 Subject: [PATCH 02/44] Replace fixture from deprecated testing method usage with generated type --- packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php index af821382f17..4772b72c2c9 100644 --- a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php +++ b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php @@ -151,7 +151,7 @@ public function testGet() public function testParse() { $this->directory('directory'); - $this->setupTestPublication('directory'); + (new PublicationType('directory'))->save(); Hyde::touch(\Hyde\Publications\Models\PublicationPage::sourcePath('directory/foo')); $this->assertInstanceOf(PublicationPage::class, PublicationPage::parse('directory/foo')); From 8aff23b02a804802d0bce7cf6121664d518ed2be Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:04:16 +0100 Subject: [PATCH 03/44] Replace deprecated test method with local helper --- .../tests/PublicationPageCompilerTest.php | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/publications/tests/PublicationPageCompilerTest.php b/packages/publications/tests/PublicationPageCompilerTest.php index 41eac32f233..28770057b71 100644 --- a/packages/publications/tests/PublicationPageCompilerTest.php +++ b/packages/publications/tests/PublicationPageCompilerTest.php @@ -4,6 +4,7 @@ namespace Hyde\Publications\Testing; +use Hyde\Facades\Filesystem; use function file_get_contents; use function file_put_contents; use Hyde\Framework\Exceptions\FileNotFoundException; @@ -23,8 +24,7 @@ class PublicationPageCompilerTest extends TestCase { public function test_can_compile_publication_pages() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); file_put_contents(Hyde::path('test-publication/detail.blade.php'), 'Detail: {{ $publication->title }}'); @@ -35,8 +35,7 @@ public function test_can_compile_publication_pages() public function test_can_compile_publication_list_pages() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); file_put_contents(Hyde::path('test-publication/my-publication.md'), 'Foo'); file_put_contents(Hyde::path('test-publication/list.blade.php'), 'List: {{ $publicationType->getPublications()->first()->title }}'); @@ -48,8 +47,7 @@ public function test_can_compile_publication_list_pages() public function test_can_compile_publication_pages_with_registered_view() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); $schema->detailTemplate = 'foo'; @@ -64,8 +62,7 @@ public function test_can_compile_publication_pages_with_registered_view() public function test_can_compile_publication_list_pages_with_registered_view() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); $schema->listTemplate = 'foo'; @@ -80,8 +77,7 @@ public function test_can_compile_publication_list_pages_with_registered_view() public function test_can_compile_publication_pages_with_registered_namespaced_view() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); $schema->detailTemplate = 'hyde-publications::publication_detail'; @@ -94,8 +90,7 @@ public function test_can_compile_publication_pages_with_registered_namespaced_vi public function test_can_compile_publication_list_pages_with_registered_namespaced_view() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); $this->file('vendor/hyde/framework/resources/views/layouts/test.blade.php', 'Registered list view'); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); @@ -110,8 +105,7 @@ public function test_can_compile_publication_list_pages_with_registered_namespac public function test_with_missing_detail_blade_view() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('File [test-publication/detail.blade.php] not found.'); @@ -121,12 +115,17 @@ public function test_with_missing_detail_blade_view() public function test_with_missing_list_blade_view() { - $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('File [test-publication/list.blade.php] not found.'); PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage()); } + + protected function copyTestPublicationFixture() + { + $this->directory('test-publication'); + Filesystem::copy('tests/fixtures/test-publication-schema.json', "test-publication/schema.json"); + } } From 496cdf1fdab20c2b740d7e9c97a02f2abdad0e52 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:05:44 +0100 Subject: [PATCH 04/44] Save new object instead of copying deprecated fixture --- packages/publications/tests/PublicationPageCompilerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/tests/PublicationPageCompilerTest.php b/packages/publications/tests/PublicationPageCompilerTest.php index 28770057b71..c5422a99354 100644 --- a/packages/publications/tests/PublicationPageCompilerTest.php +++ b/packages/publications/tests/PublicationPageCompilerTest.php @@ -126,6 +126,6 @@ public function test_with_missing_list_blade_view() protected function copyTestPublicationFixture() { $this->directory('test-publication'); - Filesystem::copy('tests/fixtures/test-publication-schema.json', "test-publication/schema.json"); + (new PublicationType('Test Publication'))->save(); } } From ad518f09e82578aa3666e065622e6c80eee7eb12 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:05:50 +0100 Subject: [PATCH 05/44] Rename local testing helper method --- .../tests/PublicationPageCompilerTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/publications/tests/PublicationPageCompilerTest.php b/packages/publications/tests/PublicationPageCompilerTest.php index c5422a99354..73759d9b62c 100644 --- a/packages/publications/tests/PublicationPageCompilerTest.php +++ b/packages/publications/tests/PublicationPageCompilerTest.php @@ -24,7 +24,7 @@ class PublicationPageCompilerTest extends TestCase { public function test_can_compile_publication_pages() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); file_put_contents(Hyde::path('test-publication/detail.blade.php'), 'Detail: {{ $publication->title }}'); @@ -35,7 +35,7 @@ public function test_can_compile_publication_pages() public function test_can_compile_publication_list_pages() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); file_put_contents(Hyde::path('test-publication/my-publication.md'), 'Foo'); file_put_contents(Hyde::path('test-publication/list.blade.php'), 'List: {{ $publicationType->getPublications()->first()->title }}'); @@ -47,7 +47,7 @@ public function test_can_compile_publication_list_pages() public function test_can_compile_publication_pages_with_registered_view() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); $schema->detailTemplate = 'foo'; @@ -62,7 +62,7 @@ public function test_can_compile_publication_pages_with_registered_view() public function test_can_compile_publication_list_pages_with_registered_view() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); $schema->listTemplate = 'foo'; @@ -77,7 +77,7 @@ public function test_can_compile_publication_list_pages_with_registered_view() public function test_can_compile_publication_pages_with_registered_namespaced_view() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); $schema->detailTemplate = 'hyde-publications::publication_detail'; @@ -90,7 +90,7 @@ public function test_can_compile_publication_pages_with_registered_namespaced_vi public function test_can_compile_publication_list_pages_with_registered_namespaced_view() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); $this->file('vendor/hyde/framework/resources/views/layouts/test.blade.php', 'Registered list view'); $schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json'))); @@ -105,7 +105,7 @@ public function test_can_compile_publication_list_pages_with_registered_namespac public function test_with_missing_detail_blade_view() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('File [test-publication/detail.blade.php] not found.'); @@ -115,7 +115,7 @@ public function test_with_missing_detail_blade_view() public function test_with_missing_list_blade_view() { - $this->copyTestPublicationFixture(); + $this->setupPublicationType(); $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('File [test-publication/list.blade.php] not found.'); @@ -123,7 +123,7 @@ public function test_with_missing_list_blade_view() PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage()); } - protected function copyTestPublicationFixture() + protected function setupPublicationType() { $this->directory('test-publication'); (new PublicationType('Test Publication'))->save(); From 94f94d289b1e2e5f163fe4f5ebb6dfd713d545ed Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:08:05 +0100 Subject: [PATCH 06/44] Clean up test fixture handling --- .../tests/PublicationPageTest.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/publications/tests/PublicationPageTest.php b/packages/publications/tests/PublicationPageTest.php index efc1745de9b..84559abca33 100644 --- a/packages/publications/tests/PublicationPageTest.php +++ b/packages/publications/tests/PublicationPageTest.php @@ -18,20 +18,6 @@ */ class PublicationPageTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); - - mkdir(Hyde::path('test-publication')); - } - - protected function tearDown(): void - { - Filesystem::deleteDirectory('test-publication'); - - parent::tearDown(); - } - public function test_source_path_mappings() { $this->createPublicationFiles(); @@ -113,6 +99,7 @@ public function test_identifier_normalizer_does_not_affect_directory_with_same_n protected function createRealPublicationFiles(): void { + $this->directory('test-publication'); file_put_contents(Hyde::path('test-publication/schema.json'), '{ "name": "test", "canonicalField": "slug", @@ -145,7 +132,9 @@ protected function createRealPublicationFiles(): void protected function createPublicationFiles(): void { - $this->setupTestPublication(); + $this->directory('test-publication'); + (new PublicationType('Test Publication'))->save(); + file_put_contents( Hyde::path('test-publication/foo.md'), '--- From f74e08dcec43ddae6f40affdf22297903fa1a2a6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:10:01 +0100 Subject: [PATCH 07/44] Add deprecated attribute --- packages/testing/src/TestCase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 866c6a5f6b6..c5de2cf571c 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -4,6 +4,7 @@ namespace Hyde\Testing; +use JetBrains\PhpStorm\Deprecated; use function file_get_contents; use Hyde\Facades\Features; use Hyde\Facades\Filesystem; @@ -49,6 +50,7 @@ protected function tearDown(): void } /** @deprecated Will be removed as it's no longer part of the main package. */ + #[Deprecated (reason: "Will be removed as it's no longer part of the main package. In most cases you can use the following replacement:", replacement: "(new PublicationType('Test Publication'))->save();")] protected function setupTestPublication(string $directory = 'test-publication') { Filesystem::copy('tests/fixtures/test-publication-schema.json', "$directory/schema.json"); From 59ee01cc11a468ede070dfe3b2fbbb85a34899a2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:11:43 +0100 Subject: [PATCH 08/44] Replace deprecated method usage with successor --- packages/publications/tests/SeedPublicationCommandTest.php | 4 ++-- packages/publications/tests/SeedsPublicationFilesTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/publications/tests/SeedPublicationCommandTest.php b/packages/publications/tests/SeedPublicationCommandTest.php index 3fc72a4cd59..03938f3a7b7 100644 --- a/packages/publications/tests/SeedPublicationCommandTest.php +++ b/packages/publications/tests/SeedPublicationCommandTest.php @@ -20,8 +20,8 @@ protected function setUp(): void parent::setUp(); $this->directory('test-publication'); - $this->setupTestPublication(); - $this->pubType = PublicationType::get('test-publication'); + $this->pubType = new PublicationType('Test Publication'); + $this->pubType->save(); } public function test_can_seed_publications() diff --git a/packages/publications/tests/SeedsPublicationFilesTest.php b/packages/publications/tests/SeedsPublicationFilesTest.php index 1e78b30acb3..21cef2d82c5 100644 --- a/packages/publications/tests/SeedsPublicationFilesTest.php +++ b/packages/publications/tests/SeedsPublicationFilesTest.php @@ -24,8 +24,8 @@ protected function setUp(): void parent::setUp(); $this->directory('test-publication'); - $this->setupTestPublication(); - $this->pubType = PublicationType::get('test-publication'); + $this->pubType = new PublicationType('Test Publication'); + $this->pubType->save(); } public function testCreate() From 846ccf6249d4f7d67df201fdd0ab428e550b9367 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:12:23 +0100 Subject: [PATCH 09/44] Remove schema disk write for test that doesn't need it --- packages/publications/tests/SeedsPublicationFilesTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/publications/tests/SeedsPublicationFilesTest.php b/packages/publications/tests/SeedsPublicationFilesTest.php index 21cef2d82c5..5a66b635d5c 100644 --- a/packages/publications/tests/SeedsPublicationFilesTest.php +++ b/packages/publications/tests/SeedsPublicationFilesTest.php @@ -25,7 +25,6 @@ protected function setUp(): void $this->directory('test-publication'); $this->pubType = new PublicationType('Test Publication'); - $this->pubType->save(); } public function testCreate() From dc2487acaa09c9516f7da8799d9af3284a6dc18a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:14:34 +0100 Subject: [PATCH 10/44] Create new object instead of using deprecated fixture --- .../tests/ValidatePublicationsCommandTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/publications/tests/ValidatePublicationsCommandTest.php b/packages/publications/tests/ValidatePublicationsCommandTest.php index 515e524e3be..d8385188fb4 100644 --- a/packages/publications/tests/ValidatePublicationsCommandTest.php +++ b/packages/publications/tests/ValidatePublicationsCommandTest.php @@ -4,6 +4,7 @@ namespace Hyde\Publications\Testing; +use Hyde\Publications\Models\PublicationType; use function copy; use Hyde\Hyde; use Hyde\Testing\TestCase; @@ -87,8 +88,8 @@ public function testWithMultiplePublicationTypes() { $this->directory('test-publication'); $this->directory('test-publication-two'); - $this->setupTestPublication(); - $this->setupTestPublication('test-publication-two'); + (new PublicationType('Test Publication'))->save(); + (new PublicationType('Test Publication Two'))->save(); $this->artisan('validate:publications') ->expectsOutput('Validating publication type [test-publication-two]') @@ -100,8 +101,8 @@ public function testOnlySpecifiedTypeIsValidatedWhenUsingArgument() { $this->directory('test-publication'); $this->directory('test-publication-two'); - $this->setupTestPublication(); - $this->setupTestPublication('test-publication-two'); + (new PublicationType('Test Publication'))->save(); + (new PublicationType('Test Publication Two'))->save(); $this->artisan('validate:publications test-publication-two') ->expectsOutput('Validating publication type [test-publication-two]') From 5e8a2dac5a5ef5dcd098dea23e4088e1df227fc6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:15:07 +0100 Subject: [PATCH 11/44] Extract method --- .../tests/ValidatePublicationsCommandTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/publications/tests/ValidatePublicationsCommandTest.php b/packages/publications/tests/ValidatePublicationsCommandTest.php index d8385188fb4..9a7f16d9e9d 100644 --- a/packages/publications/tests/ValidatePublicationsCommandTest.php +++ b/packages/publications/tests/ValidatePublicationsCommandTest.php @@ -88,8 +88,8 @@ public function testWithMultiplePublicationTypes() { $this->directory('test-publication'); $this->directory('test-publication-two'); - (new PublicationType('Test Publication'))->save(); - (new PublicationType('Test Publication Two'))->save(); + $this->savePublication('Test Publication'); + $this->savePublication('Test Publication Two'); $this->artisan('validate:publications') ->expectsOutput('Validating publication type [test-publication-two]') @@ -101,12 +101,17 @@ public function testOnlySpecifiedTypeIsValidatedWhenUsingArgument() { $this->directory('test-publication'); $this->directory('test-publication-two'); - (new PublicationType('Test Publication'))->save(); - (new PublicationType('Test Publication Two'))->save(); + $this->savePublication('Test Publication'); + $this->savePublication('Test Publication Two'); $this->artisan('validate:publications test-publication-two') ->expectsOutput('Validating publication type [test-publication-two]') ->doesntExpectOutput('Validating publication type [test-publication]') ->assertExitCode(0); } + + protected function savePublication(string $name): void + { + (new PublicationType($name))->save(); + } } From fbb991faf4800314d89f450e52f1b52cde3fb8fd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:17:11 +0100 Subject: [PATCH 12/44] Inline test fixture --- .../tests/ValidatePublicationsCommandTest.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/publications/tests/ValidatePublicationsCommandTest.php b/packages/publications/tests/ValidatePublicationsCommandTest.php index 9a7f16d9e9d..62fcfc1a481 100644 --- a/packages/publications/tests/ValidatePublicationsCommandTest.php +++ b/packages/publications/tests/ValidatePublicationsCommandTest.php @@ -8,6 +8,7 @@ use function copy; use Hyde\Hyde; use Hyde\Testing\TestCase; +use function file_put_contents; /** * @covers \Hyde\Publications\Commands\ValidatePublicationsCommand @@ -31,7 +32,7 @@ public function testWithInvalidPublicationType() public function testWithPublicationType() { $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); copy(Hyde::path('tests/fixtures/test-publication.md'), Hyde::path('test-publication/test.md')); $this->artisan('validate:publications') @@ -48,7 +49,7 @@ public function testWithPublicationType() public function testWithPublicationTypeAndVerboseOutput() { $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); copy(Hyde::path('tests/fixtures/test-publication.md'), Hyde::path('test-publication/test.md')); $this->artisan('validate:publications', ['--verbose' => true]) @@ -65,7 +66,7 @@ public function testWithPublicationTypeAndVerboseOutput() public function testWithInvalidPublication() { $this->directory('test-publication'); - $this->setupTestPublication(); + $this->copyTestPublicationFixture(); file_put_contents(Hyde::path('test-publication/test.md'), '--- Foo: bar --- @@ -110,6 +111,28 @@ public function testOnlySpecifiedTypeIsValidatedWhenUsingArgument() ->assertExitCode(0); } + protected function copyTestPublicationFixture(): void + { + file_put_contents(Hyde::path('test-publication/schema.json'), <<<'JSON' + { + "name": "Test Publication", + "canonicalField": "title", + "detailTemplate": "detail.blade.php", + "listTemplate": "list.blade.php", + "sortField": "__createdAt", + "sortAscending": true, + "pageSize": 25, + "fields": [ + { + "name": "title", + "type": "string" + } + ] + } + JSON + ); + } + protected function savePublication(string $name): void { (new PublicationType($name))->save(); From 18a8c8ee1131ffb696a58743dbbf0891cab50f71 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 12:17:30 +0000 Subject: [PATCH 13/44] Apply fixes from StyleCI --- packages/publications/tests/PublicationPageCompilerTest.php | 1 - packages/publications/tests/PublicationPageTest.php | 2 -- .../publications/tests/ValidatePublicationsCommandTest.php | 4 ++-- packages/testing/src/TestCase.php | 4 ++-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/publications/tests/PublicationPageCompilerTest.php b/packages/publications/tests/PublicationPageCompilerTest.php index 73759d9b62c..44415700566 100644 --- a/packages/publications/tests/PublicationPageCompilerTest.php +++ b/packages/publications/tests/PublicationPageCompilerTest.php @@ -4,7 +4,6 @@ namespace Hyde\Publications\Testing; -use Hyde\Facades\Filesystem; use function file_get_contents; use function file_put_contents; use Hyde\Framework\Exceptions\FileNotFoundException; diff --git a/packages/publications/tests/PublicationPageTest.php b/packages/publications/tests/PublicationPageTest.php index 84559abca33..9b6c5cf9e5d 100644 --- a/packages/publications/tests/PublicationPageTest.php +++ b/packages/publications/tests/PublicationPageTest.php @@ -5,13 +5,11 @@ namespace Hyde\Publications\Testing; use function file_put_contents; -use Hyde\Facades\Filesystem; use Hyde\Hyde; use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\Models\PublicationType; use Hyde\Support\Models\Route; use Hyde\Testing\TestCase; -use function mkdir; /** * @covers \Hyde\Publications\Models\PublicationPage diff --git a/packages/publications/tests/ValidatePublicationsCommandTest.php b/packages/publications/tests/ValidatePublicationsCommandTest.php index 62fcfc1a481..12ae7ad5447 100644 --- a/packages/publications/tests/ValidatePublicationsCommandTest.php +++ b/packages/publications/tests/ValidatePublicationsCommandTest.php @@ -4,11 +4,11 @@ namespace Hyde\Publications\Testing; -use Hyde\Publications\Models\PublicationType; use function copy; +use function file_put_contents; use Hyde\Hyde; +use Hyde\Publications\Models\PublicationType; use Hyde\Testing\TestCase; -use function file_put_contents; /** * @covers \Hyde\Publications\Commands\ValidatePublicationsCommand diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index c5de2cf571c..04c5ca49a5d 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -4,13 +4,13 @@ namespace Hyde\Testing; -use JetBrains\PhpStorm\Deprecated; use function file_get_contents; use Hyde\Facades\Features; use Hyde\Facades\Filesystem; use Hyde\Hyde; use function Hyde\normalize_newlines; use Illuminate\View\Component; +use JetBrains\PhpStorm\Deprecated; use LaravelZero\Framework\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase @@ -50,7 +50,7 @@ protected function tearDown(): void } /** @deprecated Will be removed as it's no longer part of the main package. */ - #[Deprecated (reason: "Will be removed as it's no longer part of the main package. In most cases you can use the following replacement:", replacement: "(new PublicationType('Test Publication'))->save();")] + #[Deprecated(reason: "Will be removed as it's no longer part of the main package. In most cases you can use the following replacement:", replacement: "(new PublicationType('Test Publication'))->save();")] protected function setupTestPublication(string $directory = 'test-publication') { Filesystem::copy('tests/fixtures/test-publication-schema.json', "$directory/schema.json"); From 97ab59754faf1b596f9fdaab61792e8369e1bc3f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 13:17:38 +0100 Subject: [PATCH 14/44] Remove now unused internal deprecated test helper setupTestPublication --- packages/testing/src/TestCase.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index c5de2cf571c..d6f237e2ada 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -49,13 +49,6 @@ protected function tearDown(): void parent::tearDown(); } - /** @deprecated Will be removed as it's no longer part of the main package. */ - #[Deprecated (reason: "Will be removed as it's no longer part of the main package. In most cases you can use the following replacement:", replacement: "(new PublicationType('Test Publication'))->save();")] - protected function setupTestPublication(string $directory = 'test-publication') - { - Filesystem::copy('tests/fixtures/test-publication-schema.json', "$directory/schema.json"); - } - protected function assertFileEqualsString(string $string, string $path, bool $strict = false): void { if ($strict) { From dcf4b8d014ea2e3dcfeefec8473c7813974cd068 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 12:18:49 +0000 Subject: [PATCH 15/44] Apply fixes from StyleCI --- packages/testing/src/TestCase.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index d6f237e2ada..d13bb8fb4cd 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -4,10 +4,8 @@ namespace Hyde\Testing; -use JetBrains\PhpStorm\Deprecated; use function file_get_contents; use Hyde\Facades\Features; -use Hyde\Facades\Filesystem; use Hyde\Hyde; use function Hyde\normalize_newlines; use Illuminate\View\Component; From cf9083ea358e1fea0d309a927d791ba80b7c9a3d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 15:35:24 +0100 Subject: [PATCH 16/44] Create PublicationsExtension.php --- packages/publications/src/PublicationsExtension.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 packages/publications/src/PublicationsExtension.php diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php new file mode 100644 index 00000000000..f50f82001ad --- /dev/null +++ b/packages/publications/src/PublicationsExtension.php @@ -0,0 +1,12 @@ + Date: Wed, 11 Jan 2023 15:35:35 +0100 Subject: [PATCH 17/44] Register the publications extension --- packages/publications/src/PublicationsServiceProvider.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/publications/src/PublicationsServiceProvider.php b/packages/publications/src/PublicationsServiceProvider.php index cc5618b119d..50148162da4 100644 --- a/packages/publications/src/PublicationsServiceProvider.php +++ b/packages/publications/src/PublicationsServiceProvider.php @@ -4,6 +4,7 @@ namespace Hyde\Publications; +use Hyde\Foundation\HydeKernel; use Hyde\Publications\Providers\TranslationServiceProvider; use Illuminate\Support\ServiceProvider; use Illuminate\Validation\ValidationServiceProvider; @@ -15,6 +16,8 @@ class PublicationsServiceProvider extends ServiceProvider */ public function register(): void { + $this->app->make(HydeKernel::class)->registerExtension(PublicationsExtension::class); + $this->commands([ Commands\MakePublicationTagCommand::class, Commands\MakePublicationTypeCommand::class, From 939b0700bc9fd6a68d6ea6ef8d4318f918c3a920 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 15:36:29 +0100 Subject: [PATCH 18/44] Move publication page discovery logic to extension handler --- .../src/Foundation/PageCollection.php | 48 --------------- .../src/PublicationsExtension.php | 60 ++++++++++++++++++- 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 127c2437fd8..8b4a533a65a 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -89,10 +89,6 @@ protected function runDiscovery(): self $this->discoverPagesFor(DocumentationPage::class); } - if (Features::hasPublicationPages()) { - $this->discoverPublicationPages(); - } - foreach ($this->kernel->getRegisteredPageClasses() as $pageClass) { $this->discoverPagesFor($pageClass); } @@ -127,48 +123,4 @@ protected function parsePagesFor(string $pageClass): Collection return $collection; } - - protected function discoverPublicationPages(): void - { - PublicationService::getPublicationTypes()->each(function (PublicationType $type): void { - $this->discoverPublicationPagesForType($type); - $this->generatePublicationListingPageForType($type); - }); - } - - protected function discoverPublicationPagesForType(PublicationType $type): void - { - PublicationService::getPublicationsForPubType($type)->each(function (PublicationPage $publication): void { - $this->addPage($publication); - }); - } - - protected function generatePublicationListingPageForType(PublicationType $type): void - { - $page = new PublicationListPage($type); - $this->put($page->getSourcePath(), $page); - - if ($type->usesPagination()) { - $this->generatePublicationPaginatedListingPagesForType($type); - } - } - - /** - * @deprecated This method will be removed before merging into master. - * - * @internal This method will be removed before merging into master. - */ - protected function generatePublicationPaginatedListingPagesForType(PublicationType $type): void - { - $paginator = $type->getPaginator(); - - foreach (range(1, $paginator->totalPages()) as $page) { - $paginator->setCurrentPage($page); - $listingPage = new VirtualPage("{$type->getDirectory()}/page-$page", [ - 'publicationType' => $type, 'paginatorPage' => $page, - 'title' => $type->name.' - Page '.$page, - ], view: $type->listTemplate); - $this->put($listingPage->getSourcePath(), $listingPage); - } - } } diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php index f50f82001ad..6be1ee7c627 100644 --- a/packages/publications/src/PublicationsExtension.php +++ b/packages/publications/src/PublicationsExtension.php @@ -5,8 +5,66 @@ namespace Hyde\Publications; use Hyde\Foundation\Extensions\HydeExtension; +use Hyde\Foundation\PageCollection; +use Hyde\Pages\VirtualPage; +use Hyde\Publications\Models\PublicationListPage; +use Hyde\Publications\Models\PublicationPage; +use Hyde\Publications\Models\PublicationType; + +use function range; class PublicationsExtension extends HydeExtension { - // + public static function discoverPages(PageCollection $collection): void + { + static::discoverPublicationPages($collection); + } + + protected static function discoverPublicationPages(PageCollection $instance): void + { + PublicationService::getPublicationTypes()->each(function (PublicationType $type) use ($instance): void { + static::discoverPublicationPagesForType($type, $instance); + static::generatePublicationListingPageForType($type, $instance); + }); + } + + protected static function discoverPublicationPagesForType(PublicationType $type, PageCollection $instance): void + { + PublicationService::getPublicationsForPubType($type)->each(function (PublicationPage $publication) use ( + $instance + ): void { + $instance->addPage($publication); + }); + } + + protected static function generatePublicationListingPageForType(PublicationType $type, PageCollection $instance): void + { + $page = new PublicationListPage($type); + $instance->put($page->getSourcePath(), $page); + + if ($type->usesPagination()) { + static::generatePublicationPaginatedListingPagesForType($type, $instance); + } + } + + /** + * @deprecated This method will be removed before merging into master. + * + * @internal This method will be removed before merging into master. + */ + protected static function generatePublicationPaginatedListingPagesForType(PublicationType $type, + PageCollection $instance + ): void + { + $paginator = $type->getPaginator(); + + foreach (range(1, $paginator->totalPages()) as $page) { + $paginator->setCurrentPage($page); + $listingPage = new VirtualPage("{$type->getDirectory()}/page-$page", [ + 'publicationType' => $type, 'paginatorPage' => $page, + 'title' => $type->name.' - Page '.$page, + ], view: $type->listTemplate); + $instance->put($listingPage->getSourcePath(), $listingPage); + } + } } From cdc128f2597d7177257a7db5e2412c8b81b106fe Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 14:37:40 +0000 Subject: [PATCH 19/44] Apply fixes from StyleCI --- packages/framework/src/Foundation/PageCollection.php | 5 ----- packages/publications/src/PublicationsExtension.php | 4 +--- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 8b4a533a65a..1dd3843a3bd 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -13,11 +13,6 @@ use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; -use Hyde\Pages\VirtualPage; -use Hyde\Publications\Models\PublicationListPage; -use Hyde\Publications\Models\PublicationPage; -use Hyde\Publications\Models\PublicationType; -use Hyde\Publications\PublicationService; use Illuminate\Support\Collection; /** diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php index 6be1ee7c627..90b9bcc6b1b 100644 --- a/packages/publications/src/PublicationsExtension.php +++ b/packages/publications/src/PublicationsExtension.php @@ -10,7 +10,6 @@ use Hyde\Publications\Models\PublicationListPage; use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\Models\PublicationType; - use function range; class PublicationsExtension extends HydeExtension @@ -54,8 +53,7 @@ protected static function generatePublicationListingPageForType(PublicationType */ protected static function generatePublicationPaginatedListingPagesForType(PublicationType $type, PageCollection $instance - ): void - { + ): void { $paginator = $type->getPaginator(); foreach (range(1, $paginator->totalPages()) as $page) { From fbef5f8cb64bf834dc5bd2e447cf6136e985b6fc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 15:44:52 +0100 Subject: [PATCH 20/44] Create PublicationDiscoveryTest.php --- .../tests/PublicationDiscoveryTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/publications/tests/PublicationDiscoveryTest.php diff --git a/packages/publications/tests/PublicationDiscoveryTest.php b/packages/publications/tests/PublicationDiscoveryTest.php new file mode 100644 index 00000000000..4c33ee2074b --- /dev/null +++ b/packages/publications/tests/PublicationDiscoveryTest.php @@ -0,0 +1,16 @@ + Date: Wed, 11 Jan 2023 15:45:35 +0100 Subject: [PATCH 21/44] Move publication page discovery to its own test --- .../tests/Feature/PageCollectionTest.php | 43 ---------------- .../tests/PublicationDiscoveryTest.php | 50 ++++++++++++++++++- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 944dc63e06b..e3feb76092c 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Testing\Feature; -use function copy; use Hyde\Foundation\HydeKernel; use Hyde\Foundation\PageCollection; use Hyde\Hyde; @@ -13,8 +12,6 @@ use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; -use Hyde\Publications\Models\PublicationListPage; -use Hyde\Publications\Models\PublicationPage; use Hyde\Testing\TestCase; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; @@ -183,44 +180,4 @@ public function test_pages_with_custom_source_directories_are_discovered_properl File::deleteDirectory(Hyde::path('.source')); } - - public function test_publication_pages_are_discovered() - { - mkdir(Hyde::path('publication')); - $this->createPublication(); - - $collection = PageCollection::boot(Hyde::getInstance())->getPages(); - $this->assertCount(4, $collection); // Default pages + publication index + publication page - $this->assertInstanceOf(PublicationPage::class, $collection->get('publication/foo.md')); - - File::deleteDirectory(Hyde::path('publication')); - } - - public function test_listing_pages_for_publications_are_discovered() - { - mkdir(Hyde::path('publication')); - $this->createPublication(); - - $this->assertInstanceOf( - PublicationListPage::class, - PageCollection::boot(Hyde::getInstance())->getPage('publication/index') - ); - - File::deleteDirectory(Hyde::path('publication')); - } - - protected function createPublication(): void - { - copy(Hyde::path('tests/fixtures/test-publication-schema.json'), Hyde::path('publication/schema.json')); - file_put_contents(Hyde::path('publication/foo.md'), - '--- -__canonical: canonical -__createdAt: 2022-11-16 11:32:52 -foo: bar ---- - -Hello World! -' - ); - } } diff --git a/packages/publications/tests/PublicationDiscoveryTest.php b/packages/publications/tests/PublicationDiscoveryTest.php index 4c33ee2074b..b5e14fc7b99 100644 --- a/packages/publications/tests/PublicationDiscoveryTest.php +++ b/packages/publications/tests/PublicationDiscoveryTest.php @@ -4,13 +4,61 @@ namespace Hyde\Publications\Testing; +use Hyde\Foundation\PageCollection; +use Hyde\Hyde; +use Hyde\Publications\Models\PublicationListPage; +use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\PublicationsExtension; use Hyde\Testing\TestCase; +use Illuminate\Support\Facades\File; + +use function copy; +use function file_put_contents; +use function mkdir; /** * @covers \Hyde\Publications\PublicationsExtension */ class PublicationDiscoveryTest extends TestCase { - // + + public function test_publication_pages_are_discovered() + { + mkdir(Hyde::path('publication')); + $this->createPublication(); + + $collection = PageCollection::boot(Hyde::getInstance())->getPages(); + $this->assertCount(4, $collection); // Default pages + publication index + publication page + $this->assertInstanceOf(PublicationPage::class, $collection->get('publication/foo.md')); + + File::deleteDirectory(Hyde::path('publication')); + } + + public function test_listing_pages_for_publications_are_discovered() + { + mkdir(Hyde::path('publication')); + $this->createPublication(); + + $this->assertInstanceOf( + PublicationListPage::class, + PageCollection::boot(Hyde::getInstance())->getPage('publication/index') + ); + + File::deleteDirectory(Hyde::path('publication')); + } + + protected function createPublication(): void + { + copy(Hyde::path('tests/fixtures/test-publication-schema.json'), Hyde::path('publication/schema.json')); + file_put_contents(Hyde::path('publication/foo.md'), + '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +' + ); + } } From 5ac8a069969f3fe243b7737928ef4af132a68e7a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 14:45:48 +0000 Subject: [PATCH 22/44] Apply fixes from StyleCI --- packages/publications/tests/PublicationDiscoveryTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/publications/tests/PublicationDiscoveryTest.php b/packages/publications/tests/PublicationDiscoveryTest.php index b5e14fc7b99..5654481a7dc 100644 --- a/packages/publications/tests/PublicationDiscoveryTest.php +++ b/packages/publications/tests/PublicationDiscoveryTest.php @@ -4,16 +4,14 @@ namespace Hyde\Publications\Testing; +use function copy; +use function file_put_contents; use Hyde\Foundation\PageCollection; use Hyde\Hyde; use Hyde\Publications\Models\PublicationListPage; use Hyde\Publications\Models\PublicationPage; -use Hyde\Publications\PublicationsExtension; use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; - -use function copy; -use function file_put_contents; use function mkdir; /** @@ -21,7 +19,6 @@ */ class PublicationDiscoveryTest extends TestCase { - public function test_publication_pages_are_discovered() { mkdir(Hyde::path('publication')); From e5a0a87d2f8aa678e93ed452ef36698322726477 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 15:59:47 +0100 Subject: [PATCH 23/44] Move test to package suite --- .../tests/Feature/SourceFileParserTest.php | 18 ---------------- .../tests/PublicationPageTest.php | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/framework/tests/Feature/SourceFileParserTest.php b/packages/framework/tests/Feature/SourceFileParserTest.php index 58938ebfd1e..f0daa38f87c 100644 --- a/packages/framework/tests/Feature/SourceFileParserTest.php +++ b/packages/framework/tests/Feature/SourceFileParserTest.php @@ -77,24 +77,6 @@ public function test_html_page_parser() $this->assertEquals('

Foo Bar

', $page->contents()); } - public function test_publication_parser() - { - mkdir(Hyde::path('test-publication')); - copy(Hyde::path('tests/fixtures/test-publication-schema.json'), Hyde::path('test-publication/schema.json')); - copy(Hyde::path('tests/fixtures/test-publication.md'), Hyde::path('test-publication/foo.md')); - - $parser = new SourceFileParser(PublicationPage::class, 'test-publication/foo'); - $page = $parser->get(); - $this->assertInstanceOf(PublicationPage::class, $page); - $this->assertEquals('test-publication/foo', $page->identifier); - $this->assertEquals('## Write something awesome.', $page->markdown); - $this->assertEquals('My Title', $page->title); - $this->assertEquals('My Title', $page->matter->get('title')); - $this->assertTrue($page->matter->has('__createdAt')); - - Filesystem::deleteDirectory('test-publication'); - } - public function test_parsed_page_is_run_through_dynamic_constructor() { $this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'Foo Bar Baz']); diff --git a/packages/publications/tests/PublicationPageTest.php b/packages/publications/tests/PublicationPageTest.php index 9b6c5cf9e5d..2d1e5fa4355 100644 --- a/packages/publications/tests/PublicationPageTest.php +++ b/packages/publications/tests/PublicationPageTest.php @@ -4,12 +4,16 @@ namespace Hyde\Publications\Testing; +use Hyde\Facades\Filesystem; +use Hyde\Framework\Actions\SourceFileParser; +use function copy; use function file_put_contents; use Hyde\Hyde; use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\Models\PublicationType; use Hyde\Support\Models\Route; use Hyde\Testing\TestCase; +use function mkdir; /** * @covers \Hyde\Publications\Models\PublicationPage @@ -62,6 +66,23 @@ public function test_publication_pages_are_properly_parsed() $this->assertEquals('Hello World!', $page->markdown()->body()); } + public function test_publication_pages_are_parsable() + { + mkdir(Hyde::path('test-publication')); + copy(Hyde::path('tests/fixtures/test-publication-schema.json'), Hyde::path('test-publication/schema.json')); + copy(Hyde::path('tests/fixtures/test-publication.md'), Hyde::path('test-publication/foo.md')); + + $page = (PublicationPage::parse('test-publication/foo')); + $this->assertInstanceOf(PublicationPage::class, $page); + $this->assertEquals('test-publication/foo', $page->identifier); + $this->assertEquals('## Write something awesome.', $page->markdown); + $this->assertEquals('My Title', $page->title); + $this->assertEquals('My Title', $page->matter->get('title')); + $this->assertTrue($page->matter->has('__createdAt')); + + Filesystem::deleteDirectory('test-publication'); + } + public function test_publication_pages_are_compilable() { $this->createRealPublicationFiles(); From 7bd7793812c6d3081171cffbee3e21454f59090d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 16:04:38 +0100 Subject: [PATCH 24/44] Inline parsing logic for publication pages --- .../Framework/Actions/SourceFileParser.php | 19 --------------- .../src/Models/PublicationPage.php | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/framework/src/Framework/Actions/SourceFileParser.php b/packages/framework/src/Framework/Actions/SourceFileParser.php index d13cb498f35..31a23c981fe 100644 --- a/packages/framework/src/Framework/Actions/SourceFileParser.php +++ b/packages/framework/src/Framework/Actions/SourceFileParser.php @@ -46,10 +46,6 @@ protected function constructPage(string $pageClass): HydePage|BladePage|BaseMark return $this->parseBladePage(); } - if ($pageClass === PublicationPage::class) { - return $this->parsePublicationPage(); - } - if (is_subclass_of($pageClass, BaseMarkdownPage::class)) { return $this->parseMarkdownPage($pageClass); } @@ -57,21 +53,6 @@ protected function constructPage(string $pageClass): HydePage|BladePage|BaseMark return new $pageClass($this->identifier); } - protected function parsePublicationPage(): PublicationPage - { - /** @var \Hyde\Pages\Concerns\BaseMarkdownPage $pageClass */ - $document = MarkdownFileParser::parse( - PublicationPage::sourcePath($this->identifier) - ); - - return new PublicationPage( - identifier: $this->identifier, - matter: $document->matter, - markdown: $document->markdown, - type: PublicationType::get(Str::before($this->identifier, '/')) - ); - } - protected function parseBladePage(): BladePage { return new BladePage( diff --git a/packages/publications/src/Models/PublicationPage.php b/packages/publications/src/Models/PublicationPage.php index d412005e1be..467bac08521 100644 --- a/packages/publications/src/Models/PublicationPage.php +++ b/packages/publications/src/Models/PublicationPage.php @@ -4,11 +4,15 @@ namespace Hyde\Publications\Models; +use Hyde\Framework\Actions\MarkdownFileParser; +use Hyde\Framework\Concerns\ValidatesExistence; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Hyde\Pages\Concerns; use Hyde\Pages\Contracts\DynamicPage; use Hyde\Publications\Actions\PublicationPageCompiler; +use Illuminate\Support\Str; + use function str_starts_with; /** @@ -19,6 +23,8 @@ */ class PublicationPage extends Concerns\BaseMarkdownPage implements DynamicPage { + use ValidatesExistence; + public PublicationType $type; public static string $sourceDirectory = ''; @@ -42,6 +48,23 @@ public function compile(): string return $this->renderComponent(); } + public static function parse(string $identifier): self + { + static::validateExistence(static::class, $identifier); + + /** @var \Hyde\Pages\Concerns\BaseMarkdownPage $pageClass */ + $document = MarkdownFileParser::parse( + PublicationPage::sourcePath($identifier) + ); + + return new PublicationPage( + identifier: $identifier, + matter: $document->matter, + markdown: $document->markdown, + type: PublicationType::get(Str::before($identifier, '/')) + ); + } + protected function renderComponent(): string { return PublicationPageCompiler::call($this); From abfaea8092afd35c19dc428f6919427879691268 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 15:04:55 +0000 Subject: [PATCH 25/44] Apply fixes from StyleCI --- packages/framework/src/Framework/Actions/SourceFileParser.php | 3 --- packages/framework/tests/Feature/SourceFileParserTest.php | 3 --- packages/publications/src/Models/PublicationPage.php | 1 - packages/publications/tests/PublicationPageTest.php | 3 +-- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/framework/src/Framework/Actions/SourceFileParser.php b/packages/framework/src/Framework/Actions/SourceFileParser.php index 31a23c981fe..86cde6b13ed 100644 --- a/packages/framework/src/Framework/Actions/SourceFileParser.php +++ b/packages/framework/src/Framework/Actions/SourceFileParser.php @@ -8,9 +8,6 @@ use Hyde\Pages\BladePage; use Hyde\Pages\Concerns\BaseMarkdownPage; use Hyde\Pages\Concerns\HydePage; -use Hyde\Publications\Models\PublicationPage; -use Hyde\Publications\Models\PublicationType; -use Illuminate\Support\Str; /** * Parses a source file and returns a new page model instance for it. diff --git a/packages/framework/tests/Feature/SourceFileParserTest.php b/packages/framework/tests/Feature/SourceFileParserTest.php index f0daa38f87c..d58408b757d 100644 --- a/packages/framework/tests/Feature/SourceFileParserTest.php +++ b/packages/framework/tests/Feature/SourceFileParserTest.php @@ -4,15 +4,12 @@ namespace Hyde\Framework\Testing\Feature; -use Hyde\Facades\Filesystem; use Hyde\Framework\Actions\SourceFileParser; -use Hyde\Hyde; use Hyde\Pages\BladePage; use Hyde\Pages\DocumentationPage; use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; -use Hyde\Publications\Models\PublicationPage; use Hyde\Testing\TestCase; /** diff --git a/packages/publications/src/Models/PublicationPage.php b/packages/publications/src/Models/PublicationPage.php index 467bac08521..ff6409a4cc4 100644 --- a/packages/publications/src/Models/PublicationPage.php +++ b/packages/publications/src/Models/PublicationPage.php @@ -12,7 +12,6 @@ use Hyde\Pages\Contracts\DynamicPage; use Hyde\Publications\Actions\PublicationPageCompiler; use Illuminate\Support\Str; - use function str_starts_with; /** diff --git a/packages/publications/tests/PublicationPageTest.php b/packages/publications/tests/PublicationPageTest.php index 2d1e5fa4355..c63eeac7214 100644 --- a/packages/publications/tests/PublicationPageTest.php +++ b/packages/publications/tests/PublicationPageTest.php @@ -4,10 +4,9 @@ namespace Hyde\Publications\Testing; -use Hyde\Facades\Filesystem; -use Hyde\Framework\Actions\SourceFileParser; use function copy; use function file_put_contents; +use Hyde\Facades\Filesystem; use Hyde\Hyde; use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\Models\PublicationType; From 26631a79a406600535d1591dc36b870ed5f02223 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 16:23:28 +0100 Subject: [PATCH 26/44] Clean up test by using helper methods --- packages/publications/tests/PublicationDiscoveryTest.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/publications/tests/PublicationDiscoveryTest.php b/packages/publications/tests/PublicationDiscoveryTest.php index 5654481a7dc..279a5fccdd5 100644 --- a/packages/publications/tests/PublicationDiscoveryTest.php +++ b/packages/publications/tests/PublicationDiscoveryTest.php @@ -21,27 +21,23 @@ class PublicationDiscoveryTest extends TestCase { public function test_publication_pages_are_discovered() { - mkdir(Hyde::path('publication')); + $this->directory('publication'); $this->createPublication(); $collection = PageCollection::boot(Hyde::getInstance())->getPages(); $this->assertCount(4, $collection); // Default pages + publication index + publication page $this->assertInstanceOf(PublicationPage::class, $collection->get('publication/foo.md')); - - File::deleteDirectory(Hyde::path('publication')); } public function test_listing_pages_for_publications_are_discovered() { - mkdir(Hyde::path('publication')); + $this->directory('publication'); $this->createPublication(); $this->assertInstanceOf( PublicationListPage::class, PageCollection::boot(Hyde::getInstance())->getPage('publication/index') ); - - File::deleteDirectory(Hyde::path('publication')); } protected function createPublication(): void From 9b024ffa60d17365113948b87013637bd37bf7ff Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 16:25:02 +0100 Subject: [PATCH 27/44] Change service helper to parse via model instead of action --- packages/publications/src/PublicationService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/PublicationService.php b/packages/publications/src/PublicationService.php index 0fc81c05932..2ad3b0eb3d9 100644 --- a/packages/publications/src/PublicationService.php +++ b/packages/publications/src/PublicationService.php @@ -79,7 +79,7 @@ public static function getValuesForTagName(string $tagName): Collection */ public static function parsePublicationFile(string $identifier): PublicationPage { - return (new SourceFileParser(PublicationPage::class, Str::replaceLast('.md', '', $identifier)))->get(); + return PublicationPage::parse(Str::replaceLast('.md', '', $identifier)); } /** From 62fe0802c3a1efe0e357d6cb914d98da98d1d1e0 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 15:25:16 +0000 Subject: [PATCH 28/44] Apply fixes from StyleCI --- packages/publications/src/PublicationService.php | 1 - packages/publications/tests/PublicationDiscoveryTest.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/packages/publications/src/PublicationService.php b/packages/publications/src/PublicationService.php index 2ad3b0eb3d9..8417c84c57f 100644 --- a/packages/publications/src/PublicationService.php +++ b/packages/publications/src/PublicationService.php @@ -5,7 +5,6 @@ namespace Hyde\Publications; use function glob; -use Hyde\Framework\Actions\SourceFileParser; use Hyde\Hyde; use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\Models\PublicationTags; diff --git a/packages/publications/tests/PublicationDiscoveryTest.php b/packages/publications/tests/PublicationDiscoveryTest.php index 279a5fccdd5..45f08ece787 100644 --- a/packages/publications/tests/PublicationDiscoveryTest.php +++ b/packages/publications/tests/PublicationDiscoveryTest.php @@ -11,8 +11,6 @@ use Hyde\Publications\Models\PublicationListPage; use Hyde\Publications\Models\PublicationPage; use Hyde\Testing\TestCase; -use Illuminate\Support\Facades\File; -use function mkdir; /** * @covers \Hyde\Publications\PublicationsExtension From 57de34835b12025ac4ba9e7a30c647f8573b9628 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 18:02:27 +0100 Subject: [PATCH 29/44] Move and decouple unit test --- .../tests}/PublicationPageUnitTest.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) rename packages/{framework/tests/Unit/Pages => publications/tests}/PublicationPageUnitTest.php (89%) diff --git a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php b/packages/publications/tests/PublicationPageUnitTest.php similarity index 89% rename from packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php rename to packages/publications/tests/PublicationPageUnitTest.php index b978b8786b8..03a786bb4f4 100644 --- a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php +++ b/packages/publications/tests/PublicationPageUnitTest.php @@ -2,10 +2,12 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Unit\Pages; +namespace Hyde\Publications\Testing; use Hyde\Foundation\PageCollection; use Hyde\Framework\Factories\Concerns\CoreDataObject; +use Hyde\Framework\Factories\Concerns\PageDataFactory; +use Hyde\Framework\Factories\HydePageDataFactory; use Hyde\Framework\Features\Metadata\PageMetadataBag; use Hyde\Hyde; use Hyde\Markdown\Models\FrontMatter; @@ -13,13 +15,12 @@ use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\Models\PublicationType; use Hyde\Support\Models\Route; - -require_once __DIR__.'/BaseMarkdownPageUnitTest.php'; +use Hyde\Testing\TestCase; /** * @covers \Hyde\Publications\Models\PublicationPage */ -class PublicationPageUnitTest extends BaseMarkdownPageUnitTest +class PublicationPageUnitTest extends TestCase { public function testSourceDirectory() { @@ -95,7 +96,8 @@ public function testGetLink() public function testMake() { - $this->assertEquals(PublicationPage::make(type: $this->pubType()), new PublicationPage('', [], '', $this->pubType())); + $this->assertEquals(PublicationPage::make(type: $this->pubType()), + new PublicationPage('', [], '', $this->pubType())); } public function testMakeWithData() @@ -174,7 +176,8 @@ public function testAll() public function testMetadata() { - $this->assertInstanceOf(PageMetadataBag::class, (new PublicationPage('', [], '', $this->pubType()))->metadata()); + $this->assertInstanceOf(PageMetadataBag::class, + (new PublicationPage('', [], '', $this->pubType()))->metadata()); } public function test__construct() @@ -199,7 +202,8 @@ public function testHas() public function testToCoreDataObject() { - $this->assertInstanceOf(CoreDataObject::class, (new PublicationPage('foo', [], '', $this->pubType()))->toCoreDataObject()); + $this->assertInstanceOf(CoreDataObject::class, + (new PublicationPage('foo', [], '', $this->pubType()))->toCoreDataObject()); } public function testConstructFactoryData() @@ -249,4 +253,9 @@ protected function pubType(): PublicationType 'directory' ); } + + protected function mockPageDataFactory(): PageDataFactory + { + return new HydePageDataFactory(new CoreDataObject(new FrontMatter(), false, '', '', '', '', '')); + } } From 7562283db064df357da6542814e1038a419474a0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 18:10:52 +0100 Subject: [PATCH 30/44] Move internal ValidatingCommand to publications package --- .../publications/src/Commands/MakePublicationCommand.php | 5 ++--- .../src/Commands/MakePublicationTagCommand.php | 3 +-- .../src/Commands/MakePublicationTypeCommand.php | 7 +++---- .../publications/src/Commands/SeedPublicationCommand.php | 1 - .../src/Commands/ValidatePublicationsCommand.php | 3 +-- .../src/Commands}/ValidatingCommand.php | 9 +++++---- .../tests}/ValidatingCommandTest.php | 7 ++++--- 7 files changed, 16 insertions(+), 19 deletions(-) rename packages/{framework/src/Console/Concerns => publications/src/Commands}/ValidatingCommand.php (99%) rename packages/{framework/tests/Feature => publications/tests}/ValidatingCommandTest.php (98%) diff --git a/packages/publications/src/Commands/MakePublicationCommand.php b/packages/publications/src/Commands/MakePublicationCommand.php index 7a7f6ed7a9e..3b9cdbad7d9 100644 --- a/packages/publications/src/Commands/MakePublicationCommand.php +++ b/packages/publications/src/Commands/MakePublicationCommand.php @@ -6,7 +6,6 @@ use Closure; use Hyde\Console\Commands\Helpers\InputStreamHandler; -use Hyde\Console\Concerns\ValidatingCommand; use Hyde\Publications\Actions\CreatesNewPublicationPage; use Hyde\Publications\Models\PublicationFieldDefinition; use Hyde\Publications\Models\PublicationFieldValue; @@ -14,10 +13,10 @@ use Hyde\Publications\PublicationFieldTypes; use Hyde\Publications\PublicationService; use Illuminate\Support\Collection; -use function implode; -use function in_array; use InvalidArgumentException; use LaravelZero\Framework\Commands\Command; +use function implode; +use function in_array; use function str_starts_with; /** diff --git a/packages/publications/src/Commands/MakePublicationTagCommand.php b/packages/publications/src/Commands/MakePublicationTagCommand.php index bc9a395a092..2e4ec016d63 100644 --- a/packages/publications/src/Commands/MakePublicationTagCommand.php +++ b/packages/publications/src/Commands/MakePublicationTagCommand.php @@ -5,14 +5,13 @@ namespace Hyde\Publications\Commands; use Hyde\Console\Commands\Helpers\InputStreamHandler; -use Hyde\Console\Concerns\ValidatingCommand; use Hyde\Framework\Services\DiscoveryService; use Hyde\Hyde; use Hyde\Publications\Models\PublicationTags; use Hyde\Publications\PublicationService; -use function implode; use LaravelZero\Framework\Commands\Command; use RuntimeException; +use function implode; use function sprintf; /** diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 5de0af8936c..006c88b5f45 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -4,9 +4,6 @@ namespace Hyde\Publications\Commands; -use function array_keys; -use function count; -use Hyde\Console\Concerns\ValidatingCommand; use Hyde\Hyde; use Hyde\Publications\Actions\CreatesNewPublicationType; use Hyde\Publications\Models\PublicationFieldDefinition; @@ -15,9 +12,11 @@ use Illuminate\Support\Collection; use Illuminate\Support\Str; use InvalidArgumentException; +use LaravelZero\Framework\Commands\Command; +use function array_keys; +use function count; use function is_dir; use function is_file; -use LaravelZero\Framework\Commands\Command; use function scandir; use function strtolower; use function trim; diff --git a/packages/publications/src/Commands/SeedPublicationCommand.php b/packages/publications/src/Commands/SeedPublicationCommand.php index 692c8c1d5f5..b6f19597623 100644 --- a/packages/publications/src/Commands/SeedPublicationCommand.php +++ b/packages/publications/src/Commands/SeedPublicationCommand.php @@ -4,7 +4,6 @@ namespace Hyde\Publications\Commands; -use Hyde\Console\Concerns\ValidatingCommand; use Hyde\Publications\Actions\SeedsPublicationFiles; use Hyde\Publications\Models\PublicationType; use Hyde\Publications\PublicationService; diff --git a/packages/publications/src/Commands/ValidatePublicationsCommand.php b/packages/publications/src/Commands/ValidatePublicationsCommand.php index 9724a491875..507bf0699b4 100644 --- a/packages/publications/src/Commands/ValidatePublicationsCommand.php +++ b/packages/publications/src/Commands/ValidatePublicationsCommand.php @@ -4,14 +4,13 @@ namespace Hyde\Publications\Commands; -use function count; use Exception; -use Hyde\Console\Concerns\ValidatingCommand; use Hyde\Publications\Models\PublicationFieldDefinition; use Hyde\Publications\PublicationService; use Hyde\Publications\ValidatesPublicationField; use InvalidArgumentException; use LaravelZero\Framework\Commands\Command; +use function count; use function str_repeat; use function strlen; diff --git a/packages/framework/src/Console/Concerns/ValidatingCommand.php b/packages/publications/src/Commands/ValidatingCommand.php similarity index 99% rename from packages/framework/src/Console/Concerns/ValidatingCommand.php rename to packages/publications/src/Commands/ValidatingCommand.php index 20501ce95be..29c409d7e99 100644 --- a/packages/framework/src/Console/Concerns/ValidatingCommand.php +++ b/packages/publications/src/Commands/ValidatingCommand.php @@ -2,15 +2,16 @@ declare(strict_types=1); -namespace Hyde\Console\Concerns; +namespace Hyde\Publications\Commands; -use function __; -use function array_merge; use Exception; use Illuminate\Support\Facades\Validator; -use function in_array; use LaravelZero\Framework\Commands\Command; use RuntimeException; + +use function __; +use function array_merge; +use function in_array; use function str_ends_with; use function ucfirst; diff --git a/packages/framework/tests/Feature/ValidatingCommandTest.php b/packages/publications/tests/ValidatingCommandTest.php similarity index 98% rename from packages/framework/tests/Feature/ValidatingCommandTest.php rename to packages/publications/tests/ValidatingCommandTest.php index 5768d4b3413..8aae1627b0f 100644 --- a/packages/framework/tests/Feature/ValidatingCommandTest.php +++ b/packages/publications/tests/ValidatingCommandTest.php @@ -5,18 +5,19 @@ namespace Hyde\Framework\Testing\Feature; use Closure; -use Hyde\Console\Concerns\ValidatingCommand; +use Hyde\Publications\Commands\ValidatingCommand; use Hyde\Testing\TestCase; use Illuminate\Console\OutputStyle; use Illuminate\Support\Facades\Validator; use Mockery; use PHPUnit\Framework\ExpectationFailedException; use RuntimeException; -use function str_starts_with; use Symfony\Component\Console\Question\ChoiceQuestion; +use function str_starts_with; + /** - * @covers \Hyde\Console\Concerns\ValidatingCommand + * @covers \Hyde\Publications\Commands\ValidatingCommand */ class ValidatingCommandTest extends TestCase { From c329ea07fc0b2c6201909b4887742b878b26db9b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 17:11:07 +0000 Subject: [PATCH 31/44] Apply fixes from StyleCI --- .../publications/src/Commands/MakePublicationCommand.php | 4 ++-- .../src/Commands/MakePublicationTagCommand.php | 2 +- .../src/Commands/MakePublicationTypeCommand.php | 6 +++--- .../src/Commands/ValidatePublicationsCommand.php | 2 +- packages/publications/src/Commands/ValidatingCommand.php | 7 +++---- packages/publications/tests/ValidatingCommandTest.php | 3 +-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationCommand.php b/packages/publications/src/Commands/MakePublicationCommand.php index 3b9cdbad7d9..98fa106e324 100644 --- a/packages/publications/src/Commands/MakePublicationCommand.php +++ b/packages/publications/src/Commands/MakePublicationCommand.php @@ -13,10 +13,10 @@ use Hyde\Publications\PublicationFieldTypes; use Hyde\Publications\PublicationService; use Illuminate\Support\Collection; -use InvalidArgumentException; -use LaravelZero\Framework\Commands\Command; use function implode; use function in_array; +use InvalidArgumentException; +use LaravelZero\Framework\Commands\Command; use function str_starts_with; /** diff --git a/packages/publications/src/Commands/MakePublicationTagCommand.php b/packages/publications/src/Commands/MakePublicationTagCommand.php index 2e4ec016d63..96057997940 100644 --- a/packages/publications/src/Commands/MakePublicationTagCommand.php +++ b/packages/publications/src/Commands/MakePublicationTagCommand.php @@ -9,9 +9,9 @@ use Hyde\Hyde; use Hyde\Publications\Models\PublicationTags; use Hyde\Publications\PublicationService; +use function implode; use LaravelZero\Framework\Commands\Command; use RuntimeException; -use function implode; use function sprintf; /** diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 006c88b5f45..bd28115c349 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -4,6 +4,8 @@ namespace Hyde\Publications\Commands; +use function array_keys; +use function count; use Hyde\Hyde; use Hyde\Publications\Actions\CreatesNewPublicationType; use Hyde\Publications\Models\PublicationFieldDefinition; @@ -12,11 +14,9 @@ use Illuminate\Support\Collection; use Illuminate\Support\Str; use InvalidArgumentException; -use LaravelZero\Framework\Commands\Command; -use function array_keys; -use function count; use function is_dir; use function is_file; +use LaravelZero\Framework\Commands\Command; use function scandir; use function strtolower; use function trim; diff --git a/packages/publications/src/Commands/ValidatePublicationsCommand.php b/packages/publications/src/Commands/ValidatePublicationsCommand.php index 507bf0699b4..18552fb9fc2 100644 --- a/packages/publications/src/Commands/ValidatePublicationsCommand.php +++ b/packages/publications/src/Commands/ValidatePublicationsCommand.php @@ -4,13 +4,13 @@ namespace Hyde\Publications\Commands; +use function count; use Exception; use Hyde\Publications\Models\PublicationFieldDefinition; use Hyde\Publications\PublicationService; use Hyde\Publications\ValidatesPublicationField; use InvalidArgumentException; use LaravelZero\Framework\Commands\Command; -use function count; use function str_repeat; use function strlen; diff --git a/packages/publications/src/Commands/ValidatingCommand.php b/packages/publications/src/Commands/ValidatingCommand.php index 29c409d7e99..7c5622a155b 100644 --- a/packages/publications/src/Commands/ValidatingCommand.php +++ b/packages/publications/src/Commands/ValidatingCommand.php @@ -4,14 +4,13 @@ namespace Hyde\Publications\Commands; +use function __; +use function array_merge; use Exception; use Illuminate\Support\Facades\Validator; +use function in_array; use LaravelZero\Framework\Commands\Command; use RuntimeException; - -use function __; -use function array_merge; -use function in_array; use function str_ends_with; use function ucfirst; diff --git a/packages/publications/tests/ValidatingCommandTest.php b/packages/publications/tests/ValidatingCommandTest.php index 8aae1627b0f..dbc7c2ae8b7 100644 --- a/packages/publications/tests/ValidatingCommandTest.php +++ b/packages/publications/tests/ValidatingCommandTest.php @@ -12,9 +12,8 @@ use Mockery; use PHPUnit\Framework\ExpectationFailedException; use RuntimeException; -use Symfony\Component\Console\Question\ChoiceQuestion; - use function str_starts_with; +use Symfony\Component\Console\Question\ChoiceQuestion; /** * @covers \Hyde\Publications\Commands\ValidatingCommand From b28f071cf36a5a831b37cfe12025dc8e2e8b0fc9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 18:18:41 +0100 Subject: [PATCH 32/44] Move test for moved provider --- .../tests}/TranslationServiceProviderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/{framework/tests/Unit => publications/tests}/TranslationServiceProviderTest.php (95%) diff --git a/packages/framework/tests/Unit/TranslationServiceProviderTest.php b/packages/publications/tests/TranslationServiceProviderTest.php similarity index 95% rename from packages/framework/tests/Unit/TranslationServiceProviderTest.php rename to packages/publications/tests/TranslationServiceProviderTest.php index 2cbedf53cfa..587b934f4bc 100644 --- a/packages/framework/tests/Unit/TranslationServiceProviderTest.php +++ b/packages/publications/tests/TranslationServiceProviderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Unit; +namespace Hyde\Publications\Testing; use Hyde\Publications\Providers\TranslationServiceProvider; use Hyde\Testing\TestCase; From 8af5d61570a60ba6c19ec7ddd79f84eeb392f5fe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 18:19:37 +0100 Subject: [PATCH 33/44] Move test for moved rule --- .../tests/Unit => publications/tests}/BooleanRuleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/{framework/tests/Unit => publications/tests}/BooleanRuleTest.php (97%) diff --git a/packages/framework/tests/Unit/BooleanRuleTest.php b/packages/publications/tests/BooleanRuleTest.php similarity index 97% rename from packages/framework/tests/Unit/BooleanRuleTest.php rename to packages/publications/tests/BooleanRuleTest.php index 57d99f1e283..e0248e1782a 100644 --- a/packages/framework/tests/Unit/BooleanRuleTest.php +++ b/packages/publications/tests/BooleanRuleTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Unit; +namespace Hyde\Publications\Testing; use Hyde\Publications\Validation\BooleanRule; use Hyde\Testing\TestCase; From 0f0a576bcdf2033415d7b069543f97829e78440f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 18:23:31 +0100 Subject: [PATCH 34/44] Move class into appropriate actions namespace --- .../publications/src/{ => Actions}/ValidatesPublicationField.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/publications/src/{ => Actions}/ValidatesPublicationField.php (100%) diff --git a/packages/publications/src/ValidatesPublicationField.php b/packages/publications/src/Actions/ValidatesPublicationField.php similarity index 100% rename from packages/publications/src/ValidatesPublicationField.php rename to packages/publications/src/Actions/ValidatesPublicationField.php From 968f770a077542580b65d14462c139203cadde8a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 18:23:57 +0100 Subject: [PATCH 35/44] Return the page classes provided by the extension --- packages/publications/src/PublicationsExtension.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php index 90b9bcc6b1b..1b4c480d9bd 100644 --- a/packages/publications/src/PublicationsExtension.php +++ b/packages/publications/src/PublicationsExtension.php @@ -14,6 +14,15 @@ class PublicationsExtension extends HydeExtension { + /** @return array> */ + public static function getPageClasses(): array + { + return [ + PublicationPage::class, + PublicationListPage::class, + ]; + } + public static function discoverPages(PageCollection $collection): void { static::discoverPublicationPages($collection); From 743e98289e6bf87687eaf1ac6c8b17b377d2408c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 22:20:15 +0100 Subject: [PATCH 36/44] Update extension namespace --- packages/publications/src/PublicationsExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php index 1b4c480d9bd..36943f64641 100644 --- a/packages/publications/src/PublicationsExtension.php +++ b/packages/publications/src/PublicationsExtension.php @@ -4,7 +4,7 @@ namespace Hyde\Publications; -use Hyde\Foundation\Extensions\HydeExtension; +use Hyde\Foundation\Concerns\HydeExtension; use Hyde\Foundation\PageCollection; use Hyde\Pages\VirtualPage; use Hyde\Publications\Models\PublicationListPage; From 39875d877315d3da47a6e56d4cbe323d81794d31 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 22:23:12 +0100 Subject: [PATCH 37/44] Reset the kernel after tests Revert "Reset the kernel after tests" This reverts commit d37e5f7c6933eb1f0633f1d1f953eafd330dedad. Reset kernel before test --- packages/framework/tests/Feature/HydeExtensionFeatureTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/tests/Feature/HydeExtensionFeatureTest.php b/packages/framework/tests/Feature/HydeExtensionFeatureTest.php index a3256e9d4ab..e2cea4ca70c 100644 --- a/packages/framework/tests/Feature/HydeExtensionFeatureTest.php +++ b/packages/framework/tests/Feature/HydeExtensionFeatureTest.php @@ -49,7 +49,11 @@ public function testBaseClassDiscoveryHandlers() public function testCanRegisterNewExtension() { + HydeKernel::setInstance(new HydeKernel()); + + $this->kernel = HydeKernel::getInstance(); $this->kernel->registerExtension(HydeTestExtension::class); + $this->assertSame([HydeTestExtension::class], $this->kernel->getRegisteredExtensions()); } From 0368f541a22192e354fc1301c3b63245dedca9dd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 22:31:33 +0100 Subject: [PATCH 38/44] Fix up namespaces --- .../publications/src/Actions/ValidatesPublicationField.php | 4 +++- .../publications/src/Commands/ValidatePublicationsCommand.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/publications/src/Actions/ValidatesPublicationField.php b/packages/publications/src/Actions/ValidatesPublicationField.php index 4d5e1236451..dcaebe43798 100644 --- a/packages/publications/src/Actions/ValidatesPublicationField.php +++ b/packages/publications/src/Actions/ValidatesPublicationField.php @@ -2,8 +2,10 @@ declare(strict_types=1); -namespace Hyde\Publications; +namespace Hyde\Publications\Actions; +use Hyde\Publications\PublicationFieldTypes; +use Hyde\Publications\PublicationService; use function array_merge; use function collect; use Hyde\Publications\Models\PublicationFieldDefinition; diff --git a/packages/publications/src/Commands/ValidatePublicationsCommand.php b/packages/publications/src/Commands/ValidatePublicationsCommand.php index 18552fb9fc2..722e2e8be4c 100644 --- a/packages/publications/src/Commands/ValidatePublicationsCommand.php +++ b/packages/publications/src/Commands/ValidatePublicationsCommand.php @@ -4,11 +4,11 @@ namespace Hyde\Publications\Commands; +use Hyde\Publications\Actions\ValidatesPublicationField; use function count; use Exception; use Hyde\Publications\Models\PublicationFieldDefinition; use Hyde\Publications\PublicationService; -use Hyde\Publications\ValidatesPublicationField; use InvalidArgumentException; use LaravelZero\Framework\Commands\Command; use function str_repeat; From ee885edd4f5939d89371a54c90f32f017cc7b316 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Jan 2023 21:31:46 +0000 Subject: [PATCH 39/44] Apply fixes from StyleCI --- .../publications/src/Actions/ValidatesPublicationField.php | 4 ++-- .../publications/src/Commands/ValidatePublicationsCommand.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Actions/ValidatesPublicationField.php b/packages/publications/src/Actions/ValidatesPublicationField.php index dcaebe43798..d2617e1656e 100644 --- a/packages/publications/src/Actions/ValidatesPublicationField.php +++ b/packages/publications/src/Actions/ValidatesPublicationField.php @@ -4,12 +4,12 @@ namespace Hyde\Publications\Actions; -use Hyde\Publications\PublicationFieldTypes; -use Hyde\Publications\PublicationService; use function array_merge; use function collect; use Hyde\Publications\Models\PublicationFieldDefinition; use Hyde\Publications\Models\PublicationType; +use Hyde\Publications\PublicationFieldTypes; +use Hyde\Publications\PublicationService; use Illuminate\Contracts\Validation\Validator; use function validator; diff --git a/packages/publications/src/Commands/ValidatePublicationsCommand.php b/packages/publications/src/Commands/ValidatePublicationsCommand.php index 722e2e8be4c..194c0042ec9 100644 --- a/packages/publications/src/Commands/ValidatePublicationsCommand.php +++ b/packages/publications/src/Commands/ValidatePublicationsCommand.php @@ -4,9 +4,9 @@ namespace Hyde\Publications\Commands; -use Hyde\Publications\Actions\ValidatesPublicationField; use function count; use Exception; +use Hyde\Publications\Actions\ValidatesPublicationField; use Hyde\Publications\Models\PublicationFieldDefinition; use Hyde\Publications\PublicationService; use InvalidArgumentException; From ea523c4b882ae42aa7b22f338775995b803ba3a4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Jan 2023 22:33:58 +0100 Subject: [PATCH 40/44] Fix namespace --- packages/publications/tests/ValidatesPublicationsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/tests/ValidatesPublicationsTest.php b/packages/publications/tests/ValidatesPublicationsTest.php index 34be0dfa19c..b89c584c384 100644 --- a/packages/publications/tests/ValidatesPublicationsTest.php +++ b/packages/publications/tests/ValidatesPublicationsTest.php @@ -4,9 +4,9 @@ namespace Hyde\Publications\Testing; +use Hyde\Publications\Actions\ValidatesPublicationField; use Hyde\Publications\Models\PublicationFieldDefinition; use Hyde\Publications\Models\PublicationType; -use Hyde\Publications\ValidatesPublicationField; use Hyde\Testing\TestCase; use Illuminate\Validation\ValidationException; use PHPUnit\Framework\MockObject\MockObject; From 69c555037ec986c518dea74a075fb589ded64682 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 10:07:55 +0100 Subject: [PATCH 41/44] Fix covers annotation --- packages/publications/tests/ValidatesPublicationsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/tests/ValidatesPublicationsTest.php b/packages/publications/tests/ValidatesPublicationsTest.php index b89c584c384..c9b06ecc4c0 100644 --- a/packages/publications/tests/ValidatesPublicationsTest.php +++ b/packages/publications/tests/ValidatesPublicationsTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\MockObject\MockObject; /** - * @covers \Hyde\Publications\ValidatesPublicationField + * @covers \Hyde\Publications\Actions\ValidatesPublicationField */ class ValidatesPublicationsTest extends TestCase { From 9e3403b0860f20fa8b2ee7101b122adb6516e1c8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 10:17:19 +0100 Subject: [PATCH 42/44] Change min randomization value of seeder actions to 1 --- packages/publications/src/Actions/SeedsPublicationFiles.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publications/src/Actions/SeedsPublicationFiles.php b/packages/publications/src/Actions/SeedsPublicationFiles.php index f69cda66af1..9e4456a95b5 100644 --- a/packages/publications/src/Actions/SeedsPublicationFiles.php +++ b/packages/publications/src/Actions/SeedsPublicationFiles.php @@ -97,7 +97,7 @@ protected function generateFieldData(PublicationFieldDefinition $field): string| 'float' => ((mt_rand() / mt_getrandmax()) * (200000)) + -100000, 'image' => 'https://picsum.photos/id/'.rand(1, 1000).'/400/400', 'integer' => rand(-100000, 100000), - 'string' => substr($this->fakeSentence(10), 0, rand(0, 255)), + 'string' => substr($this->fakeSentence(10), 0, rand(1, 255)), 'tag' => $this->getTags($field->tagGroup), 'text' => $this->getTextValue(rand(3, 20)), 'url' => $this->fakeUrl(), @@ -208,7 +208,7 @@ private function randomMarkdownLines(int $count): string { $lines = []; for ($i = 0; $i < $count; $i++) { - $lines[] = $this->fakeSentence(rand(0, 15)); + $lines[] = $this->fakeSentence(rand(1, 15)); } return implode("\n", $lines); From 0f5584601d1dcc6ef603f2755c507b6fe9ec207d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 10:17:48 +0100 Subject: [PATCH 43/44] Add missing parameter type --- packages/publications/src/Actions/SeedsPublicationFiles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Actions/SeedsPublicationFiles.php b/packages/publications/src/Actions/SeedsPublicationFiles.php index 9e4456a95b5..2c1b9590d88 100644 --- a/packages/publications/src/Actions/SeedsPublicationFiles.php +++ b/packages/publications/src/Actions/SeedsPublicationFiles.php @@ -77,7 +77,7 @@ protected function getDateTimeValue(): string )); } - protected function getTextValue($lines): string + protected function getTextValue(int $lines): string { $value = ''; From c4edeaace1c97a01f77ee2f3e97e03db8df954ab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 10:25:20 +0100 Subject: [PATCH 44/44] Add missing paginator test --- .../framework/tests/Feature/PaginatorTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/framework/tests/Feature/PaginatorTest.php b/packages/framework/tests/Feature/PaginatorTest.php index 858f540dd0e..9f9f3a5600a 100644 --- a/packages/framework/tests/Feature/PaginatorTest.php +++ b/packages/framework/tests/Feature/PaginatorTest.php @@ -273,6 +273,22 @@ public function testGetPageLinksWithBaseRoute() ); } + public function testFirstItemNumberOnPage() + { + $paginator = $this->makePaginator(); + $this->assertSame(1, $paginator->firstItemNumberOnPage()); + $this->assertSame(11, $paginator->setCurrentPage(2)->firstItemNumberOnPage()); + $this->assertSame(21, $paginator->setCurrentPage(3)->firstItemNumberOnPage()); + $this->assertSame(31, $paginator->setCurrentPage(4)->firstItemNumberOnPage()); + $this->assertSame(41, $paginator->setCurrentPage(5)->firstItemNumberOnPage()); + + $paginator = $this->makePaginator(1, 100, 25); + $this->assertSame(1, $paginator->firstItemNumberOnPage()); + $this->assertSame(26, $paginator->setCurrentPage(2)->firstItemNumberOnPage()); + $this->assertSame(51, $paginator->setCurrentPage(3)->firstItemNumberOnPage()); + $this->assertSame(76, $paginator->setCurrentPage(4)->firstItemNumberOnPage()); + } + protected function makePaginator(int $start = 1, int $end = 50, int $pageSize = 10): Paginator { return new Paginator(range($start, $end), $pageSize);