From 6f2477a5b60411c7b09702a8a322aba8abd776f5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:37:29 +0100 Subject: [PATCH 001/100] Add schema properties as class properties --- .../Features/Publications/Models/PublicationType.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 5221a4013b6..c624264c654 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -12,6 +12,16 @@ class PublicationType protected string $directory; protected array $schema; + public $name; + public $canonicalField; + public $sortField; + public $sortDirection; + public $pagesize; + public $prevNextLinks; + public $detailTemplate; + public $listTemplate; + public $fields; + public static function get(string $name): self { return new self(Hyde::path("$name/schema.json")); From d5927af1b785b4cee14fd4b3f57a9cffd08f8099 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:39:12 +0100 Subject: [PATCH 002/100] Declare property types --- .../Publications/Models/PublicationType.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index c624264c654..1d134aeb8ad 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -12,15 +12,15 @@ class PublicationType protected string $directory; protected array $schema; - public $name; - public $canonicalField; - public $sortField; - public $sortDirection; - public $pagesize; - public $prevNextLinks; - public $detailTemplate; - public $listTemplate; - public $fields; + public string $name; + public string $canonicalField; + public string $sortField; + public string $sortDirection; + public int $pagesize; + public bool $prevNextLinks; + public string $detailTemplate; + public string $listTemplate; + public array $fields; public static function get(string $name): self { From d2ade962a6c76baa041044d2ad9c7c21f842344a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:39:36 +0100 Subject: [PATCH 003/100] Deprecate protected property --- .../Framework/Features/Publications/Models/PublicationType.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 1d134aeb8ad..461a4b1284a 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -10,6 +10,9 @@ class PublicationType { protected string $schemaFile; protected string $directory; + /** + * @deprecated + */ protected array $schema; public string $name; From 82b858d42a6902f8111d642d24b3866ed71ebeaa Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 17:40:09 +0000 Subject: [PATCH 004/100] Apply fixes from StyleCI --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 461a4b1284a..ca28974fbc2 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -11,7 +11,7 @@ class PublicationType protected string $schemaFile; protected string $directory; /** - * @deprecated + * @deprecated */ protected array $schema; From 931b420f4540f168ee8f4df65cd5e4dcda61f6d3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:45:46 +0100 Subject: [PATCH 005/100] Style --- .../Features/Publications/Models/PublicationType.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index ca28974fbc2..e2352fe40cf 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -10,9 +10,7 @@ class PublicationType { protected string $schemaFile; protected string $directory; - /** - * @deprecated - */ + /** @deprecated */ protected array $schema; public string $name; From f7de5debf40f8cb6200ec61d06dfeaf9dea0ef07 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:46:02 +0100 Subject: [PATCH 006/100] Create PublicationTypeTest.php --- .../tests/Feature/PublicationTypeTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/framework/tests/Feature/PublicationTypeTest.php diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php new file mode 100644 index 00000000000..13afb67d579 --- /dev/null +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -0,0 +1,16 @@ + Date: Sun, 20 Nov 2022 18:46:17 +0100 Subject: [PATCH 007/100] Link to the test --- .../Framework/Features/Publications/Models/PublicationType.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index e2352fe40cf..48f371b84d2 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -6,6 +6,9 @@ use Hyde\Hyde; +/** + * @see \Hyde\Framework\Testing\Feature\PublicationTypeTest + */ class PublicationType { protected string $schemaFile; From bc9f0619da76549a6b3ba38100b6d79e75a1d99b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 17:46:27 +0000 Subject: [PATCH 008/100] Apply fixes from StyleCI --- packages/framework/tests/Feature/PublicationTypeTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 13afb67d579..f64690b5659 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Testing\Feature; -use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Testing\TestCase; /** From 928d7ccfc5d7c6ee2eb2e50f59cec612187c0d7d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:49:59 +0100 Subject: [PATCH 009/100] Add static PublicationType::fromFile helper method --- .../Features/Publications/Models/PublicationType.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 48f371b84d2..781c489ed87 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -31,6 +31,11 @@ public static function get(string $name): self return new self(Hyde::path("$name/schema.json")); } + public static function fromFile(string $schemaFile): self + { + return new self($schemaFile); + } + public function __construct(string $schemaFile) { $this->schemaFile = $schemaFile; From 29433a0b22eae2d903b3f7c9a82160947186d896 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:50:15 +0100 Subject: [PATCH 010/100] Use static helper instead of using new PublicationType --- .../src/Framework/Features/Publications/PublicationHelper.php | 2 +- packages/framework/tests/Feature/PublicationListPageTest.php | 2 +- packages/framework/tests/Feature/PublicationPageTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/PublicationHelper.php b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php index 79d313d445a..655a005cc26 100644 --- a/packages/framework/src/Framework/Features/Publications/PublicationHelper.php +++ b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php @@ -72,7 +72,7 @@ public static function getPublicationTypes(): Collection $pubTypes = Collection::create(); foreach ($schemaFiles as $schemaFile) { - $publicationType = new PublicationType($schemaFile); + $publicationType = PublicationType::fromFile($schemaFile); $pubTypes->{$publicationType->getDirectory()} = $publicationType; } diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 6edb65f1880..cd3997b88a8 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -64,6 +64,6 @@ protected function createPublicationFiles(): void protected function getPublicationType(): PublicationType { - return new PublicationType('test-publication/schema.json'); + return PublicationType::fromFile('test-publication/schema.json'); } } diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 4c59fed8f34..8a27a448465 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -37,7 +37,7 @@ public function test_source_path_mappings() { $this->createPublicationFiles(); - $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); + $page = new PublicationPage(PublicationType::fromFile('test-publication/schema.json'), 'foo'); $this->assertSame('test-publication/foo', $page->getIdentifier()); $this->assertSame('test-publication/foo', $page->getRouteKey()); @@ -49,7 +49,7 @@ public function test_publication_pages_are_routable() { $this->createPublicationFiles(); - $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); + $page = new PublicationPage(PublicationType::fromFile('test-publication/schema.json'), 'foo'); $this->assertInstanceOf(Route::class, $page->getRoute()); $this->assertEquals(new Route($page), $page->getRoute()); From 34c90222228dde27c28e389b0c1844052fdd3b54 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:52:47 +0100 Subject: [PATCH 011/100] Generate new constructor --- .../Publications/Models/PublicationType.php | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 781c489ed87..562bde4550d 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -26,6 +26,32 @@ class PublicationType public string $listTemplate; public array $fields; + public function __construct( + string $schemaFile, + string $directory, + string $name, + string $canonicalField, + string $sortField, + string $sortDirection, + int $pagesize, + bool $prevNextLinks, + string $detailTemplate, + string $listTemplate, + array $fields + ) { + $this->schemaFile = $schemaFile; + $this->directory = $directory; + $this->name = $name; + $this->canonicalField = $canonicalField; + $this->sortField = $sortField; + $this->sortDirection = $sortDirection; + $this->pagesize = $pagesize; + $this->prevNextLinks = $prevNextLinks; + $this->detailTemplate = $detailTemplate; + $this->listTemplate = $listTemplate; + $this->fields = $fields; + } + public static function get(string $name): self { return new self(Hyde::path("$name/schema.json")); @@ -36,12 +62,6 @@ public static function fromFile(string $schemaFile): self return new self($schemaFile); } - public function __construct(string $schemaFile) - { - $this->schemaFile = $schemaFile; - $this->directory = Hyde::pathToRelative(dirname($schemaFile)); - $this->schema = static::parseSchema($schemaFile); - } public function __get(string $name): mixed { From 7fed1d96c9ccc7fb229a86e99e7e637fe41a03fd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:53:51 +0100 Subject: [PATCH 012/100] Make non schema properties optional for easier mocking --- .../Publications/Models/PublicationType.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 562bde4550d..704169a9cfb 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -27,8 +27,6 @@ class PublicationType public array $fields; public function __construct( - string $schemaFile, - string $directory, string $name, string $canonicalField, string $sortField, @@ -37,10 +35,10 @@ public function __construct( bool $prevNextLinks, string $detailTemplate, string $listTemplate, - array $fields + array $fields, + ?string $schemaFile = null, + ?string $directory = null, ) { - $this->schemaFile = $schemaFile; - $this->directory = $directory; $this->name = $name; $this->canonicalField = $canonicalField; $this->sortField = $sortField; @@ -50,6 +48,12 @@ public function __construct( $this->detailTemplate = $detailTemplate; $this->listTemplate = $listTemplate; $this->fields = $fields; + if ($schemaFile) { + $this->schemaFile = $schemaFile; + } + if ($directory) { + $this->directory = $directory; + } } public static function get(string $name): self From dffaf20afc8215a621874fbbbc1eec09684b232d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:56:46 +0100 Subject: [PATCH 013/100] Construct all the arguments --- .../Publications/Models/PublicationType.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 704169a9cfb..44bf7ef5fb2 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -63,10 +63,23 @@ public static function get(string $name): self public static function fromFile(string $schemaFile): self { - return new self($schemaFile); + $directory = Hyde::pathToRelative(dirname($schemaFile)); + $schema = static::parseSchema($schemaFile); + return new self( + $schema['name'], + $schema['canonicalField'], + $schema['sortField'], + $schema['sortDirection'], + $schema['pagesize'], + $schema['prevNextLinks'], + $schema['detailTemplate'], + $schema['listTemplate'], + $schema['fields'], + $schemaFile, + $directory, + ); } - public function __get(string $name): mixed { return $this->$name ?? $this->schema[$name] ?? null; From d5303d90d3a490925363043d88cc23e055dfb843 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:57:13 +0100 Subject: [PATCH 014/100] Update get helper method --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 44bf7ef5fb2..45a350b58c9 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -58,7 +58,7 @@ public function __construct( public static function get(string $name): self { - return new self(Hyde::path("$name/schema.json")); + return self::fromFile(Hyde::path("$name/schema.json")); } public static function fromFile(string $schemaFile): self From 5395be20037d35791543c81933705452ce7b07b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:58:12 +0100 Subject: [PATCH 015/100] Remove resolved todo --- .../Framework/Features/Publications/Models/PublicationType.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 45a350b58c9..13c5b446ca0 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -104,6 +104,4 @@ protected static function parseSchema(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); } - - // TODO build list pages and detail pages for each publication type } From 68f2a74faaf2b079f8ddd784eb21347f69ed87fb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:58:52 +0100 Subject: [PATCH 016/100] Remove deprecated array property and accessors --- .../Features/Publications/Models/PublicationType.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 13c5b446ca0..b3ef14a5bb9 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -13,8 +13,6 @@ class PublicationType { protected string $schemaFile; protected string $directory; - /** @deprecated */ - protected array $schema; public string $name; public string $canonicalField; @@ -80,11 +78,6 @@ public static function fromFile(string $schemaFile): self ); } - public function __get(string $name): mixed - { - return $this->$name ?? $this->schema[$name] ?? null; - } - public function getSchemaFile(): string { return $this->schemaFile; @@ -95,11 +88,6 @@ public function getDirectory(): string return $this->directory; } - public function getSchema(): array - { - return $this->schema; - } - protected static function parseSchema(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); From ef87ac972616fbfb47b8ed33a4be567d7739d28a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 18:59:32 +0100 Subject: [PATCH 017/100] Join comma-separated values into a single line --- .../Publications/Models/PublicationType.php | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index b3ef14a5bb9..88451f830c2 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -24,19 +24,7 @@ class PublicationType public string $listTemplate; public array $fields; - public function __construct( - string $name, - string $canonicalField, - string $sortField, - string $sortDirection, - int $pagesize, - bool $prevNextLinks, - string $detailTemplate, - string $listTemplate, - array $fields, - ?string $schemaFile = null, - ?string $directory = null, - ) { + public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $schemaFile = null, ?string $directory = null) { $this->name = $name; $this->canonicalField = $canonicalField; $this->sortField = $sortField; @@ -63,19 +51,7 @@ public static function fromFile(string $schemaFile): self { $directory = Hyde::pathToRelative(dirname($schemaFile)); $schema = static::parseSchema($schemaFile); - return new self( - $schema['name'], - $schema['canonicalField'], - $schema['sortField'], - $schema['sortDirection'], - $schema['pagesize'], - $schema['prevNextLinks'], - $schema['detailTemplate'], - $schema['listTemplate'], - $schema['fields'], - $schemaFile, - $directory, - ); + return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $schemaFile, $directory); } public function getSchemaFile(): string From 5c515ac726adb844f16713cc1d943674ec1ceb3f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:00:48 +0100 Subject: [PATCH 018/100] Implements JsonSerializable, Arrayable --- .../Features/Publications/Models/PublicationType.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 88451f830c2..a7e2ad2b67f 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -5,11 +5,13 @@ namespace Hyde\Framework\Features\Publications\Models; use Hyde\Hyde; +use Illuminate\Contracts\Support\Arrayable; +use JsonSerializable; /** * @see \Hyde\Framework\Testing\Feature\PublicationTypeTest */ -class PublicationType +class PublicationType implements JsonSerializable, Arrayable { protected string $schemaFile; protected string $directory; From 7e7efe4343f5f611d3f67b5031f546e4fca096b6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:00:57 +0100 Subject: [PATCH 019/100] Use JsonSerializesArrayable --- .../Framework/Features/Publications/Models/PublicationType.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index a7e2ad2b67f..e809fde5791 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Features\Publications\Models; use Hyde\Hyde; +use Hyde\Support\Concerns\JsonSerializesArrayable; use Illuminate\Contracts\Support\Arrayable; use JsonSerializable; @@ -13,6 +14,8 @@ */ class PublicationType implements JsonSerializable, Arrayable { + use JsonSerializesArrayable; + protected string $schemaFile; protected string $directory; From f5415f651259376b137590cc356887746420da65 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:01:39 +0100 Subject: [PATCH 020/100] Implement toArray method --- .../Publications/Models/PublicationType.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index e809fde5791..d2006f69959 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -59,6 +59,21 @@ public static function fromFile(string $schemaFile): self return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $schemaFile, $directory); } + public function toArray(): array + { + return [ + 'name' => $this->name, + 'canonicalField' => $this->canonicalField, + 'sortField' => $this->sortField, + 'sortDirection' => $this->sortDirection, + 'pagesize' => $this->pagesize, + 'prevNextLinks' => $this->prevNextLinks, + 'detailTemplate' => $this->detailTemplate, + 'listTemplate' => $this->listTemplate, + 'fields' => $this->fields, + ]; + } + public function getSchemaFile(): string { return $this->schemaFile; From d3020bfe9cbcc3daac0e589331087ad0bbae6d56 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:01:56 +0100 Subject: [PATCH 021/100] Move up static helper methods --- .../Publications/Models/PublicationType.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index d2006f69959..50e6687053a 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -29,6 +29,18 @@ class PublicationType implements JsonSerializable, Arrayable public string $listTemplate; public array $fields; + public static function get(string $name): self + { + return self::fromFile(Hyde::path("$name/schema.json")); + } + + public static function fromFile(string $schemaFile): self + { + $directory = Hyde::pathToRelative(dirname($schemaFile)); + $schema = static::parseSchema($schemaFile); + return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $schemaFile, $directory); + } + public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $schemaFile = null, ?string $directory = null) { $this->name = $name; $this->canonicalField = $canonicalField; @@ -47,18 +59,6 @@ public function __construct(string $name, string $canonicalField, string $sortFi } } - public static function get(string $name): self - { - return self::fromFile(Hyde::path("$name/schema.json")); - } - - public static function fromFile(string $schemaFile): self - { - $directory = Hyde::pathToRelative(dirname($schemaFile)); - $schema = static::parseSchema($schemaFile); - return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $schemaFile, $directory); - } - public function toArray(): array { return [ From d8bc8c1aa647433673e869d9de27167c014f2c3e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:02:06 +0100 Subject: [PATCH 022/100] Import functions --- .../Features/Publications/Models/PublicationType.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 50e6687053a..ed3c7431325 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -9,6 +9,10 @@ use Illuminate\Contracts\Support\Arrayable; use JsonSerializable; +use function dirname; +use function file_get_contents; +use function json_decode; + /** * @see \Hyde\Framework\Testing\Feature\PublicationTypeTest */ From b755695c5d6676b6dced9e9c81548941f9555643 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 18:02:17 +0000 Subject: [PATCH 023/100] Apply fixes from StyleCI --- .../Features/Publications/Models/PublicationType.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index ed3c7431325..2d40f757423 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,14 +4,13 @@ namespace Hyde\Framework\Features\Publications\Models; +use function dirname; +use function file_get_contents; use Hyde\Hyde; use Hyde\Support\Concerns\JsonSerializesArrayable; use Illuminate\Contracts\Support\Arrayable; -use JsonSerializable; - -use function dirname; -use function file_get_contents; use function json_decode; +use JsonSerializable; /** * @see \Hyde\Framework\Testing\Feature\PublicationTypeTest @@ -42,10 +41,12 @@ public static function fromFile(string $schemaFile): self { $directory = Hyde::pathToRelative(dirname($schemaFile)); $schema = static::parseSchema($schemaFile); + return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $schemaFile, $directory); } - public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $schemaFile = null, ?string $directory = null) { + public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $schemaFile = null, ?string $directory = null) + { $this->name = $name; $this->canonicalField = $canonicalField; $this->sortField = $sortField; From 7d349b341d0ffd89c6fb8af5029f817bfc73ec14 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:03:54 +0100 Subject: [PATCH 024/100] Add base test --- .../tests/Feature/PublicationTypeTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index f64690b5659..d078512fcb6 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Feature; +use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Testing\TestCase; /** @@ -11,5 +12,18 @@ */ class PublicationTypeTest extends TestCase { - // + public function testCanConstructNewPublicationType() + { + $publicationType = new PublicationType('test', 'canonical', 'sort', 'asc', 10, true, 'detail', 'list', ['foo' => 'bar']); + + $this->assertSame('test', $publicationType->name); + $this->assertSame('canonical', $publicationType->canonicalField); + $this->assertSame('sort', $publicationType->sortField); + $this->assertSame('asc', $publicationType->sortDirection); + $this->assertSame(10, $publicationType->pagesize); + $this->assertSame(true, $publicationType->prevNextLinks); + $this->assertSame('detail', $publicationType->detailTemplate); + $this->assertSame('list', $publicationType->listTemplate); + $this->assertSame(['foo' => 'bar'], $publicationType->fields); + } } From e3729858b90924c1e51a003d44c959a50a120e53 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:09:13 +0100 Subject: [PATCH 025/100] Dynamically handle test --- .../tests/Feature/PublicationTypeTest.php | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index d078512fcb6..11fa23e1c6b 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -14,16 +14,27 @@ class PublicationTypeTest extends TestCase { public function testCanConstructNewPublicationType() { - $publicationType = new PublicationType('test', 'canonical', 'sort', 'asc', 10, true, 'detail', 'list', ['foo' => 'bar']); + $publicationType = new PublicationType(...$this->getTestData()); - $this->assertSame('test', $publicationType->name); - $this->assertSame('canonical', $publicationType->canonicalField); - $this->assertSame('sort', $publicationType->sortField); - $this->assertSame('asc', $publicationType->sortDirection); - $this->assertSame(10, $publicationType->pagesize); - $this->assertSame(true, $publicationType->prevNextLinks); - $this->assertSame('detail', $publicationType->detailTemplate); - $this->assertSame('list', $publicationType->listTemplate); - $this->assertSame(['foo' => 'bar'], $publicationType->fields); + foreach ($this->getTestData() as $key => $property) { + $this->assertEquals($property, $publicationType->$key); + } + } + + protected function getTestData(): array + { + return [ + 'name' => 'test', + 'canonicalField' => 'canonical', + 'sortField' => 'sort', + 'sortDirection' => 'asc', + 'pagesize' => 10, + 'prevNextLinks' => true, + 'detailTemplate' => 'detail', + 'listTemplate' => 'list', + 'fields' => [ + 'foo' => 'bar', + ] + ]; } } From 47195e2472a2fdfd637e63dffbe6b2e6f492a81c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:14:45 +0100 Subject: [PATCH 026/100] Test serialization --- .../framework/tests/Feature/PublicationTypeTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 11fa23e1c6b..563c32a9ca1 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -21,6 +21,18 @@ public function testCanConstructNewPublicationType() } } + public function testClassIsArrayable() + { + $publicationType = new PublicationType(...$this->getTestData()); + $this->assertSame($this->getTestData(), $publicationType->toArray()); + } + + public function testClassIsJsonSerializable() + { + $publicationType = new PublicationType(...$this->getTestData()); + $this->assertSame(json_encode($this->getTestData()), json_encode($publicationType)); + } + protected function getTestData(): array { return [ From 86909762bb7d51346df00ffaff542512f38d749f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:21:29 +0100 Subject: [PATCH 027/100] Test with path information --- .../tests/Feature/PublicationTypeTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 563c32a9ca1..e3bc0ffdbd3 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -33,6 +33,12 @@ public function testClassIsJsonSerializable() $this->assertSame(json_encode($this->getTestData()), json_encode($publicationType)); } + public function testGetDirectory() + { + $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); + $this->assertSame('test-publication', $publicationType->getDirectory()); + } + protected function getTestData(): array { return [ @@ -49,4 +55,21 @@ protected function getTestData(): array ] ]; } + + protected function getTestDataWithPathInformation(): array + { + return [ + 'test', + 'canonical', + 'sort', + 'asc', + 10, + true, + 'detail', + 'list', + ['foo' => 'bar'], + 'test.json', + 'test-publication', + ]; + } } From 8a638c339626e651728a48ae6c4f11b0809bd2ba Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:23:16 +0100 Subject: [PATCH 028/100] Refactor to handle $schemaFile dynamically --- .../Features/Publications/Models/PublicationType.php | 11 ++++------- .../framework/tests/Feature/PublicationTypeTest.php | 1 - 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 2d40f757423..3ec696c9012 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -19,7 +19,6 @@ class PublicationType implements JsonSerializable, Arrayable { use JsonSerializesArrayable; - protected string $schemaFile; protected string $directory; public string $name; @@ -42,10 +41,10 @@ public static function fromFile(string $schemaFile): self $directory = Hyde::pathToRelative(dirname($schemaFile)); $schema = static::parseSchema($schemaFile); - return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $schemaFile, $directory); + return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $directory); } - public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $schemaFile = null, ?string $directory = null) + public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $directory = null) { $this->name = $name; $this->canonicalField = $canonicalField; @@ -56,9 +55,7 @@ public function __construct(string $name, string $canonicalField, string $sortFi $this->detailTemplate = $detailTemplate; $this->listTemplate = $listTemplate; $this->fields = $fields; - if ($schemaFile) { - $this->schemaFile = $schemaFile; - } + if ($directory) { $this->directory = $directory; } @@ -81,7 +78,7 @@ public function toArray(): array public function getSchemaFile(): string { - return $this->schemaFile; + return "$this->directory/schema.json"; } public function getDirectory(): string diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index e3bc0ffdbd3..573cc0eb94f 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -68,7 +68,6 @@ protected function getTestDataWithPathInformation(): array 'detail', 'list', ['foo' => 'bar'], - 'test.json', 'test-publication', ]; } From 4cf0ee9e34d21ffadc766ac1849d9e606b08978b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:23:44 +0100 Subject: [PATCH 029/100] Refactor test helper to be dynamic --- .../tests/Feature/PublicationTypeTest.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 573cc0eb94f..83e971c9d41 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -58,17 +58,8 @@ protected function getTestData(): array protected function getTestDataWithPathInformation(): array { - return [ - 'test', - 'canonical', - 'sort', - 'asc', - 10, - true, - 'detail', - 'list', - ['foo' => 'bar'], - 'test-publication', - ]; + return array_merge($this->getTestData(), [ + 'directory' => 'test-publication', + ]); } } From e1811eac35e85f3a98c6e9c6d7073c2b4a38ce21 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:28:35 +0100 Subject: [PATCH 030/100] Implement save method --- .../Features/Publications/Models/PublicationType.php | 5 +++++ packages/framework/tests/Feature/PublicationTypeTest.php | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 3ec696c9012..bc0ca79fbe4 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -86,6 +86,11 @@ public function getDirectory(): string return $this->directory; } + public function save(): void + { + file_put_contents($this->getSchemaFile(), json_encode($this->toArray(), JSON_PRETTY_PRINT)); + } + protected static function parseSchema(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 83e971c9d41..aa18e3560c0 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -39,6 +39,15 @@ public function testGetDirectory() $this->assertSame('test-publication', $publicationType->getDirectory()); } + public function testCanSaveToJsonFile() + { + $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); + $publicationType->save(); + + $this->assertFileExists('test-publication/schema.json'); + $this->assertSame(json_encode($this->getTestData(), 128), file_get_contents('test-publication/schema.json')); + } + protected function getTestData(): array { return [ From 46d02fc3ea76e16cafd85eb57c01949108d52aaa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:29:09 +0100 Subject: [PATCH 031/100] Clean up after the test --- packages/framework/tests/Feature/PublicationTypeTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index aa18e3560c0..7a2d903323f 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -5,7 +5,9 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Hyde; use Hyde\Testing\TestCase; +use Illuminate\Support\Facades\File; /** * @covers \Hyde\Framework\Features\Publications\Models\PublicationType @@ -45,7 +47,9 @@ public function testCanSaveToJsonFile() $publicationType->save(); $this->assertFileExists('test-publication/schema.json'); - $this->assertSame(json_encode($this->getTestData(), 128), file_get_contents('test-publication/schema.json')); + $this->assertSame(json_encode($this->getTestData(), 128), file_get_contents(Hyde::path('test-publication/schema.json'))); + + File::deleteDirectory(Hyde::path('test-publication')); } protected function getTestData(): array From 6bcef6623db9247c7f0660522ce17e4cf7bef813 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:30:45 +0100 Subject: [PATCH 032/100] Allow output directory to be customized --- .../Features/Publications/Models/PublicationType.php | 4 ++-- packages/framework/tests/Feature/PublicationTypeTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index bc0ca79fbe4..ab33cf579dd 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -86,9 +86,9 @@ public function getDirectory(): string return $this->directory; } - public function save(): void + public function save(?string $path = null): void { - file_put_contents($this->getSchemaFile(), json_encode($this->toArray(), JSON_PRETTY_PRINT)); + file_put_contents($path ?? $this->getSchemaFile(), json_encode($this->toArray(), JSON_PRETTY_PRINT)); } protected static function parseSchema(string $schemaFile): array diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 7a2d903323f..157493f5a29 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -52,6 +52,12 @@ public function testCanSaveToJsonFile() File::deleteDirectory(Hyde::path('test-publication')); } + public function testCanSaveToJsonFileUsingCustomPath() + { + $publicationType = new PublicationType(...$this->getTestData()); + $publicationType->save('test-publication/foo.json'); + } + protected function getTestData(): array { return [ From a44cb91bf7e45575c817fc435c847e10afc341db Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:31:53 +0100 Subject: [PATCH 033/100] Ensure the directory exists --- .../Features/Publications/Models/PublicationType.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index ab33cf579dd..2f33f228d5b 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Features\Publications\Models; +use Hyde\Framework\Concerns\InteractsWithDirectories; use function dirname; use function file_get_contents; use Hyde\Hyde; @@ -18,6 +19,7 @@ class PublicationType implements JsonSerializable, Arrayable { use JsonSerializesArrayable; + use InteractsWithDirectories; protected string $directory; @@ -88,7 +90,9 @@ public function getDirectory(): string public function save(?string $path = null): void { - file_put_contents($path ?? $this->getSchemaFile(), json_encode($this->toArray(), JSON_PRETTY_PRINT)); + $path ??= $this->getSchemaFile(); + $this->needsParentDirectory($path); + file_put_contents($path, json_encode($this->toArray(), JSON_PRETTY_PRINT)); } protected static function parseSchema(string $schemaFile): array From 709ca02eb35a1322bcf69a9de72417d4af1588b4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 19:32:16 +0100 Subject: [PATCH 034/100] Fix test --- packages/framework/tests/Feature/PublicationTypeTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 157493f5a29..a6539c6bb69 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -56,6 +56,11 @@ public function testCanSaveToJsonFileUsingCustomPath() { $publicationType = new PublicationType(...$this->getTestData()); $publicationType->save('test-publication/foo.json'); + + $this->assertFileExists('test-publication/foo.json'); + $this->assertSame(json_encode($this->getTestData(), 128), file_get_contents(Hyde::path('test-publication/foo.json'))); + + File::deleteDirectory(Hyde::path('test-publication')); } protected function getTestData(): array From 5868206b922e1e3f1e6b90dcabaf082463ecfc7c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 18:33:10 +0000 Subject: [PATCH 035/100] Apply fixes from StyleCI --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- packages/framework/tests/Feature/PublicationTypeTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 2f33f228d5b..e3639d711c5 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,9 +4,9 @@ namespace Hyde\Framework\Features\Publications\Models; -use Hyde\Framework\Concerns\InteractsWithDirectories; use function dirname; use function file_get_contents; +use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Hyde; use Hyde\Support\Concerns\JsonSerializesArrayable; use Illuminate\Contracts\Support\Arrayable; diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index a6539c6bb69..487fd084400 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -76,7 +76,7 @@ protected function getTestData(): array 'listTemplate' => 'list', 'fields' => [ 'foo' => 'bar', - ] + ], ]; } From 3ed83b01649d031752efd34b1c3d7304f37f22dd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:17:14 +0100 Subject: [PATCH 036/100] Merge test helpers --- packages/framework/tests/Feature/PublicationTypeTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 487fd084400..229d3cf73e1 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -77,13 +77,7 @@ protected function getTestData(): array 'fields' => [ 'foo' => 'bar', ], - ]; - } - - protected function getTestDataWithPathInformation(): array - { - return array_merge($this->getTestData(), [ 'directory' => 'test-publication', - ]); + ]; } } From f9bc88fa1a01b7e09bc70ae8412481b35864e8c3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:17:36 +0100 Subject: [PATCH 037/100] Revert "Merge test helpers" This reverts commit 3ed83b01649d031752efd34b1c3d7304f37f22dd. --- packages/framework/tests/Feature/PublicationTypeTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 229d3cf73e1..487fd084400 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -77,7 +77,13 @@ protected function getTestData(): array 'fields' => [ 'foo' => 'bar', ], - 'directory' => 'test-publication', ]; } + + protected function getTestDataWithPathInformation(): array + { + return array_merge($this->getTestData(), [ + 'directory' => 'test-publication', + ]); + } } From c4a2b53150d8e9e8cffe798ac9abef66ff02dbf0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:18:03 +0100 Subject: [PATCH 038/100] Make protected test helpers public static --- packages/framework/tests/Feature/PublicationTypeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 487fd084400..19ef81facd0 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -63,7 +63,7 @@ public function testCanSaveToJsonFileUsingCustomPath() File::deleteDirectory(Hyde::path('test-publication')); } - protected function getTestData(): array + public static function getTestData(): array { return [ 'name' => 'test', @@ -80,7 +80,7 @@ protected function getTestData(): array ]; } - protected function getTestDataWithPathInformation(): array + public static function getTestDataWithPathInformation(): array { return array_merge($this->getTestData(), [ 'directory' => 'test-publication', From 49e33f32b3ac1aca14e88c487d9d299426a7a673 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:18:21 +0100 Subject: [PATCH 039/100] Use self for static method --- packages/framework/tests/Feature/PublicationTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 19ef81facd0..572291bdd90 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -82,7 +82,7 @@ public static function getTestData(): array public static function getTestDataWithPathInformation(): array { - return array_merge($this->getTestData(), [ + return array_merge(self::getTestData(), [ 'directory' => 'test-publication', ]); } From ae1f79c70fd7e8698d4809faec84f3761e347a85 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:19:01 +0100 Subject: [PATCH 040/100] Replace self with static --- .../Features/Publications/Models/PublicationType.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index e3639d711c5..ae66e8993d3 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -33,17 +33,17 @@ class PublicationType implements JsonSerializable, Arrayable public string $listTemplate; public array $fields; - public static function get(string $name): self + public static function get(string $name): static { - return self::fromFile(Hyde::path("$name/schema.json")); + return static::fromFile(Hyde::path("$name/schema.json")); } - public static function fromFile(string $schemaFile): self + public static function fromFile(string $schemaFile): static { $directory = Hyde::pathToRelative(dirname($schemaFile)); $schema = static::parseSchema($schemaFile); - return new self($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $directory); + return new static($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $directory); } public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $directory = null) From c02476865a5ebdc33e48058864d771e6680e1628 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:22:02 +0100 Subject: [PATCH 041/100] Throw more helpful exception when schema parsing fails --- .../Features/Publications/Models/PublicationType.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index ae66e8993d3..aeaef580af5 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,8 @@ namespace Hyde\Framework\Features\Publications\Models; +use Exception; +use RuntimeException; use function dirname; use function file_get_contents; use Hyde\Framework\Concerns\InteractsWithDirectories; @@ -40,10 +42,14 @@ public static function get(string $name): static public static function fromFile(string $schemaFile): static { - $directory = Hyde::pathToRelative(dirname($schemaFile)); - $schema = static::parseSchema($schemaFile); + try { + $directory = Hyde::pathToRelative(dirname($schemaFile)); + $schema = static::parseSchema($schemaFile); - return new static($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $directory); + return new static($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $directory); + } catch (Exception $exception) { + throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); + } } public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $directory = null) From 939f802503c6bf261af00941c885d9eded44b449 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:33:35 +0100 Subject: [PATCH 042/100] Add unrelated todo --- packages/framework/src/Foundation/PageCollection.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index cc0b1ec2b87..5e6018a0a70 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -24,6 +24,9 @@ * This class is stored as a singleton in the HydeKernel. * You would commonly access it via one of the facades: * + * @todo We could improve this by catching exceptions and rethrowing them using a + * DiscoveryException to make it clear that the problem is with the discovery process. + * * @see \Hyde\Foundation\Facades\PageCollection * @see \Hyde\Hyde::pages() */ From 62524150ae172e55b32a147d4a2e51f65e5a38a0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:34:34 +0100 Subject: [PATCH 043/100] Revert "Make protected test helpers public static" This reverts commit c4a2b53150d8e9e8cffe798ac9abef66ff02dbf0. --- packages/framework/tests/Feature/PublicationTypeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 572291bdd90..e9a034f360c 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -63,7 +63,7 @@ public function testCanSaveToJsonFileUsingCustomPath() File::deleteDirectory(Hyde::path('test-publication')); } - public static function getTestData(): array + protected function getTestData(): array { return [ 'name' => 'test', @@ -80,7 +80,7 @@ public static function getTestData(): array ]; } - public static function getTestDataWithPathInformation(): array + protected function getTestDataWithPathInformation(): array { return array_merge(self::getTestData(), [ 'directory' => 'test-publication', From b518e5e2f5966d886e3bbed8fb0cc3c059057751 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:34:37 +0100 Subject: [PATCH 044/100] Revert "Use self for static method" This reverts commit 49e33f32b3ac1aca14e88c487d9d299426a7a673. --- packages/framework/tests/Feature/PublicationTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index e9a034f360c..487fd084400 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -82,7 +82,7 @@ protected function getTestData(): array protected function getTestDataWithPathInformation(): array { - return array_merge(self::getTestData(), [ + return array_merge($this->getTestData(), [ 'directory' => 'test-publication', ]); } From 9ac2da17e1a3540cb1a96ab3643660161e7c7580 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:35:54 +0100 Subject: [PATCH 045/100] Extract testing trait --- .../Testing/Helpers/TestsPublications.php | 37 +++++++++++++++++++ .../tests/Feature/PublicationTypeTest.php | 27 ++------------ 2 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php diff --git a/packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php b/packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php new file mode 100644 index 00000000000..5542e287403 --- /dev/null +++ b/packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php @@ -0,0 +1,37 @@ + 'test', + 'canonicalField' => 'canonical', + 'sortField' => 'sort', + 'sortDirection' => 'asc', + 'pagesize' => 10, + 'prevNextLinks' => true, + 'detailTemplate' => 'detail', + 'listTemplate' => 'list', + 'fields' => [ + 'foo' => 'bar', + ], + ]; + } + + protected function getTestDataWithPathInformation(): array + { + return array_merge($this->getTestData(), [ + 'directory' => 'test-publication', + ]); + } +} diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 487fd084400..a9bb67ac491 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Framework\Testing\Helpers\TestsPublications; use Hyde\Hyde; use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; @@ -14,6 +15,8 @@ */ class PublicationTypeTest extends TestCase { + use TestsPublications; + public function testCanConstructNewPublicationType() { $publicationType = new PublicationType(...$this->getTestData()); @@ -62,28 +65,4 @@ public function testCanSaveToJsonFileUsingCustomPath() File::deleteDirectory(Hyde::path('test-publication')); } - - protected function getTestData(): array - { - return [ - 'name' => 'test', - 'canonicalField' => 'canonical', - 'sortField' => 'sort', - 'sortDirection' => 'asc', - 'pagesize' => 10, - 'prevNextLinks' => true, - 'detailTemplate' => 'detail', - 'listTemplate' => 'list', - 'fields' => [ - 'foo' => 'bar', - ], - ]; - } - - protected function getTestDataWithPathInformation(): array - { - return array_merge($this->getTestData(), [ - 'directory' => 'test-publication', - ]); - } } From 64009b818d11f5c9a8a9ce43795bb2945d04bb8d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:37:04 +0100 Subject: [PATCH 046/100] Revert "Extract testing trait" This reverts commit 9ac2da17e1a3540cb1a96ab3643660161e7c7580. --- .../Testing/Helpers/TestsPublications.php | 37 ------------------- .../tests/Feature/PublicationTypeTest.php | 27 ++++++++++++-- 2 files changed, 24 insertions(+), 40 deletions(-) delete mode 100644 packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php diff --git a/packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php b/packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php deleted file mode 100644 index 5542e287403..00000000000 --- a/packages/framework/tests/Feature/Hyde/Framework/Testing/Helpers/TestsPublications.php +++ /dev/null @@ -1,37 +0,0 @@ - 'test', - 'canonicalField' => 'canonical', - 'sortField' => 'sort', - 'sortDirection' => 'asc', - 'pagesize' => 10, - 'prevNextLinks' => true, - 'detailTemplate' => 'detail', - 'listTemplate' => 'list', - 'fields' => [ - 'foo' => 'bar', - ], - ]; - } - - protected function getTestDataWithPathInformation(): array - { - return array_merge($this->getTestData(), [ - 'directory' => 'test-publication', - ]); - } -} diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index a9bb67ac491..487fd084400 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -5,7 +5,6 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Framework\Features\Publications\Models\PublicationType; -use Hyde\Framework\Testing\Helpers\TestsPublications; use Hyde\Hyde; use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; @@ -15,8 +14,6 @@ */ class PublicationTypeTest extends TestCase { - use TestsPublications; - public function testCanConstructNewPublicationType() { $publicationType = new PublicationType(...$this->getTestData()); @@ -65,4 +62,28 @@ public function testCanSaveToJsonFileUsingCustomPath() File::deleteDirectory(Hyde::path('test-publication')); } + + protected function getTestData(): array + { + return [ + 'name' => 'test', + 'canonicalField' => 'canonical', + 'sortField' => 'sort', + 'sortDirection' => 'asc', + 'pagesize' => 10, + 'prevNextLinks' => true, + 'detailTemplate' => 'detail', + 'listTemplate' => 'list', + 'fields' => [ + 'foo' => 'bar', + ], + ]; + } + + protected function getTestDataWithPathInformation(): array + { + return array_merge($this->getTestData(), [ + 'directory' => 'test-publication', + ]); + } } From 8a55a3e0267f3b42ae82c7e47a2e9cc5434e2a10 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:37:54 +0100 Subject: [PATCH 047/100] Copy over test helper method --- .../tests/Feature/PublicationListPageTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index cd3997b88a8..4e369457e93 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -66,4 +66,21 @@ protected function getPublicationType(): PublicationType { return PublicationType::fromFile('test-publication/schema.json'); } + + protected function getTestData(): array + { + return [ + 'name' => 'test', + 'canonicalField' => 'canonical', + 'sortField' => 'sort', + 'sortDirection' => 'asc', + 'pagesize' => 10, + 'prevNextLinks' => true, + 'detailTemplate' => 'detail', + 'listTemplate' => 'list', + 'fields' => [ + 'foo' => 'bar', + ], + ]; + } } From a14a51ec0dfe323abb2bdb9c0bf35516227a202b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:38:00 +0100 Subject: [PATCH 048/100] Use test helper method --- .../framework/tests/Feature/PublicationListPageTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 4e369457e93..6182c772531 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -44,11 +44,7 @@ public function test_listing_page_can_be_compiled() protected function createPublicationFiles(): void { mkdir(Hyde::path('test-publication')); - file_put_contents(Hyde::path('test-publication/schema.json'), json_encode([ - 'foo' => 'bar', - 'detailTemplate' => 'test_detail', - 'listTemplate' => 'test_list', - ])); + file_put_contents(Hyde::path('test-publication/schema.json'), json_encode($this->getTestData())); file_put_contents( Hyde::path('test-publication/foo.md'), '--- From 8d9b044a5dba6e341bf7f80ad9a037ae287b4e02 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:38:43 +0100 Subject: [PATCH 049/100] Use getter instead of protected property --- .../src/Framework/Features/Publications/PublicationHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/PublicationHelper.php b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php index 655a005cc26..066d8fd7df3 100644 --- a/packages/framework/src/Framework/Features/Publications/PublicationHelper.php +++ b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php @@ -87,7 +87,7 @@ public static function getPublicationTypes(): Collection public static function getPublicationsForPubType(PublicationType $pubType, $sort = true): Collection { $root = base_path(); - $files = glob("$root/{$pubType->directory}/*.md"); + $files = glob("$root/{$pubType->getDirectory()}/*.md"); $publications = Collection::create(); foreach ($files as $file) { @@ -109,7 +109,7 @@ public static function getPublicationsForPubType(PublicationType $pubType, $sort public static function getMediaForPubType(PublicationType $pubType, $sort = true): Collection { $root = Hyde::path(); - $files = glob("$root/_media/{$pubType->directory}/*.{jpg,jpeg,png,gif,pdf}", GLOB_BRACE); + $files = glob("$root/_media/{$pubType->getDirectory()}/*.{jpg,jpeg,png,gif,pdf}", GLOB_BRACE); $media = Collection::create(); foreach ($files as $file) { From e3704d0407fba81f1d739e706cc64da98cee4ba6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:39:53 +0100 Subject: [PATCH 050/100] Update to use added class properties --- .../Features/Publications/Models/PublicationListPage.php | 2 +- packages/framework/src/Pages/PublicationPage.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 45a2ee03eec..e656b8aded2 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -37,7 +37,7 @@ public function compile(): string 'publications' => PublicationHelper::getPublicationsForPubType($this->type), ]; - $template = $this->type->getSchema()['listTemplate']; + $template = $this->type->listTemplate; if (str_contains($template, '::')) { return view($template, $data)->render(); } diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 7ce93a1ce84..481f833bdff 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -47,7 +47,7 @@ protected function renderComponent(): string 'publication' => $this, ]; - $template = $this->type->getSchema()['detailTemplate']; + $template = $this->type->detailTemplate; if (str_contains($template, '::')) { return view($template, $data)->render(); } From d47805335547c8f7cfcc7d0b8db0ad42895844d0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:41:42 +0100 Subject: [PATCH 051/100] Check if file exists and throw more explicit exception when missing --- .../Features/Publications/Models/PublicationListPage.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index e656b8aded2..cc9fc4c8f49 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Features\Publications\Models; +use InvalidArgumentException; use function file_get_contents; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Hyde; @@ -43,8 +44,12 @@ public function compile(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. + $viewPath = Hyde::path("{$this->type->getDirectory()}/$template") . '.blade.php'; + if (! file_exists($viewPath)) { + throw new InvalidArgumentException("View [$viewPath] not found."); + } return Blade::render( - file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template").'.blade.php'), $data + file_get_contents($viewPath), $data ); } From 5305c3ab50f304ba452bfd3f33dcb6640a1e59da Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:43:02 +0100 Subject: [PATCH 052/100] Update path to match test data --- packages/framework/tests/Feature/PublicationListPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 6182c772531..2a693369f3b 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -32,7 +32,7 @@ public function test_listing_page_can_be_compiled() { $this->createPublicationFiles(); - file_put_contents(Hyde::path('test-publication/test_list.blade.php'), 'Listing Page'); + file_put_contents(Hyde::path('test-publication/list.blade.php'), 'Listing Page'); $page = new PublicationListPage($this->getPublicationType()); From 9cb167d7c874a0563c6406440194d1e79717bd14 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 20:43:14 +0000 Subject: [PATCH 053/100] Apply fixes from StyleCI --- .../Features/Publications/Models/PublicationListPage.php | 5 +++-- .../Features/Publications/Models/PublicationType.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index cc9fc4c8f49..2553f2e6af8 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -4,12 +4,12 @@ namespace Hyde\Framework\Features\Publications\Models; -use InvalidArgumentException; use function file_get_contents; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Hyde; use Hyde\Pages\BladePage; use Illuminate\Support\Facades\Blade; +use InvalidArgumentException; use function str_contains; use function view; @@ -44,10 +44,11 @@ public function compile(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - $viewPath = Hyde::path("{$this->type->getDirectory()}/$template") . '.blade.php'; + $viewPath = Hyde::path("{$this->type->getDirectory()}/$template").'.blade.php'; if (! file_exists($viewPath)) { throw new InvalidArgumentException("View [$viewPath] not found."); } + return Blade::render( file_get_contents($viewPath), $data ); diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index aeaef580af5..a59ce3b9034 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,9 +4,8 @@ namespace Hyde\Framework\Features\Publications\Models; -use Exception; -use RuntimeException; use function dirname; +use Exception; use function file_get_contents; use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Hyde; @@ -14,6 +13,7 @@ use Illuminate\Contracts\Support\Arrayable; use function json_decode; use JsonSerializable; +use RuntimeException; /** * @see \Hyde\Framework\Testing\Feature\PublicationTypeTest From 164b7e2a8efaa9b9ea8d46a6dc2ab63db22b07c5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:45:56 +0100 Subject: [PATCH 054/100] Create test-publication-schema.json --- tests/fixtures/test-publication-schema.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/fixtures/test-publication-schema.json diff --git a/tests/fixtures/test-publication-schema.json b/tests/fixtures/test-publication-schema.json new file mode 100644 index 00000000000..1d0b10cfb09 --- /dev/null +++ b/tests/fixtures/test-publication-schema.json @@ -0,0 +1,13 @@ +{ + "name": "test", + "canonicalField": "canonical", + "sortField": "sort", + "sortDirection": "asc", + "pagesize": 10, + "prevNextLinks": true, + "detailTemplate": "detail", + "listTemplate": "list", + "fields": { + "foo": "bar" + } +} \ No newline at end of file From c1388b0ddecd292ac61de97c860d7eea7883ff4a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:48:22 +0100 Subject: [PATCH 055/100] Use testing fixture --- packages/framework/tests/Feature/PageCollectionTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index b96db553a41..5945151f457 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -17,6 +17,8 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; +use function copy; + /** * @covers \Hyde\Foundation\PageCollection * @covers \Hyde\Foundation\Concerns\BaseFoundationCollection @@ -207,7 +209,7 @@ public function test_listing_pages_for_publications_are_discovered() protected function createPublication(): void { - file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); + copy(Hyde::path('tests/fixtures/test-publication-schema.json'), Hyde::path('publication/schema.json')); file_put_contents(Hyde::path('publication/foo.md'), '--- __canonical: canonical From e9823d731a924de801c9b79764082fac46030fe4 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 20:48:32 +0000 Subject: [PATCH 056/100] Apply fixes from StyleCI --- packages/framework/tests/Feature/PageCollectionTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 5945151f457..e362066295a 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Feature; +use function copy; use Hyde\Foundation\PageCollection; use Hyde\Framework\Features\Publications\Models\PublicationListPage; use Hyde\Hyde; @@ -17,8 +18,6 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; -use function copy; - /** * @covers \Hyde\Foundation\PageCollection * @covers \Hyde\Foundation\Concerns\BaseFoundationCollection From 8290b5f2f3004add56b7d70e07be7382ce4f60c2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 21:50:54 +0100 Subject: [PATCH 057/100] Use testing fixture --- packages/framework/tests/Feature/PublicationPageTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 8a27a448465..b427adfdd9e 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Feature; +use function copy; use function deleteDirectory; use function file_put_contents; use Hyde\Framework\Features\Publications\Models\PublicationType; @@ -128,7 +129,7 @@ protected function createRealPublicationFiles(): void protected function createPublicationFiles(): void { - file_put_contents(Hyde::path('test-publication/schema.json'), json_encode(['foo' => 'bar'])); + copy(Hyde::path('tests/fixtures/test-publication-schema.json'), Hyde::path('test-publication/schema.json')); file_put_contents( Hyde::path('test-publication/foo.md'), '--- From 80d53db762c6bc5f88f6caeb7917d6c5b569ecd7 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 20:51:06 +0000 Subject: [PATCH 058/100] Apply fixes from StyleCI --- packages/framework/tests/Feature/PublicationPageTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index b427adfdd9e..e74fa0c701d 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -12,7 +12,6 @@ use Hyde\Pages\PublicationPage; use Hyde\Support\Models\Route; use Hyde\Testing\TestCase; -use function json_encode; use function mkdir; /** From 07996b9023ed61a6d8a6deb0d5600c4a3f7073e7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:08:36 +0100 Subject: [PATCH 059/100] Test can load from JSON files --- .../framework/tests/Feature/PublicationTypeTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 487fd084400..55f66ce1553 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -9,6 +9,8 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; +use function array_merge; + /** * @covers \Hyde\Framework\Features\Publications\Models\PublicationType */ @@ -63,6 +65,15 @@ public function testCanSaveToJsonFileUsingCustomPath() File::deleteDirectory(Hyde::path('test-publication')); } + public function testCanLoadFromJsonFile() + { + $publicationType = new PublicationType(...array_merge($this->getTestData(), [ + 'directory' => 'tests/fixtures', + ])); + + $this->assertEquals($publicationType, PublicationType::fromFile(Hyde::path('tests/fixtures/test-publication-schema.json'))); + } + protected function getTestData(): array { return [ From 0080771433eb7309196b50ac58624418b23cbafa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:10:33 +0100 Subject: [PATCH 060/100] Merge directory into array and use array unpacking for constructor --- .../Features/Publications/Models/PublicationType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index a59ce3b9034..20748c28dcb 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -45,8 +45,8 @@ public static function fromFile(string $schemaFile): static try { $directory = Hyde::pathToRelative(dirname($schemaFile)); $schema = static::parseSchema($schemaFile); - - return new static($schema['name'], $schema['canonicalField'], $schema['sortField'], $schema['sortDirection'], $schema['pagesize'], $schema['prevNextLinks'], $schema['detailTemplate'], $schema['listTemplate'], $schema['fields'], $directory); + $schema['directory'] ??= $directory; + return new static(...$schema); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); } From 5fae8da3c3cee99fd8c98951382ea88eb6127ed4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:12:31 +0100 Subject: [PATCH 061/100] Use array merge instead of coalesce assignment --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 20748c28dcb..0b527f1de0a 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -45,7 +45,7 @@ public static function fromFile(string $schemaFile): static try { $directory = Hyde::pathToRelative(dirname($schemaFile)); $schema = static::parseSchema($schemaFile); - $schema['directory'] ??= $directory; + $schema = array_merge($schema, ['directory' => $schema['directory'] ?? $directory]); return new static(...$schema); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); From 7926eebfb3e53142f52856bc68187f9bf6abae5d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:12:58 +0100 Subject: [PATCH 062/100] Inline local variable --- .../Framework/Features/Publications/Models/PublicationType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 0b527f1de0a..304cfdaa7ae 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -43,9 +43,8 @@ public static function get(string $name): static public static function fromFile(string $schemaFile): static { try { - $directory = Hyde::pathToRelative(dirname($schemaFile)); $schema = static::parseSchema($schemaFile); - $schema = array_merge($schema, ['directory' => $schema['directory'] ?? $directory]); + $schema = array_merge($schema, ['directory' => $schema['directory'] ?? Hyde::pathToRelative(dirname($schemaFile))]); return new static(...$schema); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); From 50670367b11fbc2b353a889ffa9f3292a64fb58a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:13:26 +0100 Subject: [PATCH 063/100] Rename internal helper method --- .../Features/Publications/Models/PublicationType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 304cfdaa7ae..3070ff65dd6 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -43,7 +43,7 @@ public static function get(string $name): static public static function fromFile(string $schemaFile): static { try { - $schema = static::parseSchema($schemaFile); + $schema = static::parseSchemaFile($schemaFile); $schema = array_merge($schema, ['directory' => $schema['directory'] ?? Hyde::pathToRelative(dirname($schemaFile))]); return new static(...$schema); } catch (Exception $exception) { @@ -100,7 +100,7 @@ public function save(?string $path = null): void file_put_contents($path, json_encode($this->toArray(), JSON_PRETTY_PRINT)); } - protected static function parseSchema(string $schemaFile): array + protected static function parseSchemaFile(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); } From f72db5554f90881e9ca20c426d9eafd49c4f6fc1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:14:04 +0100 Subject: [PATCH 064/100] Extract semantic helper method --- .../Features/Publications/Models/PublicationType.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 3070ff65dd6..5c6686c0c13 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -44,7 +44,7 @@ public static function fromFile(string $schemaFile): static { try { $schema = static::parseSchemaFile($schemaFile); - $schema = array_merge($schema, ['directory' => $schema['directory'] ?? Hyde::pathToRelative(dirname($schemaFile))]); + $schema = array_merge($schema, ['directory' => $schema['directory'] ?? self::getRelativeDirectoryName($schemaFile)]); return new static(...$schema); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); @@ -104,4 +104,9 @@ protected static function parseSchemaFile(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); } + + protected static function getRelativeDirectoryName(string $schemaFile): string + { + return Hyde::pathToRelative(dirname($schemaFile)); + } } From 259df4a6e9bd68e9e8c36fa9f96022211ecb807e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:14:58 +0100 Subject: [PATCH 065/100] Remove always null variable as value cannot be gotten from schema file --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 5c6686c0c13..6fc6d0a06dc 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -44,7 +44,7 @@ public static function fromFile(string $schemaFile): static { try { $schema = static::parseSchemaFile($schemaFile); - $schema = array_merge($schema, ['directory' => $schema['directory'] ?? self::getRelativeDirectoryName($schemaFile)]); + $schema = array_merge($schema, ['directory' => self::getRelativeDirectoryName($schemaFile)]); return new static(...$schema); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); From 4742052219d2d248bf8f13ab23e96aafb8bae53b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:15:45 +0100 Subject: [PATCH 066/100] Inline local variable --- .../Framework/Features/Publications/Models/PublicationType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 6fc6d0a06dc..7223f6230fc 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -44,8 +44,7 @@ public static function fromFile(string $schemaFile): static { try { $schema = static::parseSchemaFile($schemaFile); - $schema = array_merge($schema, ['directory' => self::getRelativeDirectoryName($schemaFile)]); - return new static(...$schema); + return new static(...array_merge($schema, ['directory' => self::getRelativeDirectoryName($schemaFile)])); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); } From 02448c0e06f72454458d7c9c9f2b04ab0c6492f2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:16:00 +0100 Subject: [PATCH 067/100] Inline local variable --- .../Framework/Features/Publications/Models/PublicationType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 7223f6230fc..af8ce563213 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -43,8 +43,7 @@ public static function get(string $name): static public static function fromFile(string $schemaFile): static { try { - $schema = static::parseSchemaFile($schemaFile); - return new static(...array_merge($schema, ['directory' => self::getRelativeDirectoryName($schemaFile)])); + return new static(...array_merge(static::parseSchemaFile($schemaFile), ['directory' => self::getRelativeDirectoryName($schemaFile)])); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); } From e1272590730076d3fb56ed8392d956d010133dba Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:16:46 +0100 Subject: [PATCH 068/100] Shift array semantics --- .../Features/Publications/Models/PublicationType.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index af8ce563213..628df7947d8 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -43,7 +43,7 @@ public static function get(string $name): static public static function fromFile(string $schemaFile): static { try { - return new static(...array_merge(static::parseSchemaFile($schemaFile), ['directory' => self::getRelativeDirectoryName($schemaFile)])); + return new static(...array_merge(static::parseSchemaFile($schemaFile), self::getRelativeDirectoryName($schemaFile))); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); } @@ -103,8 +103,8 @@ protected static function parseSchemaFile(string $schemaFile): array return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); } - protected static function getRelativeDirectoryName(string $schemaFile): string + protected static function getRelativeDirectoryName(string $schemaFile): array { - return Hyde::pathToRelative(dirname($schemaFile)); + return ['directory' => Hyde::pathToRelative(dirname($schemaFile))]; } } From 6daf303b781d697e334a25cec380848a56929ff5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:17:14 +0100 Subject: [PATCH 069/100] Wrap long line to multiple lines --- .../Features/Publications/Models/PublicationType.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 628df7947d8..452e66b72f4 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -43,7 +43,10 @@ public static function get(string $name): static public static function fromFile(string $schemaFile): static { try { - return new static(...array_merge(static::parseSchemaFile($schemaFile), self::getRelativeDirectoryName($schemaFile))); + return new static(...array_merge( + static::parseSchemaFile($schemaFile), + self::getRelativeDirectoryName($schemaFile)) + ); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); } From 145148cd61bb7853923e35daf1dade1b3dbd10a1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 22:17:23 +0100 Subject: [PATCH 070/100] Use static instead of self --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 452e66b72f4..f02963eb346 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -45,7 +45,7 @@ public static function fromFile(string $schemaFile): static try { return new static(...array_merge( static::parseSchemaFile($schemaFile), - self::getRelativeDirectoryName($schemaFile)) + static::getRelativeDirectoryName($schemaFile)) ); } catch (Exception $exception) { throw new RuntimeException("Could not parse schema file $schemaFile", 0, $exception); From 9284f573308711393c9455f8c96c9536104d2bc2 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 21:19:43 +0000 Subject: [PATCH 071/100] Apply fixes from StyleCI --- packages/framework/tests/Feature/PublicationTypeTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 55f66ce1553..07772fcb3ab 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -4,13 +4,12 @@ namespace Hyde\Framework\Testing\Feature; +use function array_merge; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; -use function array_merge; - /** * @covers \Hyde\Framework\Features\Publications\Models\PublicationType */ From 554ef9fa99032e2a1bee73e8d81737166276d925 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 12:59:38 +0100 Subject: [PATCH 072/100] Breaking: Change publication schema property pagesize to pageSize --- .../src/Console/Commands/MakePublicationTypeCommand.php | 8 ++++---- .../Framework/Actions/CreatesNewPublicationTypeSchema.php | 4 ++-- .../Features/Publications/Models/PublicationType.php | 8 ++++---- .../Feature/Commands/MakePublicationTypeCommandTest.php | 4 ++-- .../framework/tests/Feature/PublicationListPageTest.php | 2 +- packages/framework/tests/Feature/PublicationPageTest.php | 2 +- packages/framework/tests/Feature/PublicationTypeTest.php | 2 +- tests/fixtures/test-publication-schema.json | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 5ad6e763335..d335f2dc6d5 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -60,10 +60,10 @@ public function handle(): int 2 => 'DESC', }; - $pagesize = (int) PublicationHelper::askWithValidation( + $pageSize = (int) PublicationHelper::askWithValidation( $this, - 'pagesize', - 'Enter the pagesize (0 for no limit)', + 'pageSize', + 'Enter the pageSize (0 for no limit)', ['required', 'integer', 'between:0,100'], 25 ); @@ -86,7 +86,7 @@ public function handle(): int $canonicalField = $fields[$selected - 1]['name']; try { - $creator = new CreatesNewPublicationTypeSchema($title, $fields, $canonicalField, $sortField, $sortDirection, $pagesize, $prevNextLinks); + $creator = new CreatesNewPublicationTypeSchema($title, $fields, $canonicalField, $sortField, $sortDirection, $pageSize, $prevNextLinks); $creator->create(); } catch (Exception $e) { $this->error('Error: '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine()); diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php index 927bcbd684c..0dcf00e459b 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php @@ -29,7 +29,7 @@ public function __construct( protected string $canonicalField, protected string $sortField, protected string $sortDirection, - protected int $pagesize, + protected int $pageSize, protected bool $prevNextLinks ) { } @@ -45,7 +45,7 @@ public function create(): void $data['canonicalField'] = $this->canonicalField; $data['sortField'] = $this->sortField; $data['sortDirection'] = $this->sortDirection; - $data['pagesize'] = $this->pagesize; + $data['pageSize'] = $this->pageSize; $data['prevNextLinks'] = $this->prevNextLinks; $data['detailTemplate'] = "{$dirName}_detail"; $data['listTemplate'] = "{$dirName}_list"; diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index f02963eb346..f6e11847d40 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -29,7 +29,7 @@ class PublicationType implements JsonSerializable, Arrayable public string $canonicalField; public string $sortField; public string $sortDirection; - public int $pagesize; + public int $pageSize; public bool $prevNextLinks; public string $detailTemplate; public string $listTemplate; @@ -52,13 +52,13 @@ public static function fromFile(string $schemaFile): static } } - public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pagesize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $directory = null) + public function __construct(string $name, string $canonicalField, string $sortField, string $sortDirection, int $pageSize, bool $prevNextLinks, string $detailTemplate, string $listTemplate, array $fields, ?string $directory = null) { $this->name = $name; $this->canonicalField = $canonicalField; $this->sortField = $sortField; $this->sortDirection = $sortDirection; - $this->pagesize = $pagesize; + $this->pageSize = $pageSize; $this->prevNextLinks = $prevNextLinks; $this->detailTemplate = $detailTemplate; $this->listTemplate = $listTemplate; @@ -76,7 +76,7 @@ public function toArray(): array 'canonicalField' => $this->canonicalField, 'sortField' => $this->sortField, 'sortDirection' => $this->sortDirection, - 'pagesize' => $this->pagesize, + 'pageSize' => $this->pageSize, 'prevNextLinks' => $this->prevNextLinks, 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index fca80e2026a..0dce2735f7f 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -24,7 +24,7 @@ public function test_command_creates_publication() ->expectsQuestion('Add another field (y/n)', 'n') ->expectsQuestion('Sort field (0-1)', 0) ->expectsQuestion('Sort field (1-2)', 1) - ->expectsQuestion('Enter the pagesize (0 for no limit)', 10) + ->expectsQuestion('Enter the pageSize (0 for no limit)', 10) ->expectsQuestion('Generate previous/next links in detail view (y/n)', 'n') ->expectsQuestion('Canonical field (1-1)', 1) ->expectsOutputToContain('Creating a new Publication Type!') @@ -43,7 +43,7 @@ public function test_command_creates_publication() "canonicalField": "Title", "sortField": "__createdAt", "sortDirection": "ASC", - "pagesize": 10, + "pageSize": 10, "prevNextLinks": true, "detailTemplate": "test-publication_detail", "listTemplate": "test-publication_list", diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 2a693369f3b..0f392ba0b00 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -70,7 +70,7 @@ protected function getTestData(): array 'canonicalField' => 'canonical', 'sortField' => 'sort', 'sortDirection' => 'asc', - 'pagesize' => 10, + 'pageSize' => 10, 'prevNextLinks' => true, 'detailTemplate' => 'detail', 'listTemplate' => 'list', diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index e74fa0c701d..46dd99e72c8 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -97,7 +97,7 @@ protected function createRealPublicationFiles(): void "canonicalField": "slug", "sortField": "__createdAt", "sortDirection": "DESC", - "pagesize": 0, + "pageSize": 0, "prevNextLinks": true, "detailTemplate": "test_detail", "listTemplate": "test_list", diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 07772fcb3ab..266c02befbe 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -80,7 +80,7 @@ protected function getTestData(): array 'canonicalField' => 'canonical', 'sortField' => 'sort', 'sortDirection' => 'asc', - 'pagesize' => 10, + 'pageSize' => 10, 'prevNextLinks' => true, 'detailTemplate' => 'detail', 'listTemplate' => 'list', diff --git a/tests/fixtures/test-publication-schema.json b/tests/fixtures/test-publication-schema.json index 1d0b10cfb09..4ed5899266e 100644 --- a/tests/fixtures/test-publication-schema.json +++ b/tests/fixtures/test-publication-schema.json @@ -3,7 +3,7 @@ "canonicalField": "canonical", "sortField": "sort", "sortDirection": "asc", - "pagesize": 10, + "pageSize": 10, "prevNextLinks": true, "detailTemplate": "detail", "listTemplate": "list", From 84a9c33885eb193bc8f3148aa0107fc3d2fa32da Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:07:08 +0100 Subject: [PATCH 073/100] Add getIdentifier method --- .../Features/Publications/Models/PublicationType.php | 6 ++++++ .../framework/tests/Feature/PublicationTypeTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index f6e11847d40..b6b2a1efea7 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Features\Publications\Models; +use Illuminate\Support\Str; use function dirname; use Exception; use function file_get_contents; @@ -84,6 +85,11 @@ public function toArray(): array ]; } + public function getIdentifier(): string + { + return $this->directory ?? Str::slug($this->name); + } + public function getSchemaFile(): string { return "$this->directory/schema.json"; diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 266c02befbe..b76f3cf0525 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -42,6 +42,18 @@ public function testGetDirectory() $this->assertSame('test-publication', $publicationType->getDirectory()); } + public function testGetIdentifier() + { + $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); + $this->assertSame('test-publication', $publicationType->getIdentifier()); + } + + public function testGetIdentifierWithNoDirectory() + { + $publicationType = new PublicationType(...$this->getTestData()); + $this->assertSame('test', $publicationType->getIdentifier()); + } + public function testCanSaveToJsonFile() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); From 8789b253e89736096fe32903d872fd1f2d923b6c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:07:28 +0100 Subject: [PATCH 074/100] Update case --- .../tests/Feature/PublicationTypeTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index b76f3cf0525..c570d0c4574 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -15,7 +15,7 @@ */ class PublicationTypeTest extends TestCase { - public function testCanConstructNewPublicationType() + public function test_can_construct_new_publication_type() { $publicationType = new PublicationType(...$this->getTestData()); @@ -24,37 +24,37 @@ public function testCanConstructNewPublicationType() } } - public function testClassIsArrayable() + public function test_class_is_arrayable() { $publicationType = new PublicationType(...$this->getTestData()); $this->assertSame($this->getTestData(), $publicationType->toArray()); } - public function testClassIsJsonSerializable() + public function test_class_is_json_serializable() { $publicationType = new PublicationType(...$this->getTestData()); $this->assertSame(json_encode($this->getTestData()), json_encode($publicationType)); } - public function testGetDirectory() + public function test_get_directory() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); $this->assertSame('test-publication', $publicationType->getDirectory()); } - public function testGetIdentifier() + public function test_get_identifier() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); $this->assertSame('test-publication', $publicationType->getIdentifier()); } - public function testGetIdentifierWithNoDirectory() + public function test_get_identifier_with_no_directory() { $publicationType = new PublicationType(...$this->getTestData()); $this->assertSame('test', $publicationType->getIdentifier()); } - public function testCanSaveToJsonFile() + public function test_can_save_to_json_file() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); $publicationType->save(); @@ -65,7 +65,7 @@ public function testCanSaveToJsonFile() File::deleteDirectory(Hyde::path('test-publication')); } - public function testCanSaveToJsonFileUsingCustomPath() + public function test_can_save_to_json_file_using_custom_path() { $publicationType = new PublicationType(...$this->getTestData()); $publicationType->save('test-publication/foo.json'); @@ -76,7 +76,7 @@ public function testCanSaveToJsonFileUsingCustomPath() File::deleteDirectory(Hyde::path('test-publication')); } - public function testCanLoadFromJsonFile() + public function test_can_load_from_json_file() { $publicationType = new PublicationType(...array_merge($this->getTestData(), [ 'directory' => 'tests/fixtures', From 9a48a43b5dc82b0e3913acd4b5d608e8fbc22d4b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 21 Nov 2022 12:07:39 +0000 Subject: [PATCH 075/100] Apply fixes from StyleCI --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index b6b2a1efea7..e36a596f9e4 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Features\Publications\Models; -use Illuminate\Support\Str; use function dirname; use Exception; use function file_get_contents; @@ -12,6 +11,7 @@ use Hyde\Hyde; use Hyde\Support\Concerns\JsonSerializesArrayable; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Support\Str; use function json_decode; use JsonSerializable; use RuntimeException; From a470002bf5b9234a32fab02799229a8ebc53a4c4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:09:00 +0100 Subject: [PATCH 076/100] Use assertEqualsIgnoringLineEndingType --- .../tests/Feature/Commands/MakePublicationTypeCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index 0dce2735f7f..92c14426f00 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -35,7 +35,7 @@ public function test_command_creates_publication() ->assertExitCode(0); $this->assertFileExists(Hyde::path('test-publication/schema.json')); - $this->assertEquals( + $this->assertEqualsIgnoringLineEndingType( file_get_contents(Hyde::path('test-publication/schema.json')), <<<'JSON' { From 593ee68cac12b8ed713c6d584bf7339518383b36 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:10:02 +0100 Subject: [PATCH 077/100] Create CreatesNewPublicationTypeSchemaTest.php --- .../CreatesNewPublicationTypeSchemaTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/framework/tests/Feature/CreatesNewPublicationTypeSchemaTest.php diff --git a/packages/framework/tests/Feature/CreatesNewPublicationTypeSchemaTest.php b/packages/framework/tests/Feature/CreatesNewPublicationTypeSchemaTest.php new file mode 100644 index 00000000000..51e078fa367 --- /dev/null +++ b/packages/framework/tests/Feature/CreatesNewPublicationTypeSchemaTest.php @@ -0,0 +1,16 @@ + Date: Mon, 21 Nov 2022 13:12:46 +0100 Subject: [PATCH 078/100] Move test to sub namespace --- .../{ => Actions}/CreatesNewPublicationTypeSchemaTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename packages/framework/tests/Feature/{ => Actions}/CreatesNewPublicationTypeSchemaTest.php (66%) diff --git a/packages/framework/tests/Feature/CreatesNewPublicationTypeSchemaTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php similarity index 66% rename from packages/framework/tests/Feature/CreatesNewPublicationTypeSchemaTest.php rename to packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php index 51e078fa367..72788639681 100644 --- a/packages/framework/tests/Feature/CreatesNewPublicationTypeSchemaTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Feature; +namespace Hyde\Framework\Testing\Feature\Actions; -use Hyde\Framework\Actions\CreatesNewPublicationTypeSchema; use Hyde\Testing\TestCase; /** From 58e1980af9e3c77ff16a150435e5c0f41e6eb893 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:12:51 +0100 Subject: [PATCH 079/100] Update class PHPDoc --- .../src/Framework/Actions/CreatesNewPublicationTypeSchema.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php index 0dcf00e459b..0b96e4fd304 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php @@ -13,9 +13,9 @@ use function Safe\mkdir; /** - * Scaffold a new Markdown, Blade, or documentation page. + * Scaffold a new publication type schema. * - * @see \Hyde\Framework\Testing\Feature\Actions\CreatesNewPageSourceFileTest + * @see \Hyde\Framework\Testing\Feature\Actions\CreatesNewPublicationTypeSchemaTest */ class CreatesNewPublicationTypeSchema implements CreateActionInterface { From 5ab2e4e61b4c764e4b6200fb17d9d910d31339c3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:13:15 +0100 Subject: [PATCH 080/100] Rename CreatesNewPublicationTypeSchema to CreatesNewPublicationType --- .../src/Console/Commands/MakePublicationTypeCommand.php | 4 ++-- ...ublicationTypeSchema.php => CreatesNewPublicationType.php} | 2 +- .../Feature/Actions/CreatesNewPublicationTypeSchemaTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename packages/framework/src/Framework/Actions/{CreatesNewPublicationTypeSchema.php => CreatesNewPublicationType.php} (96%) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index d335f2dc6d5..a25e72e5485 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -6,7 +6,7 @@ use Exception; use Hyde\Console\Commands\Interfaces\CommandHandleInterface; -use Hyde\Framework\Actions\CreatesNewPublicationTypeSchema; +use Hyde\Framework\Actions\CreatesNewPublicationType; use Hyde\Framework\Features\Publications\PublicationHelper; use InvalidArgumentException; use LaravelZero\Framework\Commands\Command; @@ -86,7 +86,7 @@ public function handle(): int $canonicalField = $fields[$selected - 1]['name']; try { - $creator = new CreatesNewPublicationTypeSchema($title, $fields, $canonicalField, $sortField, $sortDirection, $pageSize, $prevNextLinks); + $creator = new CreatesNewPublicationType($title, $fields, $canonicalField, $sortField, $sortDirection, $pageSize, $prevNextLinks); $creator->create(); } catch (Exception $e) { $this->error('Error: '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine()); diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php similarity index 96% rename from packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php rename to packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index 0b96e4fd304..ba7aeb64066 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -17,7 +17,7 @@ * * @see \Hyde\Framework\Testing\Feature\Actions\CreatesNewPublicationTypeSchemaTest */ -class CreatesNewPublicationTypeSchema implements CreateActionInterface +class CreatesNewPublicationType implements CreateActionInterface { use InteractsWithDirectories; diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php index 72788639681..cd646ebe59a 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php @@ -7,7 +7,7 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Framework\Actions\CreatesNewPublicationTypeSchema + * @covers \Hyde\Framework\Actions\CreatesNewPublicationType */ class CreatesNewPublicationTypeSchemaTest extends TestCase { From dcad25e5e241e2e0dd2de941b7daf53c233695ad Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:17:28 +0100 Subject: [PATCH 081/100] Rename test for renamed class --- ...tionTypeSchemaTest.php => CreatesNewPublicationTypeTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/framework/tests/Feature/Actions/{CreatesNewPublicationTypeSchemaTest.php => CreatesNewPublicationTypeTest.php} (76%) diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php similarity index 76% rename from packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php rename to packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index cd646ebe59a..2dbb31d628a 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeSchemaTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -9,7 +9,7 @@ /** * @covers \Hyde\Framework\Actions\CreatesNewPublicationType */ -class CreatesNewPublicationTypeSchemaTest extends TestCase +class CreatesNewPublicationTypeTest extends TestCase { // } From ab28eaa2ca0b16b4d4dd7c69ab54e3615211d2dd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:21:21 +0100 Subject: [PATCH 082/100] Implement CreatesNewPublicationTypeTest --- .../Actions/CreatesNewPublicationTypeTest.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index 2dbb31d628a..ee1b40fcce5 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -4,12 +4,33 @@ namespace Hyde\Framework\Testing\Feature\Actions; +use Hyde\Framework\Actions\CreatesNewPublicationType; +use Hyde\Hyde; use Hyde\Testing\TestCase; +use Rgasch\Collection\Collection; + +use function deleteDirectory; /** * @covers \Hyde\Framework\Actions\CreatesNewPublicationType */ class CreatesNewPublicationTypeTest extends TestCase { - // + public function test_it_creates_a_new_publication_type() + { + $creator = new CreatesNewPublicationType('name', new Collection(), 'canonical', 'sort', 'asc', 10, true); + $creator->create(); + + $this->assertFileExists('name/schema.json'); + $this->assertStringContainsString('"name": "name"', $creator->getResult()); + $this->assertStringContainsString('"canonicalField": "canonical"', $creator->getResult()); + $this->assertStringContainsString('"sortField": "sort"', $creator->getResult()); + $this->assertStringContainsString('"sortDirection": "asc"', $creator->getResult()); + $this->assertStringContainsString('"pageSize": 10', $creator->getResult()); + $this->assertStringContainsString('"prevNextLinks": true', $creator->getResult()); + $this->assertStringContainsString('"detailTemplate": "name_detail"', $creator->getResult()); + $this->assertStringContainsString('"listTemplate": "name_list"', $creator->getResult()); + + deleteDirectory(Hyde::path('name')); + } } From 8feaf251cf32a81ffad0cc0e54235e8fddae8b1d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 21 Nov 2022 12:21:44 +0000 Subject: [PATCH 083/100] Apply fixes from StyleCI --- .../tests/Feature/Actions/CreatesNewPublicationTypeTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index ee1b40fcce5..7c47d4bcf92 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -4,13 +4,12 @@ namespace Hyde\Framework\Testing\Feature\Actions; +use function deleteDirectory; use Hyde\Framework\Actions\CreatesNewPublicationType; use Hyde\Hyde; use Hyde\Testing\TestCase; use Rgasch\Collection\Collection; -use function deleteDirectory; - /** * @covers \Hyde\Framework\Actions\CreatesNewPublicationType */ From cf0cbf67009e15ffbfe8cad33116bd4a1e8b3f52 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:27:46 +0100 Subject: [PATCH 084/100] Outfile should be absolute --- .../src/Framework/Actions/CreatesNewPublicationType.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index ba7aeb64066..c29e48ad78d 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -7,6 +7,7 @@ use Hyde\Framework\Actions\Interfaces\CreateActionInterface; use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Framework\Features\Publications\PublicationHelper; +use Hyde\Hyde; use Rgasch\Collection\Collection; use function Safe\file_put_contents; use function Safe\json_encode; @@ -37,7 +38,7 @@ public function __construct( public function create(): void { $dirName = PublicationHelper::formatNameForStorage($this->name); - $outFile = "$dirName/schema.json"; + $outFile = Hyde::path("$dirName/schema.json"); mkdir($dirName); $data = []; From c7dd3ea1079200ad999725ffb2f5d9e934d8a11c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:28:41 +0100 Subject: [PATCH 085/100] Print message as sprintf with relative path --- .../src/Framework/Actions/CreatesNewPublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index c29e48ad78d..96467fd4a64 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -54,7 +54,7 @@ public function create(): void $json = json_encode($data, JSON_PRETTY_PRINT); $this->result = $json; - echo "Saving publicationType data to [$outFile]\n"; + echo sprintf("Saving publicationType data to [%s]\n", Hyde::pathToRelative($outFile)); file_put_contents($outFile, $json); } From 0a5a91024d7e798ec55e589b9e90b7beaddd20a0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:29:12 +0100 Subject: [PATCH 086/100] Refactor to use the PublicationType object --- .../Actions/CreatesNewPublicationType.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index 96467fd4a64..7c2d37709ce 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -6,6 +6,7 @@ use Hyde\Framework\Actions\Interfaces\CreateActionInterface; use Hyde\Framework\Concerns\InteractsWithDirectories; +use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Hyde; use Rgasch\Collection\Collection; @@ -51,12 +52,25 @@ public function create(): void $data['detailTemplate'] = "{$dirName}_detail"; $data['listTemplate'] = "{$dirName}_list"; $data['fields'] = $this->fields; - $json = json_encode($data, JSON_PRETTY_PRINT); + + $type = new PublicationType( + $data['name'], + $data['canonicalField'], + $data['sortField'], + $data['sortDirection'], + $data['pageSize'], + $data['prevNextLinks'], + $data['detailTemplate'], + $data['listTemplate'], + $data['fields']->toArray() + ); + + $json = json_encode($type->toArray(), JSON_PRETTY_PRINT); $this->result = $json; echo sprintf("Saving publicationType data to [%s]\n", Hyde::pathToRelative($outFile)); - file_put_contents($outFile, $json); + $type->save($outFile); } public function getResult(): string From fd2aa8900646e17f144b61c9445a19060d64621e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:29:46 +0100 Subject: [PATCH 087/100] Remove mkdir handled by save method --- .../src/Framework/Actions/CreatesNewPublicationType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index 7c2d37709ce..ef2faba44cf 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -40,7 +40,6 @@ public function create(): void { $dirName = PublicationHelper::formatNameForStorage($this->name); $outFile = Hyde::path("$dirName/schema.json"); - mkdir($dirName); $data = []; $data['name'] = $this->name; From b2a08cbed715036b03f652bc4f587d26c80b42b7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:33:07 +0100 Subject: [PATCH 088/100] Implement Jsonable --- .../Features/Publications/Models/PublicationType.php | 8 +++++++- packages/framework/tests/Feature/PublicationTypeTest.php | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index e36a596f9e4..77c6a8f2f41 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Features\Publications\Models; +use Illuminate\Contracts\Support\Jsonable; use function dirname; use Exception; use function file_get_contents; @@ -19,7 +20,7 @@ /** * @see \Hyde\Framework\Testing\Feature\PublicationTypeTest */ -class PublicationType implements JsonSerializable, Arrayable +class PublicationType implements JsonSerializable, Jsonable, Arrayable { use JsonSerializesArrayable; use InteractsWithDirectories; @@ -85,6 +86,11 @@ public function toArray(): array ]; } + public function toJson($options = 0): string + { + return json_encode($this->toArray(), $options); + } + public function getIdentifier(): string { return $this->directory ?? Str::slug($this->name); diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index c570d0c4574..fa1ff459dbf 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -36,6 +36,12 @@ public function test_class_is_json_serializable() $this->assertSame(json_encode($this->getTestData()), json_encode($publicationType)); } + public function test_class_is_jsonable() + { + $publicationType = new PublicationType(...$this->getTestData()); + $this->assertSame(json_encode($this->getTestData()), $publicationType->toJson()); + } + public function test_get_directory() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); From 7dbf151dc7d48468f8cd365d7ae07ce6f21da8a2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:34:09 +0100 Subject: [PATCH 089/100] Default to pretty print JSON --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- packages/framework/tests/Feature/PublicationTypeTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 77c6a8f2f41..36f5f55aa13 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -86,7 +86,7 @@ public function toArray(): array ]; } - public function toJson($options = 0): string + public function toJson($options = JSON_PRETTY_PRINT): string { return json_encode($this->toArray(), $options); } diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index fa1ff459dbf..eeb80597b8b 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -39,7 +39,7 @@ public function test_class_is_json_serializable() public function test_class_is_jsonable() { $publicationType = new PublicationType(...$this->getTestData()); - $this->assertSame(json_encode($this->getTestData()), $publicationType->toJson()); + $this->assertSame(json_encode($this->getTestData(), 128), $publicationType->toJson()); } public function test_get_directory() From d85bd7ec3cfeccf496d932a6f273f7777d76ee73 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:34:28 +0100 Subject: [PATCH 090/100] Use toJson helper --- .../src/Framework/Actions/CreatesNewPublicationType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index ef2faba44cf..ef4c2688db4 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -64,8 +64,7 @@ public function create(): void $data['fields']->toArray() ); - $json = json_encode($type->toArray(), JSON_PRETTY_PRINT); - $this->result = $json; + $this->result = $type->toJson(); echo sprintf("Saving publicationType data to [%s]\n", Hyde::pathToRelative($outFile)); From 23683efe7f5b6414c66a0f9ff781b2d6728078dc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:35:28 +0100 Subject: [PATCH 091/100] Inline local array --- .../Actions/CreatesNewPublicationType.php | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index ef4c2688db4..484e865644d 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -41,27 +41,16 @@ public function create(): void $dirName = PublicationHelper::formatNameForStorage($this->name); $outFile = Hyde::path("$dirName/schema.json"); - $data = []; - $data['name'] = $this->name; - $data['canonicalField'] = $this->canonicalField; - $data['sortField'] = $this->sortField; - $data['sortDirection'] = $this->sortDirection; - $data['pageSize'] = $this->pageSize; - $data['prevNextLinks'] = $this->prevNextLinks; - $data['detailTemplate'] = "{$dirName}_detail"; - $data['listTemplate'] = "{$dirName}_list"; - $data['fields'] = $this->fields; - $type = new PublicationType( - $data['name'], - $data['canonicalField'], - $data['sortField'], - $data['sortDirection'], - $data['pageSize'], - $data['prevNextLinks'], - $data['detailTemplate'], - $data['listTemplate'], - $data['fields']->toArray() + $this->name, + $this->canonicalField, + $this->sortField, + $this->sortDirection, + $this->pageSize, + $this->prevNextLinks, + "{$dirName}_detail", + "{$dirName}_list", + $this->fields->toArray() ); $this->result = $type->toJson(); From c53be825143ef0460661b73c66e3f1d2fafe0db0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:36:23 +0100 Subject: [PATCH 092/100] Move down property assignment --- .../src/Framework/Actions/CreatesNewPublicationType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index 484e865644d..6a2b3dfb10c 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -53,11 +53,10 @@ public function create(): void $this->fields->toArray() ); - $this->result = $type->toJson(); - echo sprintf("Saving publicationType data to [%s]\n", Hyde::pathToRelative($outFile)); $type->save($outFile); + $this->result = $type->toJson(); } public function getResult(): string From 508f0d1afaabeb6afd7b1f9ebd0f97cfc172823f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:39:15 +0100 Subject: [PATCH 093/100] Pass along output style and use it instead of echo --- .../src/Console/Commands/MakePublicationTypeCommand.php | 2 +- .../src/Framework/Actions/CreatesNewPublicationType.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index a25e72e5485..66d96751fec 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -86,7 +86,7 @@ public function handle(): int $canonicalField = $fields[$selected - 1]['name']; try { - $creator = new CreatesNewPublicationType($title, $fields, $canonicalField, $sortField, $sortDirection, $pageSize, $prevNextLinks); + $creator = new CreatesNewPublicationType($title, $fields, $canonicalField, $sortField, $sortDirection, $pageSize, $prevNextLinks, $this->output); $creator->create(); } catch (Exception $e) { $this->error('Error: '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine()); diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index 6a2b3dfb10c..7269465c136 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -9,10 +9,12 @@ use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Hyde; +use Illuminate\Console\OutputStyle; use Rgasch\Collection\Collection; use function Safe\file_put_contents; use function Safe\json_encode; use function Safe\mkdir; +use function sprintf; /** * Scaffold a new publication type schema. @@ -32,7 +34,8 @@ public function __construct( protected string $sortField, protected string $sortDirection, protected int $pageSize, - protected bool $prevNextLinks + protected bool $prevNextLinks, + protected ?OutputStyle $output = null, ) { } @@ -53,7 +56,7 @@ public function create(): void $this->fields->toArray() ); - echo sprintf("Saving publicationType data to [%s]\n", Hyde::pathToRelative($outFile)); + $this->output?->writeln(sprintf('Saving publication data to [%s]', Hyde::pathToRelative($outFile))); $type->save($outFile); $this->result = $type->toJson(); From 4e50c471967ee20b8272c4cb2566fd3dcb2bc6ec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:39:45 +0100 Subject: [PATCH 094/100] Remove unused trait --- .../src/Framework/Actions/CreatesNewPublicationType.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index 7269465c136..d526d2863d4 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -23,8 +23,6 @@ */ class CreatesNewPublicationType implements CreateActionInterface { - use InteractsWithDirectories; - protected string $result; public function __construct( From 5fb5244ef410e7f99ab5ae9988604d66af496cc6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:41:30 +0100 Subject: [PATCH 095/100] Clean up imports --- .../src/Framework/Actions/CreatesNewPublicationType.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index d526d2863d4..f56372e7fce 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -5,15 +5,11 @@ namespace Hyde\Framework\Actions; use Hyde\Framework\Actions\Interfaces\CreateActionInterface; -use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Hyde; use Illuminate\Console\OutputStyle; use Rgasch\Collection\Collection; -use function Safe\file_put_contents; -use function Safe\json_encode; -use function Safe\mkdir; use function sprintf; /** From 09126ac8e3d9d57a1a7fac1999d5f31a9c5a9fb2 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 21 Nov 2022 12:42:14 +0000 Subject: [PATCH 096/100] Apply fixes from StyleCI --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 36f5f55aa13..2edabc268bc 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Features\Publications\Models; -use Illuminate\Contracts\Support\Jsonable; use function dirname; use Exception; use function file_get_contents; @@ -12,6 +11,7 @@ use Hyde\Hyde; use Hyde\Support\Concerns\JsonSerializesArrayable; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Contracts\Support\Jsonable; use Illuminate\Support\Str; use function json_decode; use JsonSerializable; From 586bda8027c8c013da9058684fb114158aa129aa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:43:31 +0100 Subject: [PATCH 097/100] Add linking tag --- .../tests/Feature/Actions/CreatesNewPublicationTypeTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index 7c47d4bcf92..692fe2a7340 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -12,6 +12,7 @@ /** * @covers \Hyde\Framework\Actions\CreatesNewPublicationType + * @see \Hyde\Console\Commands\MakePublicationTypeCommand */ class CreatesNewPublicationTypeTest extends TestCase { From 85ff16156bc54e096e6c35c8a7337871fa0c2b25 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:44:34 +0100 Subject: [PATCH 098/100] Expect fixed output --- .../tests/Feature/Commands/MakePublicationTypeCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index 92c14426f00..4127317235d 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -31,7 +31,7 @@ public function test_command_creates_publication() ->expectsOutput('Choose the default field you wish to sort by:') ->expectsOutput('Choose the default sort direction:') // ->expectsOutput('Publication type created successfully!') - // ->expectsOutput('Saving publicationType data to [test-publication/schema.json]') + ->expectsOutput('Saving publication data to [test-publication/schema.json]') ->assertExitCode(0); $this->assertFileExists(Hyde::path('test-publication/schema.json')); From f5251f491337f5b25f2184081d114f5973a8d4f3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 21 Nov 2022 13:45:49 +0100 Subject: [PATCH 099/100] Display finish output --- .../src/Console/Commands/MakePublicationTypeCommand.php | 1 + .../tests/Feature/Commands/MakePublicationTypeCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 66d96751fec..023eb5275a7 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -94,6 +94,7 @@ public function handle(): int return Command::FAILURE; } + $this->info('Publication type created successfully!'); return Command::SUCCESS; } diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index 4127317235d..79b7ad64464 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -30,8 +30,8 @@ public function test_command_creates_publication() ->expectsOutputToContain('Creating a new Publication Type!') ->expectsOutput('Choose the default field you wish to sort by:') ->expectsOutput('Choose the default sort direction:') - // ->expectsOutput('Publication type created successfully!') ->expectsOutput('Saving publication data to [test-publication/schema.json]') + ->expectsOutput('Publication type created successfully!') ->assertExitCode(0); $this->assertFileExists(Hyde::path('test-publication/schema.json')); From a2b2244b32cac2b468f554b9ad4ad161f770a3b8 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 21 Nov 2022 12:45:59 +0000 Subject: [PATCH 100/100] Apply fixes from StyleCI --- .../src/Console/Commands/MakePublicationTypeCommand.php | 1 + .../tests/Feature/Actions/CreatesNewPublicationTypeTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 023eb5275a7..5e302bb576d 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -95,6 +95,7 @@ public function handle(): int } $this->info('Publication type created successfully!'); + return Command::SUCCESS; } diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index 692fe2a7340..8d91c9c21e2 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -12,6 +12,7 @@ /** * @covers \Hyde\Framework\Actions\CreatesNewPublicationType + * * @see \Hyde\Console\Commands\MakePublicationTypeCommand */ class CreatesNewPublicationTypeTest extends TestCase