From e373d672afc7b44c3a324e45aa12c81f12268a5e Mon Sep 17 00:00:00 2001 From: markhuot Date: Tue, 13 Feb 2024 09:01:55 -0500 Subject: [PATCH 01/67] some craft5 compat --- .github/workflows/php.yml | 2 +- composer.json | 8 ++++---- src/console/IdeController.php | 3 ++- src/console/PestController.php | 3 ++- src/factories/Element.php | 2 +- src/factories/Entry.php | 8 ++++---- src/factories/Field.php | 4 ++-- src/factories/Section.php | 22 ++++++++++++++++++---- src/test/TestCase.php | 2 +- tests/DatabaseTest.php | 4 ++-- 10 files changed, 37 insertions(+), 21 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b365c14..a22cac5 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - version: [~4.5.0, ~4.6.0] + version: [~4.5.0, ~4.6.0, ~4.7.0, ~5.0.0] env: CRAFT_APP_ID: pest diff --git a/composer.json b/composer.json index ba761b7..fa6d55d 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ "symfony/css-selector": "^5.3|^6.0", "symfony/dom-crawler": "^6.0.3", "symfony/process": "^5.3|^6.0", - "illuminate/collections": "^8.23|^9.1|^10.0", "pestphp/pest": "^2.26", "vlucas/phpdotenv": "^2.4|^3.4|^5.4", - "craftcms/cms": "^4.5", - "illuminate/support": "^9.52" + "craftcms/cms": "^4.5|^5.0.0-beta.1", + "illuminate/support": "^9.52|^10.0", + "composer/composer": "^2.7" }, "autoload": { "psr-4": { @@ -53,7 +53,7 @@ "prefer-stable": true, "require-dev": { "craftcms/phpstan": "dev-main", - "craftcms/craft": "^2.0", + "craftcms/craft": "^2.0|^5.0.0-alpha.1", "symfony/var-dumper": "^5.0|^6.0", "laravel/pint": "^1.13" } diff --git a/src/console/IdeController.php b/src/console/IdeController.php index 6882e27..fc3cb70 100644 --- a/src/console/IdeController.php +++ b/src/console/IdeController.php @@ -22,7 +22,8 @@ public function options($actionID): array */ public function actionGenerateMixins() { - $result = (new RenderCompiledClasses)->handle($this->force); + //$result = (new RenderCompiledClasses)->handle($this->force); + $result = false; if ($result) { echo "Mixins successfully generated!\n"; diff --git a/src/console/PestController.php b/src/console/PestController.php index 16d3f8d..d6411ff 100644 --- a/src/console/PestController.php +++ b/src/console/PestController.php @@ -150,7 +150,8 @@ public function actionCompileTemplates() public function actionGenerateMixins() { - $result = (new RenderCompiledClasses)->handle($this->force); + // $result = (new RenderCompiledClasses)->handle($this->force); + $result = false; if ($result) { echo "Mixins successfully generated!\n"; diff --git a/src/factories/Element.php b/src/factories/Element.php index f4a8829..3703c0d 100644 --- a/src/factories/Element.php +++ b/src/factories/Element.php @@ -104,7 +104,7 @@ protected function setAttributes($attributes, $element) } // No need to progress further if the element doesn't support content or has no field layout - if (! $element::hasContent() || ! $element->getFieldLayout()) { + if (! $element->getFieldLayout()) { return $element; } diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 5676dac..43e12b3 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -131,14 +131,14 @@ public function inferSectionId() if (is_a($this->sectionIdentifier, \craft\models\Section::class)) { $section = $this->sectionIdentifier; } elseif (is_numeric($this->sectionIdentifier)) { - $section = \Craft::$app->sections->getSectionById($this->sectionIdentifier); + $section = \Craft::$app->getEntries()->getSectionById($this->sectionIdentifier); } elseif (is_string($this->sectionIdentifier)) { - $section = \Craft::$app->sections->getSectionByHandle($this->sectionIdentifier); + $section = \Craft::$app->getEntries()->getSectionByHandle($this->sectionIdentifier); } else { $reflector = new \ReflectionClass($this); $className = $reflector->getShortName(); $sectionHandle = lcfirst($className); - $section = \Craft::$app->sections->getSectionByHandle($sectionHandle); + $section = \Craft::$app->getEntries()->getSectionByHandle($sectionHandle); } if (empty($section)) { @@ -158,7 +158,7 @@ public function inferTypeId($sectionid): int $reflector = new \ReflectionClass($this); $className = $reflector->getShortName(); $typeHandle = lcfirst($className); - $section = \Craft::$app->sections->getSectionById($sectionid); + $section = \Craft::$app->getEntries()->getSectionById($sectionid); $matches = array_filter($section->entryTypes, fn ($e) => $e->handle === $typeHandle); if (count($matches) === 0) { $matches = $section->entryTypes; diff --git a/src/factories/Field.php b/src/factories/Field.php index 5d500e6..8212832 100644 --- a/src/factories/Field.php +++ b/src/factories/Field.php @@ -55,11 +55,11 @@ public function newElement() public function definition(int $index = 0) { $name = $this->faker->words(2, true); - $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; +// $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; return [ 'name' => $name, - 'groupId' => $firstFieldGroupId, +// 'groupId' => $firstFieldGroupId, ]; } diff --git a/src/factories/Section.php b/src/factories/Section.php index a4ec6f8..1e23440 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -2,7 +2,9 @@ namespace markhuot\craftpest\factories; +use Craft; use craft\helpers\StringHelper; +use craft\models\EntryType; use craft\models\Section_SiteSettings; use Faker\Factory as Faker; use Illuminate\Support\Collection; @@ -74,7 +76,7 @@ public function definition(int $index = 0) return [ 'name' => $name, - 'type' => 'channel', + 'type' => \craft\models\Section::TYPE_CHANNEL, ]; } @@ -86,14 +88,14 @@ public function inferences(array $definition = []) $name = $definition['name']; $handle = $definition['handle']; - $definition['siteSettings'] = collect(\Craft::$app->sites->getAllSites()) + $definition['siteSettings'] = collect(Craft::$app->sites->getAllSites()) ->mapWithkeys(function ($site) use ($name, $handle) { $settings = new Section_SiteSettings(); $settings->siteId = $site->id; $settings->hasUrls = $this->hasUrls; $settings->uriFormat = $this->uriFormat; $settings->enabledByDefault = $this->enabledByDefault; - $settings->template = \Craft::$app->view->renderObjectTemplate($this->template, [ + $settings->template = Craft::$app->view->renderObjectTemplate($this->template, [ 'name' => $name, 'handle' => $handle, ]); @@ -101,6 +103,16 @@ public function inferences(array $definition = []) return [$site->id => $settings]; })->toArray(); + if (empty($definition['entryTypes'])) { + $entryType = new EntryType([ + 'name' => $name = $this->faker->words(3, true), + 'handle' => StringHelper::toHandle($name), + ]); + Craft::$app->getEntries()->saveEntryType($entryType); + throw_if($entryType->errors, 'Problem saving entry type: ' . implode(', ', $entryType->getFirstErrors())); + $definition['entryTypes'] = [$entryType]; + } + return $definition; } @@ -111,7 +123,9 @@ public function inferences(array $definition = []) */ public function store($element) { - $result = \Craft::$app->sections->saveSection($element); + $result = Craft::$app->getEntries()->saveSection($element); + throw_unless(empty($element->errors), 'Problem saving section: ' . implode(', ', $element->getFirstErrors())); + $this->storeFields($element->entryTypes[0]->fieldLayout); return $result; diff --git a/src/test/TestCase.php b/src/test/TestCase.php index af18af0..175c060 100644 --- a/src/test/TestCase.php +++ b/src/test/TestCase.php @@ -200,7 +200,7 @@ protected function reRunPest() public function renderCompiledClasses() { - (new RenderCompiledClasses)->handle(); + // (new RenderCompiledClasses)->handle(); } protected function needsRequireStatements() diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index c813283..d59b853 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -11,13 +11,13 @@ $section = \markhuot\craftpest\factories\Section::factory()->create(); $entry = \markhuot\craftpest\factories\Entry::factory()->section($section)->create(); - $this->assertDatabaseHas(\craft\db\Table::CONTENT, [ + $this->assertDatabaseHas(\craft\db\Table::ELEMENTS_SITES, [ 'title' => $entry->title, ]); }); it('asserts database content is missing') - ->assertDatabaseMissing(\craft\db\Table::CONTENT, ['title' => 'fooz baz']); + ->assertDatabaseMissing(\craft\db\Table::ELEMENTS_SITES, ['title' => 'fooz baz']); it('asserts trashed', function () { $entry = Entry::factory() From 6968546992f131ec15132e8d73af36a23f65702f Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 08:05:17 -0500 Subject: [PATCH 02/67] bumping MySQL for Craft 5 --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a22cac5..37ac272 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -37,7 +37,7 @@ jobs: services: mysql: - image: mysql + image: mysql:8 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: pest From 6fcbb42f52492aaf48d6d5d75c9b9090ef0e05ee Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 08:10:46 -0500 Subject: [PATCH 03/67] Removing explicit colition https://github.com/craftcms/cms/issues/14332 --- stubs/config/db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/config/db.php b/stubs/config/db.php index 9f7b4b9..df111c9 100644 --- a/stubs/config/db.php +++ b/stubs/config/db.php @@ -13,5 +13,5 @@ 'schema' => App::env('CRAFT_DB_SCHEMA'), 'tablePrefix' => App::env('CRAFT_DB_TABLE_PREFIX'), 'charset' => 'utf8', - 'collation' => 'utf8_unicode_ci', + //'collation' => 'utf8_unicode_ci', ]; From 77f7af77c42cc619ca0b88391c2b7fc4d559af98 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 22:44:21 +0000 Subject: [PATCH 04/67] phpstan fixes for 4.x --- .phpunit.cache/test-results | 1 + src/Pest.php | 7 +++++++ src/console/IdeController.php | 1 + src/console/PestController.php | 1 + src/factories/Entry.php | 11 ++++++---- src/factories/Section.php | 23 +++++++++++++-------- src/helpers/Base.php | 11 ++++++++++ src/interfaces/SectionsServiceInterface.php | 14 +++++++++++++ tests/DebugTest.php | 7 +++++++ 9 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 .phpunit.cache/test-results create mode 100644 src/interfaces/SectionsServiceInterface.php create mode 100644 tests/DebugTest.php diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results new file mode 100644 index 0000000..1467b12 --- /dev/null +++ b/.phpunit.cache/test-results @@ -0,0 +1 @@ +{"version":"pest_2.33.4","defects":[],"times":{"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":0.17}} \ No newline at end of file diff --git a/src/Pest.php b/src/Pest.php index 3bea7ae..29d3976 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -12,6 +12,7 @@ use markhuot\craftpest\behaviors\TestableElementBehavior; use markhuot\craftpest\behaviors\TestableElementQueryBehavior; use markhuot\craftpest\console\PestController; +use markhuot\craftpest\interfaces\SectionsServiceInterface; use yii\base\BootstrapInterface; use yii\base\Event; @@ -52,5 +53,11 @@ function (DefineBehaviorsEvent $event) { $event->behaviors['fieldTypeHintBehavior'] = FieldTypeHintBehavior::class; } ); + + Craft::$container->set(SectionsServiceInterface::class, function () { + return version_compare(Craft::$app->version, '5.0.0', '>=') ? + Craft::$app->getEntries() : + Craft::$app->getSections(); + }); } } diff --git a/src/console/IdeController.php b/src/console/IdeController.php index fc3cb70..ffc2ecf 100644 --- a/src/console/IdeController.php +++ b/src/console/IdeController.php @@ -25,6 +25,7 @@ public function actionGenerateMixins() //$result = (new RenderCompiledClasses)->handle($this->force); $result = false; + // @phpstan-ignore-next-line if ($result) { echo "Mixins successfully generated!\n"; } else { diff --git a/src/console/PestController.php b/src/console/PestController.php index d6411ff..a20dcbd 100644 --- a/src/console/PestController.php +++ b/src/console/PestController.php @@ -153,6 +153,7 @@ public function actionGenerateMixins() // $result = (new RenderCompiledClasses)->handle($this->force); $result = false; + // @phpstan-ignore-next-line if ($result) { echo "Mixins successfully generated!\n"; } else { diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 43e12b3..681865c 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -4,8 +4,11 @@ use craft\models\EntryType; use markhuot\craftpest\factories\Section as FactoriesSection; +use markhuot\craftpest\interfaces\SectionsServiceInterface; use markhuot\craftpest\storage\FactoryFields; +use function markhuot\craftpest\helpers\base\service; + /** * Entry Factory * @@ -131,14 +134,14 @@ public function inferSectionId() if (is_a($this->sectionIdentifier, \craft\models\Section::class)) { $section = $this->sectionIdentifier; } elseif (is_numeric($this->sectionIdentifier)) { - $section = \Craft::$app->getEntries()->getSectionById($this->sectionIdentifier); + $section = service(SectionsServiceInterface::class)->getSectionById($this->sectionIdentifier); } elseif (is_string($this->sectionIdentifier)) { - $section = \Craft::$app->getEntries()->getSectionByHandle($this->sectionIdentifier); + $section = service(SectionsServiceInterface::class)->getSectionByHandle($this->sectionIdentifier); } else { $reflector = new \ReflectionClass($this); $className = $reflector->getShortName(); $sectionHandle = lcfirst($className); - $section = \Craft::$app->getEntries()->getSectionByHandle($sectionHandle); + $section = service(SectionsServiceInterface::class)->getSectionByHandle($sectionHandle); } if (empty($section)) { @@ -158,7 +161,7 @@ public function inferTypeId($sectionid): int $reflector = new \ReflectionClass($this); $className = $reflector->getShortName(); $typeHandle = lcfirst($className); - $section = \Craft::$app->getEntries()->getSectionById($sectionid); + $section = service(SectionsServiceInterface::class)->getSectionById($sectionid); $matches = array_filter($section->entryTypes, fn ($e) => $e->handle === $typeHandle); if (count($matches) === 0) { $matches = $section->entryTypes; diff --git a/src/factories/Section.php b/src/factories/Section.php index 1e23440..2b2e454 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -8,6 +8,9 @@ use craft\models\Section_SiteSettings; use Faker\Factory as Faker; use Illuminate\Support\Collection; +use markhuot\craftpest\interfaces\SectionsServiceInterface; + +use function markhuot\craftpest\helpers\base\service; /** * @method self name(string $name) @@ -103,14 +106,16 @@ public function inferences(array $definition = []) return [$site->id => $settings]; })->toArray(); - if (empty($definition['entryTypes'])) { - $entryType = new EntryType([ - 'name' => $name = $this->faker->words(3, true), - 'handle' => StringHelper::toHandle($name), - ]); - Craft::$app->getEntries()->saveEntryType($entryType); - throw_if($entryType->errors, 'Problem saving entry type: ' . implode(', ', $entryType->getFirstErrors())); - $definition['entryTypes'] = [$entryType]; + if (version_compare(Craft::$app->version, '5.0.0', '>=')) { + if (empty($definition['entryTypes'])) { + $entryType = new EntryType([ + 'name' => $name = $this->faker->words(3, true), + 'handle' => StringHelper::toHandle($name), + ]); + service(SectionsServiceInterface::class)->saveEntryType($entryType); + throw_if($entryType->errors, 'Problem saving entry type: ' . implode(', ', $entryType->getFirstErrors())); + $definition['entryTypes'] = [$entryType]; + } } return $definition; @@ -123,7 +128,7 @@ public function inferences(array $definition = []) */ public function store($element) { - $result = Craft::$app->getEntries()->saveSection($element); + $result = service(SectionsServiceInterface::class)->saveSection($element); throw_unless(empty($element->errors), 'Problem saving section: ' . implode(', ', $element->getFirstErrors())); $this->storeFields($element->entryTypes[0]->fieldLayout); diff --git a/src/helpers/Base.php b/src/helpers/Base.php index 0ad45de..49b3207 100644 --- a/src/helpers/Base.php +++ b/src/helpers/Base.php @@ -2,6 +2,7 @@ namespace markhuot\craftpest\helpers\base; +use Craft; use Illuminate\Support\Collection; if (! function_exists('collection_wrap')) { @@ -32,3 +33,13 @@ function version_greater_than_or_equal_to(string $version1, string $version2) return version_compare($version1, $version2) >= 0; } } + +/** + * @template T + * @param class-string $className + * @return T + */ +function service(string $className) +{ + return Craft::$container->get($className); +} diff --git a/src/interfaces/SectionsServiceInterface.php b/src/interfaces/SectionsServiceInterface.php new file mode 100644 index 0000000..97b7fe1 --- /dev/null +++ b/src/interfaces/SectionsServiceInterface.php @@ -0,0 +1,14 @@ +version); +}); \ No newline at end of file From 84e01325df00e7623b9d4c0e06564d904fe48fa9 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 23:05:59 +0000 Subject: [PATCH 05/67] phpstan fixes --- .github/workflows/php.yml | 2 ++ phpstan.neon | 1 + src/Pest.php | 4 ++-- src/factories/Field.php | 16 +++++++++++----- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 37ac272..0e1cf6a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -90,6 +90,8 @@ jobs: - name: Run pint run: ./vendor/bin/pint --test -vvv src/ + if: success() || failure() - name: Run test suite run: ./vendor/bin/pest --compact -vvv + if: success() || failure() diff --git a/phpstan.neon b/phpstan.neon index 9843abd..cdd9712 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,3 +15,4 @@ parameters: excludePaths: - src/craft/* - src/illuminate/* + - src/actions/RenderCompiledClasses.php diff --git a/src/Pest.php b/src/Pest.php index 29d3976..7880d28 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -56,8 +56,8 @@ function (DefineBehaviorsEvent $event) { Craft::$container->set(SectionsServiceInterface::class, function () { return version_compare(Craft::$app->version, '5.0.0', '>=') ? - Craft::$app->getEntries() : - Craft::$app->getSections(); + Craft::$app->getEntries() : // @phpstan-ignore-line + Craft::$app->getSections(); // @phpstan-ignore-line }); } } diff --git a/src/factories/Field.php b/src/factories/Field.php index 8212832..cb85339 100644 --- a/src/factories/Field.php +++ b/src/factories/Field.php @@ -2,6 +2,7 @@ namespace markhuot\craftpest\factories; +use Craft; use craft\helpers\StringHelper; /** @@ -23,7 +24,7 @@ public function type(string $type) public function group(string $groupName) { $this->attributes['groupId'] = function () use ($groupName) { - foreach (\Craft::$app->fields->getAllGroups() as $group) { + foreach (\Craft::$app->fields->getAllGroups() as $group) { //@phpstan-ignore-line if ($group->name === $groupName) { return $group->id; } @@ -55,12 +56,17 @@ public function newElement() public function definition(int $index = 0) { $name = $this->faker->words(2, true); -// $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; - - return [ + + $definition = [ 'name' => $name, -// 'groupId' => $firstFieldGroupId, ]; + + if (version_compare(Craft::$app->version, '5.0.0', '<')) { + $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; // @phpstan-ignore-line + $definition['groupId'] = $firstFieldGroupId; + } + + return $definition; } public function inferences(array $definition = []) From 35c115505b44db8395ec08ef99dc144f15557d32 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 23:09:41 +0000 Subject: [PATCH 06/67] rerun pint and force all tests to run --- .github/workflows/php.yml | 4 ++-- src/factories/Field.php | 4 ++-- src/factories/Section.php | 4 ++-- src/helpers/Base.php | 3 ++- src/interfaces/SectionsServiceInterface.php | 3 +++ tests/DebugTest.php | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 0e1cf6a..f24d642 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -90,8 +90,8 @@ jobs: - name: Run pint run: ./vendor/bin/pint --test -vvv src/ - if: success() || failure() + if: always() - name: Run test suite run: ./vendor/bin/pest --compact -vvv - if: success() || failure() + if: always() diff --git a/src/factories/Field.php b/src/factories/Field.php index cb85339..6ab8793 100644 --- a/src/factories/Field.php +++ b/src/factories/Field.php @@ -56,11 +56,11 @@ public function newElement() public function definition(int $index = 0) { $name = $this->faker->words(2, true); - + $definition = [ 'name' => $name, ]; - + if (version_compare(Craft::$app->version, '5.0.0', '<')) { $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; // @phpstan-ignore-line $definition['groupId'] = $firstFieldGroupId; diff --git a/src/factories/Section.php b/src/factories/Section.php index 2b2e454..e9a8e28 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -113,7 +113,7 @@ public function inferences(array $definition = []) 'handle' => StringHelper::toHandle($name), ]); service(SectionsServiceInterface::class)->saveEntryType($entryType); - throw_if($entryType->errors, 'Problem saving entry type: ' . implode(', ', $entryType->getFirstErrors())); + throw_if($entryType->errors, 'Problem saving entry type: '.implode(', ', $entryType->getFirstErrors())); $definition['entryTypes'] = [$entryType]; } } @@ -129,7 +129,7 @@ public function inferences(array $definition = []) public function store($element) { $result = service(SectionsServiceInterface::class)->saveSection($element); - throw_unless(empty($element->errors), 'Problem saving section: ' . implode(', ', $element->getFirstErrors())); + throw_unless(empty($element->errors), 'Problem saving section: '.implode(', ', $element->getFirstErrors())); $this->storeFields($element->entryTypes[0]->fieldLayout); diff --git a/src/helpers/Base.php b/src/helpers/Base.php index 49b3207..3c35c2d 100644 --- a/src/helpers/Base.php +++ b/src/helpers/Base.php @@ -36,7 +36,8 @@ function version_greater_than_or_equal_to(string $version1, string $version2) /** * @template T - * @param class-string $className + * + * @param class-string $className * @return T */ function service(string $className) diff --git a/src/interfaces/SectionsServiceInterface.php b/src/interfaces/SectionsServiceInterface.php index 97b7fe1..df425f2 100644 --- a/src/interfaces/SectionsServiceInterface.php +++ b/src/interfaces/SectionsServiceInterface.php @@ -8,7 +8,10 @@ interface SectionsServiceInterface { public function saveSection(Section $section): bool; + public function saveEntryType(EntryType $entryType): bool; + public function getSectionById(int $id): ?Section; + public function getSectionByHandle(string $handle): ?Section; } diff --git a/tests/DebugTest.php b/tests/DebugTest.php index 90e0f33..44e5bde 100644 --- a/tests/DebugTest.php +++ b/tests/DebugTest.php @@ -2,6 +2,6 @@ use function markhuot\craftpest\helpers\test\dd; -it('debugs', function() { +it('debugs', function () { dd(\Craft::$app->version); -}); \ No newline at end of file +}); From 13906f0a729f65c40d7f2d21d3bda7369decf1ef Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 23:18:25 +0000 Subject: [PATCH 07/67] removing bad test --- tests/DebugTest.php | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/DebugTest.php diff --git a/tests/DebugTest.php b/tests/DebugTest.php deleted file mode 100644 index 44e5bde..0000000 --- a/tests/DebugTest.php +++ /dev/null @@ -1,7 +0,0 @@ -version); -}); From a1b70f6b969fdbf21f7c3b4ef6930a09561ee5f3 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 23:22:01 +0000 Subject: [PATCH 08/67] fixing bad cache --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f24d642..eb11fc2 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -66,7 +66,7 @@ jobs: path: | composer.lock vendor - key: ${{ runner.os }}-craft-vendor-${{ hashFiles('composer.json') }} + key: ${{ runner.os }}-craft-${{ matrix.version }}-vendor-${{ hashFiles('composer.json') }} - name: Install dependencies run: | From 8dd5b51748163fd474455569126b8db80ff63f71 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 19:39:07 -0500 Subject: [PATCH 09/67] fixing table name for 4.x --- tests/DatabaseTest.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index d59b853..c4f9eb2 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -1,5 +1,6 @@ create(); $entry = \markhuot\craftpest\factories\Entry::factory()->section($section)->create(); - $this->assertDatabaseHas(\craft\db\Table::ELEMENTS_SITES, [ + $table = version_compare(Craft::$app->version, '5.0.0', '>=') ? \craft\db\Table::ELEMENTS_SITES : \craft\db\Table::CONTENT; + $this->assertDatabaseHas($table, [ 'title' => $entry->title, ]); }); -it('asserts database content is missing') - ->assertDatabaseMissing(\craft\db\Table::ELEMENTS_SITES, ['title' => 'fooz baz']); +it('asserts database content is missing', function () { + $table = version_compare(Craft::$app->version, '5.0.0', '>=') ? \craft\db\Table::ELEMENTS_SITES : \craft\db\Table::CONTENT; + $this->assertDatabaseMissing($table, ['title' => 'fooz baz']); +}); it('asserts trashed', function () { $entry = Entry::factory() From b317c45190cc47a2cd8415f890fc517a789c087e Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 12:05:15 +0000 Subject: [PATCH 10/67] accountig for missing matrix blocks --- src/pest/MonkeyPatches.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pest/MonkeyPatches.php b/src/pest/MonkeyPatches.php index a76be69..6f42046 100644 --- a/src/pest/MonkeyPatches.php +++ b/src/pest/MonkeyPatches.php @@ -20,9 +20,11 @@ public function boot(): void $asset = preg_replace('/(class Asset.+?\{)/s', '$1 use \\markhuot\\craftpest\\traits\\Snapshotable;', $asset); eval($asset); - $matrixBlock = file_get_contents($vendorDir.'/craftcms/cms/src/elements/MatrixBlock.php'); - $matrixBlock = preg_replace('/^<\?php/', '', $matrixBlock); - $matrixBlock = preg_replace('/(class MatrixBlock.+?\{)/s', '$1 use \\markhuot\\craftpest\\traits\\Snapshotable;', $matrixBlock); - eval($matrixBlock); + if (file_exists($vendorDir.'/craftcms/cms/src/elements/MatrixBlock.php')) { + $matrixBlock = file_get_contents($vendorDir.'/craftcms/cms/src/elements/MatrixBlock.php'); + $matrixBlock = preg_replace('/^<\?php/', '', $matrixBlock); + $matrixBlock = preg_replace('/(class MatrixBlock.+?\{)/s', '$1 use \\markhuot\\craftpest\\traits\\Snapshotable;', $matrixBlock); + eval($matrixBlock); + } } } From 2ff51378d0583057a8cbc751819102d5b4e8b586 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 12:07:35 +0000 Subject: [PATCH 11/67] removing unecessary code --- tests/DatabaseTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index c4f9eb2..7c8ae36 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -1,6 +1,5 @@ Date: Sun, 18 Feb 2024 12:24:58 +0000 Subject: [PATCH 12/67] abstracting version check --- .phpunit.cache/test-results | 2 +- composer.json | 3 ++- src/Pest.php | 3 ++- src/factories/Section.php | 4 +++- src/helpers/Craft.php | 6 ++++++ tests/DatabaseTest.php | 6 ++++-- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results index 1467b12..68149c9 100644 --- a/.phpunit.cache/test-results +++ b/.phpunit.cache/test-results @@ -1 +1 @@ -{"version":"pest_2.33.4","defects":[],"times":{"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":0.17}} \ No newline at end of file +{"version":"pest_2.34.0","defects":{"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":8,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":8,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":8,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":8,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_entries_and_rolls_back":8,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_fields_and_rolls_back":8,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_errors_when_trying_to_create_fields_after_content_elements":7,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_channels":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_structures":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_hasUrls_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_uriFormat_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_enabledByDefault_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_template_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_entries_with_section_id__handle__and_object":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_place_fields_in_groups":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_fields":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via_method#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_with___count__#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via___create___definition#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_takes_an_array_of_entries#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_allows_you_to_use___set____on_a_factory":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":8,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":8},"times":{"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_factory":0.229,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_email_address":0.048,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_user_objects":0.036,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_admins_via_shorthand":1.511,"P\\Tests\\ActingAsTest::__pest_evaluable_it_throws_on_missing_users":0.032,"P\\Tests\\ActingAsTest::__pest_evaluable_it_should_not_be_logged_in_on_subsequent_tests":0.026,"P\\Tests\\ActingAsTest::__pest_evaluable_it_acts_as_a_user_on_get_requests":0.224,"P\\Tests\\ActingAsTest::__pest_evaluable_it_creates_admin_users":0.614,"P\\Tests\\ActingAsTest::__pest_evaluable_it_resets_globals_during_twig_parsing":0.188,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_duplicate_queries":0.086,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_query_speed":0.097,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_load_time":0.134,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_memory_usage":0.205,"P\\Tests\\BootstrapTest::__pest_evaluable_it_can_bootstrap_craft":0.04,"P\\Tests\\CookieTest::__pest_evaluable_it_receives_cookies":0.069,"P\\Tests\\CookieTest::__pest_evaluable_it_sends_cookies":0.084,"P\\Tests\\CookieTest::__pest_evaluable_it_retains_cookies":0.098,"P\\Tests\\CookieTest::__pest_evaluable_it_doesn_t_have_any_cookies_from_previous_tests":0.071,"P\\Tests\\CoverageTest::__pest_evaluable_it_does_not_run_a_conditional":0.078,"P\\Tests\\CoverageTest::__pest_evaluable_it_runs_a_conditional_via_a_query_var":0.092,"P\\Tests\\CoverageTest::__pest_evaluable_get___loop_test__\u2192_assertOk_":0.131,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content":0.013,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_on_condition":0.153,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_is_missing":0.004,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_trashed":0.065,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":0.055,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":0.029,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":0.029,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_volumes_and_assets":0.579,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_an_asset_from_a_source":0.411,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_set_the_folder":0.226,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_with_no_props":0.335,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_disables_posts":0.107,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_post_date":0.12,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_throws_on_bad_post_date":0.029,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_expiry_date":0.209,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_user_object":0.264,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_id":0.161,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_username":0.197,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_entry_parent":0.037,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":0.041,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_entries_and_rolls_back":0.042,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_fields_and_rolls_back":0.052,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_errors_when_trying_to_create_fields_after_content_elements":0.195,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields":0.689,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields_with_multiple_blocks":0.646,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":0.065,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":0.067,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":0.071,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":0.102,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_channels":0.066,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_structures":0.064,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_hasUrls_of_the_section":0.161,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_uriFormat_of_the_section":0.069,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_enabledByDefault_of_the_section":0.105,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_template_of_the_section":0.185,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_entries_with_section_id__handle__and_object":0.119,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_fill_an_entries_field":0.251,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_place_fields_in_groups":0.066,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_fields":0.078,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via_method#(Closure)":0.078,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_with___count__#(Closure)":0.169,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via___create___definition#(Closure)":0.26,"P\\Tests\\FactoryTest::__pest_evaluable_it_takes_an_array_of_entries#(Closure)":0.143,"P\\Tests\\FactoryTest::__pest_evaluable_it_allows_you_to_use___set____on_a_factory":0.238,"P\\Tests\\FormFieldTest::__pest_evaluable_it_renders_the_page_with_a_form":0.481,"P\\Tests\\FormFieldTest::__pest_evaluable_it_is_unhappy_when_no_form_found":0.172,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_a_field_and_collect_existing_fields":0.284,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_deal_with_many_forms_on_one_page":0.329,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_fields_with_array_style_names":0.48,"P\\Tests\\FormFieldTest::__pest_evaluable_it_does_not_see_disabled_fields":0.627,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields":0.434,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields_on_single_form_pages":0.203,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_create_virtual_fields":0.406,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":0.517,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":0.341,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":0.224,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":0.149,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_plugins":0.083,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_modules":0.087,"P\\Tests\\HttpCpTest::__pest_evaluable_it_posts_action_requests":0.1,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_to_an_action":0.45,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_json_to_an_action":0.2,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cache_tag":0.186,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_presence":0.24,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_value":0.269,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_valid":0.185,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_expired_cookies":0.308,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_cookies":0.315,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_201_Created_status_code":0.441,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_seeing_text":0.436,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_a_download":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_exact_json":0.303,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_path":0.548,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing":0.603,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_path":0.327,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_exact":0.526,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count":0.302,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count_with_path":0.235,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_fragment":0.262,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_structure":0.266,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_403_Forbidden_status_code":0.472,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_presence":0.31,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_value":0.255,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_header":0.515,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data":0.54,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data_by_key":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect":0.543,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_to":0.675,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_hostname":0.229,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_offsite_hostname":0.245,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_a_redirect":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects":0.511,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects_in_one_call":0.502,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_no_content":0.178,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_found":0.366,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string":0.294,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_in_order":0.478,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string_without_tags":0.565,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_without_tags_in_order":0.292,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_status":0.265,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_titles":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_unauthorized":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location":0.489,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path":0.497,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path_by_shorthand":0.821,"P\\Tests\\ResponseTest::__pest_evaluable_it_returns_HTML_for_exceptions":0.405,"P\\Tests\\ResponseTest::__pest_evaluable_it_can_skip_html_errors_and_bubble_the_actual_exception":0.379,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":0.414,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":0.163,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":0.223,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":0.466,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":0.316,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_seed_console_command":0.166,"P\\Tests\\SelectorTest::__pest_evaluable_it_finds_selectors":0.314,"P\\Tests\\SelectorTest::__pest_evaluable_it_expects_selectors":0.331,"P\\Tests\\SelectorTest::__pest_evaluable_it_gets_inner_html_by_class_name":0.363,"P\\Tests\\SelectorTest::__pest_evaluable_it_throws_on_unexpected_property":0.456,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_expectation_API":0.383,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_assertion_API":0.406,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_containing_string":0.619,"P\\Tests\\SelectorTest::__pest_evaluable_it_queries_a_nodelist":0.296,"P\\Tests\\SelectorTest::__pest_evaluable_it_clicks_links":0.323,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_attributes":0.4,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_html_snapshots":0.862,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_html_snapshots":0.584,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_dom_snapshots":0.413,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_dom_snapshots":0.361,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_snapshots":0.223,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_dom_snapshots":0.249,"P\\Tests\\SnapshotTest::__pest_evaluable_it_renders_views_with_variables":0.233,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshots":0.46,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshot_assertions":0.592,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_entry_snapshots":0.265,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_nested_entry_snapshots":0.575,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_collected_snapshots":0.639}} \ No newline at end of file diff --git a/composer.json b/composer.json index fa6d55d..59e1446 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "vlucas/phpdotenv": "^2.4|^3.4|^5.4", "craftcms/cms": "^4.5|^5.0.0-beta.1", "illuminate/support": "^9.52|^10.0", - "composer/composer": "^2.7" + "composer/composer": "^2.7", + "composer/semver": "^3.4" }, "autoload": { "psr-4": { diff --git a/src/Pest.php b/src/Pest.php index 7880d28..81d748e 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -2,6 +2,7 @@ namespace markhuot\craftpest; +use Composer\Semver\Semver; use Craft; use craft\base\Field; use craft\elements\db\ElementQuery; @@ -55,7 +56,7 @@ function (DefineBehaviorsEvent $event) { ); Craft::$container->set(SectionsServiceInterface::class, function () { - return version_compare(Craft::$app->version, '5.0.0', '>=') ? + return Semver::satisfies(Craft::$app->version, '~5.0.0') ? Craft::$app->getEntries() : // @phpstan-ignore-line Craft::$app->getSections(); // @phpstan-ignore-line }); diff --git a/src/factories/Section.php b/src/factories/Section.php index e9a8e28..2112f1c 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -2,6 +2,7 @@ namespace markhuot\craftpest\factories; +use Composer\Semver\Semver; use Craft; use craft\helpers\StringHelper; use craft\models\EntryType; @@ -11,6 +12,7 @@ use markhuot\craftpest\interfaces\SectionsServiceInterface; use function markhuot\craftpest\helpers\base\service; +use function markhuot\craftpest\helpers\craft\isCraftFive; /** * @method self name(string $name) @@ -106,7 +108,7 @@ public function inferences(array $definition = []) return [$site->id => $settings]; })->toArray(); - if (version_compare(Craft::$app->version, '5.0.0', '>=')) { + if (isCraftFive()) { if (empty($definition['entryTypes'])) { $entryType = new EntryType([ 'name' => $name = $this->faker->words(3, true), diff --git a/src/helpers/Craft.php b/src/helpers/Craft.php index a683e46..e0ca304 100644 --- a/src/helpers/Craft.php +++ b/src/helpers/Craft.php @@ -2,10 +2,16 @@ namespace markhuot\craftpest\helpers\craft; +use Composer\Semver\Semver; +use Craft; use craft\helpers\FileHelper; use function markhuot\craftpest\helpers\base\version_greater_than_or_equal_to; +function isCraftFive(): bool { + return Semver::satisfies(Craft::$app->version, '~5.0.0'); +} + /** * @codeCoverageIgnore */ diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 7c8ae36..89c2f15 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -2,6 +2,8 @@ use markhuot\craftpest\factories\Entry; +use function markhuot\craftpest\helpers\craft\isCraftFive; + it('asserts database content', function () { $count = (new \craft\db\Query)->from(\craft\db\Table::SITES)->count(); $this->assertDatabaseCount(\craft\db\Table::SITES, $count); @@ -11,14 +13,14 @@ $section = \markhuot\craftpest\factories\Section::factory()->create(); $entry = \markhuot\craftpest\factories\Entry::factory()->section($section)->create(); - $table = version_compare(Craft::$app->version, '5.0.0', '>=') ? \craft\db\Table::ELEMENTS_SITES : \craft\db\Table::CONTENT; + $table = isCraftFive() ? \craft\db\Table::ELEMENTS_SITES : \craft\db\Table::CONTENT; $this->assertDatabaseHas($table, [ 'title' => $entry->title, ]); }); it('asserts database content is missing', function () { - $table = version_compare(Craft::$app->version, '5.0.0', '>=') ? \craft\db\Table::ELEMENTS_SITES : \craft\db\Table::CONTENT; + $table = isCraftFive() ? \craft\db\Table::ELEMENTS_SITES : \craft\db\Table::CONTENT; $this->assertDatabaseMissing($table, ['title' => 'fooz baz']); }); From a57c08158318cf1f5384bd7b80605d8335d5fb5f Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 12:33:03 +0000 Subject: [PATCH 13/67] avoiding Craft 4-isms while testing Craft 5 --- .phpunit.cache/test-results | 2 +- src/factories/Field.php | 5 ++++- src/helpers/Craft.php | 4 ++++ tests/FactoryTest.php | 21 +++++++++++++-------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results index 68149c9..44316d8 100644 --- a/.phpunit.cache/test-results +++ b/.phpunit.cache/test-results @@ -1 +1 @@ -{"version":"pest_2.34.0","defects":{"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":8,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":8,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":8,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":8,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_entries_and_rolls_back":8,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_fields_and_rolls_back":8,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_errors_when_trying_to_create_fields_after_content_elements":7,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_channels":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_structures":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_hasUrls_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_uriFormat_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_enabledByDefault_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_template_of_the_section":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_entries_with_section_id__handle__and_object":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_place_fields_in_groups":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_fields":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via_method#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_with___count__#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via___create___definition#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_takes_an_array_of_entries#(Closure)":8,"P\\Tests\\FactoryTest::__pest_evaluable_it_allows_you_to_use___set____on_a_factory":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":8,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":8},"times":{"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_factory":0.229,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_email_address":0.048,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_user_objects":0.036,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_admins_via_shorthand":1.511,"P\\Tests\\ActingAsTest::__pest_evaluable_it_throws_on_missing_users":0.032,"P\\Tests\\ActingAsTest::__pest_evaluable_it_should_not_be_logged_in_on_subsequent_tests":0.026,"P\\Tests\\ActingAsTest::__pest_evaluable_it_acts_as_a_user_on_get_requests":0.224,"P\\Tests\\ActingAsTest::__pest_evaluable_it_creates_admin_users":0.614,"P\\Tests\\ActingAsTest::__pest_evaluable_it_resets_globals_during_twig_parsing":0.188,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_duplicate_queries":0.086,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_query_speed":0.097,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_load_time":0.134,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_memory_usage":0.205,"P\\Tests\\BootstrapTest::__pest_evaluable_it_can_bootstrap_craft":0.04,"P\\Tests\\CookieTest::__pest_evaluable_it_receives_cookies":0.069,"P\\Tests\\CookieTest::__pest_evaluable_it_sends_cookies":0.084,"P\\Tests\\CookieTest::__pest_evaluable_it_retains_cookies":0.098,"P\\Tests\\CookieTest::__pest_evaluable_it_doesn_t_have_any_cookies_from_previous_tests":0.071,"P\\Tests\\CoverageTest::__pest_evaluable_it_does_not_run_a_conditional":0.078,"P\\Tests\\CoverageTest::__pest_evaluable_it_runs_a_conditional_via_a_query_var":0.092,"P\\Tests\\CoverageTest::__pest_evaluable_get___loop_test__\u2192_assertOk_":0.131,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content":0.013,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_on_condition":0.153,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_is_missing":0.004,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_trashed":0.065,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":0.055,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":0.029,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":0.029,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_volumes_and_assets":0.579,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_an_asset_from_a_source":0.411,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_set_the_folder":0.226,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_with_no_props":0.335,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_disables_posts":0.107,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_post_date":0.12,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_throws_on_bad_post_date":0.029,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_expiry_date":0.209,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_user_object":0.264,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_id":0.161,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_username":0.197,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_entry_parent":0.037,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":0.041,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_entries_and_rolls_back":0.042,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_fields_and_rolls_back":0.052,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_errors_when_trying_to_create_fields_after_content_elements":0.195,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields":0.689,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields_with_multiple_blocks":0.646,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":0.065,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":0.067,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":0.071,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":0.102,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_channels":0.066,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_structures":0.064,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_hasUrls_of_the_section":0.161,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_uriFormat_of_the_section":0.069,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_enabledByDefault_of_the_section":0.105,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_template_of_the_section":0.185,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_entries_with_section_id__handle__and_object":0.119,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_fill_an_entries_field":0.251,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_place_fields_in_groups":0.066,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_fields":0.078,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via_method#(Closure)":0.078,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_with___count__#(Closure)":0.169,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via___create___definition#(Closure)":0.26,"P\\Tests\\FactoryTest::__pest_evaluable_it_takes_an_array_of_entries#(Closure)":0.143,"P\\Tests\\FactoryTest::__pest_evaluable_it_allows_you_to_use___set____on_a_factory":0.238,"P\\Tests\\FormFieldTest::__pest_evaluable_it_renders_the_page_with_a_form":0.481,"P\\Tests\\FormFieldTest::__pest_evaluable_it_is_unhappy_when_no_form_found":0.172,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_a_field_and_collect_existing_fields":0.284,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_deal_with_many_forms_on_one_page":0.329,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_fields_with_array_style_names":0.48,"P\\Tests\\FormFieldTest::__pest_evaluable_it_does_not_see_disabled_fields":0.627,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields":0.434,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields_on_single_form_pages":0.203,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_create_virtual_fields":0.406,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":0.517,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":0.341,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":0.224,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":0.149,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_plugins":0.083,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_modules":0.087,"P\\Tests\\HttpCpTest::__pest_evaluable_it_posts_action_requests":0.1,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_to_an_action":0.45,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_json_to_an_action":0.2,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cache_tag":0.186,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_presence":0.24,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_value":0.269,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_valid":0.185,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_expired_cookies":0.308,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_cookies":0.315,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_201_Created_status_code":0.441,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_seeing_text":0.436,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_a_download":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_exact_json":0.303,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_path":0.548,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing":0.603,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_path":0.327,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_exact":0.526,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count":0.302,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count_with_path":0.235,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_fragment":0.262,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_structure":0.266,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_403_Forbidden_status_code":0.472,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_presence":0.31,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_value":0.255,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_header":0.515,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data":0.54,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data_by_key":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect":0.543,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_to":0.675,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_hostname":0.229,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_offsite_hostname":0.245,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_a_redirect":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects":0.511,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects_in_one_call":0.502,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_no_content":0.178,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_found":0.366,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string":0.294,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_in_order":0.478,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string_without_tags":0.565,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_without_tags_in_order":0.292,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_status":0.265,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_titles":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_unauthorized":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location":0.489,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path":0.497,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path_by_shorthand":0.821,"P\\Tests\\ResponseTest::__pest_evaluable_it_returns_HTML_for_exceptions":0.405,"P\\Tests\\ResponseTest::__pest_evaluable_it_can_skip_html_errors_and_bubble_the_actual_exception":0.379,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":0.414,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":0.163,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":0.223,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":0.466,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":0.316,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_seed_console_command":0.166,"P\\Tests\\SelectorTest::__pest_evaluable_it_finds_selectors":0.314,"P\\Tests\\SelectorTest::__pest_evaluable_it_expects_selectors":0.331,"P\\Tests\\SelectorTest::__pest_evaluable_it_gets_inner_html_by_class_name":0.363,"P\\Tests\\SelectorTest::__pest_evaluable_it_throws_on_unexpected_property":0.456,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_expectation_API":0.383,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_assertion_API":0.406,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_containing_string":0.619,"P\\Tests\\SelectorTest::__pest_evaluable_it_queries_a_nodelist":0.296,"P\\Tests\\SelectorTest::__pest_evaluable_it_clicks_links":0.323,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_attributes":0.4,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_html_snapshots":0.862,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_html_snapshots":0.584,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_dom_snapshots":0.413,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_dom_snapshots":0.361,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_snapshots":0.223,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_dom_snapshots":0.249,"P\\Tests\\SnapshotTest::__pest_evaluable_it_renders_views_with_variables":0.233,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshots":0.46,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshot_assertions":0.592,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_entry_snapshots":0.265,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_nested_entry_snapshots":0.575,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_collected_snapshots":0.639}} \ No newline at end of file +{"version":"pest_2.34.0","defects":{"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":8,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":8,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":8,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":8,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":8},"times":{"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_factory":0.229,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_email_address":0.048,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_user_objects":0.036,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_admins_via_shorthand":1.511,"P\\Tests\\ActingAsTest::__pest_evaluable_it_throws_on_missing_users":0.032,"P\\Tests\\ActingAsTest::__pest_evaluable_it_should_not_be_logged_in_on_subsequent_tests":0.026,"P\\Tests\\ActingAsTest::__pest_evaluable_it_acts_as_a_user_on_get_requests":0.224,"P\\Tests\\ActingAsTest::__pest_evaluable_it_creates_admin_users":0.614,"P\\Tests\\ActingAsTest::__pest_evaluable_it_resets_globals_during_twig_parsing":0.188,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_duplicate_queries":0.086,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_query_speed":0.097,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_load_time":0.134,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_memory_usage":0.205,"P\\Tests\\BootstrapTest::__pest_evaluable_it_can_bootstrap_craft":0.04,"P\\Tests\\CookieTest::__pest_evaluable_it_receives_cookies":0.069,"P\\Tests\\CookieTest::__pest_evaluable_it_sends_cookies":0.084,"P\\Tests\\CookieTest::__pest_evaluable_it_retains_cookies":0.098,"P\\Tests\\CookieTest::__pest_evaluable_it_doesn_t_have_any_cookies_from_previous_tests":0.071,"P\\Tests\\CoverageTest::__pest_evaluable_it_does_not_run_a_conditional":0.078,"P\\Tests\\CoverageTest::__pest_evaluable_it_runs_a_conditional_via_a_query_var":0.092,"P\\Tests\\CoverageTest::__pest_evaluable_get___loop_test__\u2192_assertOk_":0.131,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content":0.013,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_on_condition":0.153,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_is_missing":0.004,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_trashed":0.065,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":0.055,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":0.029,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":0.029,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_volumes_and_assets":0.579,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_an_asset_from_a_source":0.411,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_set_the_folder":0.226,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_with_no_props":0.335,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_disables_posts":0.107,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_post_date":0.12,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_throws_on_bad_post_date":0.029,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_expiry_date":0.209,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_user_object":0.264,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_id":0.161,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_username":0.197,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_entry_parent":0.037,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":0.041,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_entries_and_rolls_back":0.385,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_fields_and_rolls_back":0.398,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_errors_when_trying_to_create_fields_after_content_elements":0.03,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields":0.689,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields_with_multiple_blocks":0.646,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":0.065,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":0.067,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":0.071,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":0.331,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_channels":0.025,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_structures":0.047,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_hasUrls_of_the_section":0.023,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_uriFormat_of_the_section":0.022,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_enabledByDefault_of_the_section":0.023,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_template_of_the_section":0.031,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_entries_with_section_id__handle__and_object":0.155,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_fill_an_entries_field":0.417,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_place_fields_in_groups":0.017,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_fields":0.317,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via_method#(Closure)":0.233,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_with___count__#(Closure)":0.578,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via___create___definition#(Closure)":0.326,"P\\Tests\\FactoryTest::__pest_evaluable_it_takes_an_array_of_entries#(Closure)":0.25,"P\\Tests\\FactoryTest::__pest_evaluable_it_allows_you_to_use___set____on_a_factory":0.221,"P\\Tests\\FormFieldTest::__pest_evaluable_it_renders_the_page_with_a_form":0.481,"P\\Tests\\FormFieldTest::__pest_evaluable_it_is_unhappy_when_no_form_found":0.172,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_a_field_and_collect_existing_fields":0.284,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_deal_with_many_forms_on_one_page":0.329,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_fields_with_array_style_names":0.48,"P\\Tests\\FormFieldTest::__pest_evaluable_it_does_not_see_disabled_fields":0.627,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields":0.434,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields_on_single_form_pages":0.203,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_create_virtual_fields":0.406,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":0.517,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":0.341,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":0.224,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":0.149,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_plugins":0.083,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_modules":0.087,"P\\Tests\\HttpCpTest::__pest_evaluable_it_posts_action_requests":0.1,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_to_an_action":0.45,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_json_to_an_action":0.2,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cache_tag":0.186,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_presence":0.24,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_value":0.269,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_valid":0.185,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_expired_cookies":0.308,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_cookies":0.315,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_201_Created_status_code":0.441,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_seeing_text":0.436,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_a_download":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_exact_json":0.303,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_path":0.548,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing":0.603,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_path":0.327,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_exact":0.526,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count":0.302,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count_with_path":0.235,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_fragment":0.262,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_structure":0.266,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_403_Forbidden_status_code":0.472,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_presence":0.31,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_value":0.255,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_header":0.515,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data":0.54,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data_by_key":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect":0.543,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_to":0.675,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_hostname":0.229,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_offsite_hostname":0.245,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_a_redirect":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects":0.511,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects_in_one_call":0.502,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_no_content":0.178,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_found":0.366,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string":0.294,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_in_order":0.478,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string_without_tags":0.565,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_without_tags_in_order":0.292,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_status":0.265,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_titles":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_unauthorized":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location":0.489,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path":0.497,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path_by_shorthand":0.821,"P\\Tests\\ResponseTest::__pest_evaluable_it_returns_HTML_for_exceptions":0.405,"P\\Tests\\ResponseTest::__pest_evaluable_it_can_skip_html_errors_and_bubble_the_actual_exception":0.379,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":0.414,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":0.163,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":0.223,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":0.466,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":0.316,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_seed_console_command":0.166,"P\\Tests\\SelectorTest::__pest_evaluable_it_finds_selectors":0.314,"P\\Tests\\SelectorTest::__pest_evaluable_it_expects_selectors":0.331,"P\\Tests\\SelectorTest::__pest_evaluable_it_gets_inner_html_by_class_name":0.363,"P\\Tests\\SelectorTest::__pest_evaluable_it_throws_on_unexpected_property":0.456,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_expectation_API":0.383,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_assertion_API":0.406,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_containing_string":0.619,"P\\Tests\\SelectorTest::__pest_evaluable_it_queries_a_nodelist":0.296,"P\\Tests\\SelectorTest::__pest_evaluable_it_clicks_links":0.323,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_attributes":0.4,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_html_snapshots":0.862,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_html_snapshots":0.584,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_dom_snapshots":0.413,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_dom_snapshots":0.361,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_snapshots":0.223,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_dom_snapshots":0.249,"P\\Tests\\SnapshotTest::__pest_evaluable_it_renders_views_with_variables":0.233,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshots":0.46,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshot_assertions":0.592,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_entry_snapshots":0.265,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_nested_entry_snapshots":0.575,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_collected_snapshots":0.639}} \ No newline at end of file diff --git a/src/factories/Field.php b/src/factories/Field.php index 6ab8793..fe2b407 100644 --- a/src/factories/Field.php +++ b/src/factories/Field.php @@ -5,6 +5,9 @@ use Craft; use craft\helpers\StringHelper; +use function markhuot\craftpest\helpers\craft\isBeforeCraftFive; +use function markhuot\craftpest\helpers\craft\isCraftFive; + /** * @method self name(string $name) * @method self handle(string $name) @@ -61,7 +64,7 @@ public function definition(int $index = 0) 'name' => $name, ]; - if (version_compare(Craft::$app->version, '5.0.0', '<')) { + if (isBeforeCraftFive()) { $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; // @phpstan-ignore-line $definition['groupId'] = $firstFieldGroupId; } diff --git a/src/helpers/Craft.php b/src/helpers/Craft.php index e0ca304..7272465 100644 --- a/src/helpers/Craft.php +++ b/src/helpers/Craft.php @@ -12,6 +12,10 @@ function isCraftFive(): bool { return Semver::satisfies(Craft::$app->version, '~5.0.0'); } +function isBeforeCraftFive(): bool { + return Semver::satisfies(Craft::$app->version, '<5.0.0'); +} + /** * @codeCoverageIgnore */ diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index ae5f485..0ec56bf 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -1,13 +1,18 @@ type('single') ->create(); - expect(Craft::$app->sections->getSectionByHandle($section->handle)->type)->toBe('single'); + expect(service(SectionsServiceInterface::class)->getSectionByHandle($section->handle)->type)->toBe('single'); }); it('can create channels', function () { @@ -15,7 +20,7 @@ ->type('channel') ->create(); - expect(Craft::$app->sections->getSectionByHandle($section->handle)->type)->toBe('channel'); + expect(service(SectionsServiceInterface::class)->getSectionByHandle($section->handle)->type)->toBe('channel'); }); it('can create structures', function () { @@ -23,7 +28,7 @@ ->type('structure') ->create(); - expect(Craft::$app->sections->getSectionByHandle($section->handle)->type)->toBe('structure'); + expect(service(SectionsServiceInterface::class)->getSectionByHandle($section->handle)->type)->toBe('structure'); }); it('can set hasUrls of the section', function () { @@ -32,7 +37,7 @@ ->create(); $siteId = \Craft::$app->sites->getCurrentSite()->id; - expect(Craft::$app->sections->getSectionByHandle($section->handle)->siteSettings[$siteId]->hasUrls)->toBe(false); + expect(service(SectionsServiceInterface::class)->getSectionByHandle($section->handle)->siteSettings[$siteId]->hasUrls)->toBe(false); }); it('can set uriFormat of the section', function () { @@ -41,7 +46,7 @@ ->create(); $siteId = \Craft::$app->sites->getCurrentSite()->id; - expect(Craft::$app->sections->getSectionByHandle($section->handle)->siteSettings[$siteId]->uriFormat)->toBe('{sluggy}'); + expect(service(SectionsServiceInterface::class)->getSectionByHandle($section->handle)->siteSettings[$siteId]->uriFormat)->toBe('{sluggy}'); }); it('can set enabledByDefault of the section', function () { @@ -50,7 +55,7 @@ ->create(); $siteId = \Craft::$app->sites->getCurrentSite()->id; - expect(Craft::$app->sections->getSectionByHandle($section->handle)->siteSettings[$siteId]->enabledByDefault)->toBe(false); + expect(service(SectionsServiceInterface::class)->getSectionByHandle($section->handle)->siteSettings[$siteId]->enabledByDefault)->toBe(false); }); it('can set template of the section', function () { @@ -59,7 +64,7 @@ ->create(); $siteId = \Craft::$app->sites->getCurrentSite()->id; - expect(Craft::$app->sections->getSectionByHandle($section->handle)->siteSettings[$siteId]->template)->toBe(implode('/', ['_foo', $section->handle, 'bar'])); + expect(service(SectionsServiceInterface::class)->getSectionByHandle($section->handle)->siteSettings[$siteId]->template)->toBe(implode('/', ['_foo', $section->handle, 'bar'])); }); it('can create entries with section id, handle, and object', function () { @@ -93,7 +98,7 @@ ->create(); expect($field->getGroup()->name)->toBe('Common'); -}); +})->skip(fn () => isCraftFive()); it('can create fields', function () { $field = \markhuot\craftpest\factories\Field::factory() From 1df9535166bc6e56210d608dd1e524a927b3466c Mon Sep 17 00:00:00 2001 From: markhuot Date: Sun, 18 Feb 2024 10:45:55 -0500 Subject: [PATCH 14/67] changing matrix block types over to entry factories, need to back-fill support for legacy block types --- src/factories/Element.php | 17 +++++-- src/factories/Entry.php | 52 ++++++++++++++------- src/interfaces/SectionsServiceInterface.php | 6 +++ tests/FactoryMatrixTest.php | 12 ++--- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/src/factories/Element.php b/src/factories/Element.php index 3703c0d..16b66f4 100644 --- a/src/factories/Element.php +++ b/src/factories/Element.php @@ -2,11 +2,13 @@ namespace markhuot\craftpest\factories; +use craft\base\FieldInterface; use craft\fields\BaseRelationField; use craft\fields\Matrix; use Illuminate\Support\Collection; use function markhuot\craftpest\helpers\base\array_wrap; +use function markhuot\craftpest\helpers\base\collection_wrap; abstract class Element extends Factory { @@ -51,7 +53,7 @@ public function store($element) /** * Recursively resolve nested factories */ - public function resolveFactories(array $values) + public function resolveFactories(array $values, FieldInterface $field) { // for legacy reasons ->create can either return a model or a collection of models. // Because of this, when we resolve factories we could end up with nested arrays of @@ -69,7 +71,14 @@ public function resolveFactories(array $values) // will go in to the model okay, but when you try to pull them back out to save them // you get an EntryQuery with no access to the raw array of unsaved entries. // Because of that we call ->create() here on all nested factories. - $values[$index] = $value->create(); + $values[$index] = $field instanceof Matrix ? collection_wrap($value->make())->map(function (\craft\elements\Entry $entry) { + return [ + 'type' => $entry->getType()->handle, + 'enabled' => true, + 'collapsed' => false, + 'fields' => $entry->getSerializedFieldValues(), + ]; + }) : $value->create(); $flattenIndexes[] = $index; } } @@ -130,7 +139,7 @@ protected function setAttributes($attributes, $element) } if (is_subclass_of($field, BaseRelationField::class)) { - $value = $this->resolveFactories(array_wrap($value))->map(function ($element) { + $value = $this->resolveFactories(array_wrap($value), $field)->map(function ($element) { if (is_numeric($element)) { return $element; } @@ -143,7 +152,7 @@ protected function setAttributes($attributes, $element) } if (is_a($field, Matrix::class)) { - $value = $this->resolveFactories(array_wrap($value)) + $value = $this->resolveFactories(array_wrap($value), $field) ->mapWithKeys(function ($item, $index) { return ['new'.($index + 1) => $item]; })->toArray(); diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 681865c..0eb52fd 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -28,11 +28,11 @@ */ class Entry extends Element { - /** @var EntryType */ - protected $type; - /** @var string|\craft\models\Section|null */ - protected $sectionIdentifier; + protected $sectionIdentifier = null; + + /** @var EntryType|string|null */ + protected $entryTypeIdentifier = null; protected $priorityAttributes = ['sectionId', 'typeId']; @@ -56,9 +56,11 @@ public function section($identifier) /** * Set the entry type */ - public function type($handle) + public function type($identifier) { + $this->entryTypeIdentifier = $identifier; + return $this; } /** @@ -145,10 +147,10 @@ public function inferSectionId() } if (empty($section)) { - $section = FactoriesSection::factory()->create(); + $section = Section::factory()->create(); } - return $section->id; + return $section?->id; } /** @@ -156,18 +158,27 @@ public function inferSectionId() * * @internal */ - public function inferTypeId($sectionid): int + public function inferTypeId(?int $sectionid): int { - $reflector = new \ReflectionClass($this); - $className = $reflector->getShortName(); - $typeHandle = lcfirst($className); - $section = service(SectionsServiceInterface::class)->getSectionById($sectionid); - $matches = array_filter($section->entryTypes, fn ($e) => $e->handle === $typeHandle); - if (count($matches) === 0) { - $matches = $section->entryTypes; + if (is_a($this->entryTypeIdentifier, \craft\models\EntryType::class)) { + $entryType = $this->entryTypeIdentifier; + } elseif (is_numeric($this->entryTypeIdentifier)) { + $entryType = service(SectionsServiceInterface::class)->getEntryTypeById($this->entryTypeIdentifier); + } elseif (is_string($this->entryTypeIdentifier)) { + $entryType = service(SectionsServiceInterface::class)->getEntryTypeByHandle($this->entryTypeIdentifier); + } else { + $reflector = new \ReflectionClass($this); + $className = $reflector->getShortName(); + $typeHandle = lcfirst($className); + $entryType = service(SectionsServiceInterface::class)->getEntryTypeByHandle($typeHandle); } - return $matches[0]->id; + if (empty($entryType) && $sectionid) { + $entryTypes = service(SectionsServiceInterface::class)->getEntryTypesBySectionId($sectionid); + $entryType = reset($entryTypes); + } + + return $entryType?->id; } /** @@ -193,4 +204,13 @@ public function inferences(array $definition = []) 'typeId' => $typeId, ]); } + + public function toArray() + { + return [ + 'type' => $this->entryTypeIdentifier, + 'enabled' => true, + 'fields' => $this->attributes, + ]; + } } diff --git a/src/interfaces/SectionsServiceInterface.php b/src/interfaces/SectionsServiceInterface.php index df425f2..a87f813 100644 --- a/src/interfaces/SectionsServiceInterface.php +++ b/src/interfaces/SectionsServiceInterface.php @@ -14,4 +14,10 @@ public function saveEntryType(EntryType $entryType): bool; public function getSectionById(int $id): ?Section; public function getSectionByHandle(string $handle): ?Section; + + public function getEntryTypeById(int $id): ?EntryType; + + public function getEntryTypeByHandle(string $handle): ?EntryType; + + public function getEntryTypesBySectionId(int $sectionId): array; } diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index 0daf666..a8c8875 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -12,8 +12,8 @@ $entry = EntryFactory::factory() ->section('posts') ->matrixField( - BlockFactory::factory()->type('blockTypeOne')->fieldOne('foo'), - BlockFactory::factory()->type('blockTypeOne')->fieldOne('bar'), + EntryFactory::factory()->type('blockTypeOne')->fieldOne('foo'), + EntryFactory::factory()->type('blockTypeOne')->fieldOne('bar'), ) ->create(); @@ -24,7 +24,7 @@ $entry = EntryFactory::factory() ->section('posts') ->matrixField( - BlockFactory::factory()->type('blockTypeOne')->count(5), + EntryFactory::factory()->type('blockTypeOne')->count(5), ) ->create(); @@ -70,7 +70,7 @@ $firstBlock = $blocks[0]; expect($firstBlock->{$plainTextOneHandle})->toBe('foo'); expect($firstBlock->{$plainTextTwoHandle})->toBe('bar'); -}); +})->skip(); it('can fill matrix blocks with a shorthand', function () { $plainTextOne = FieldFactory::factory()->type(PlainTextField::class); @@ -94,7 +94,7 @@ $block = $entry->{$matrix->handle}->all()[0]; expect($block->{$plainTextOneHandle})->toBe('foo'); expect($block->{$plainTextTwoHandle})->toBe('bar'); -}); +})->skip(); it('can fill matrix blocks with a magic shorthand', function () { $plainTextOne = FieldFactory::factory()->type(PlainTextField::class)->name('Plain Text One'); @@ -124,4 +124,4 @@ $block = $entry->{$matrix->handle}->all()[0]; expect($block->{$plainTextOneHandle})->toBe('foo'); expect($block->{$plainTextTwoHandle})->toBe('bar'); -}); +})->skip(); From 35d030937f78e4965d07ee098caf94a0ca833f26 Mon Sep 17 00:00:00 2001 From: markhuot Date: Sun, 18 Feb 2024 15:46:17 +0000 Subject: [PATCH 15/67] GitHub action updating docs --- docs/factories/entry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/factories/entry.md b/docs/factories/entry.md index 8b5b174..0f501d7 100644 --- a/docs/factories/entry.md +++ b/docs/factories/entry.md @@ -12,7 +12,7 @@ in three ways, If you do not pass a section, one will be created automatically. -## type($handle) +## type($identifier) Set the entry type ## postDate(DateTime|string|int $value) From aeb0bf3cdc49959fc0d336ca8a57348c63dffe0e Mon Sep 17 00:00:00 2001 From: markhuot Date: Sun, 18 Feb 2024 10:47:08 -0500 Subject: [PATCH 16/67] working support for old style block factories --- src/factories/Element.php | 4 ++-- tests/FactoryMatrixTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/factories/Element.php b/src/factories/Element.php index 16b66f4..90908a7 100644 --- a/src/factories/Element.php +++ b/src/factories/Element.php @@ -71,8 +71,8 @@ public function resolveFactories(array $values, FieldInterface $field) // will go in to the model okay, but when you try to pull them back out to save them // you get an EntryQuery with no access to the raw array of unsaved entries. // Because of that we call ->create() here on all nested factories. - $values[$index] = $field instanceof Matrix ? collection_wrap($value->make())->map(function (\craft\elements\Entry $entry) { - return [ + $values[$index] = $field instanceof Matrix ? collection_wrap($value->make())->map(function (\craft\elements\Entry|array $entry) { + return is_array($entry) ? $entry : [ 'type' => $entry->getType()->handle, 'enabled' => true, 'collapsed' => false, diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index a8c8875..ee146c7 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -20,6 +20,18 @@ expect($entry->matrixField->all())->toHaveCount(2); }); +it('can use old Block factories', function () { + $entry = EntryFactory::factory() + ->section('posts') + ->matrixField( + BlockFactory::factory()->type('blockTypeOne')->fieldOne('foo'), + BlockFactory::factory()->type('blockTypeOne')->fieldOne('bar'), + ) + ->create(); + + expect($entry->matrixField->all())->toHaveCount(2); +}); + it('can fill matrix fields with multiple blocks', function () { $entry = EntryFactory::factory() ->section('posts') From 22f988bb7fbdd28166e3a089c7dce711ee2fcb1a Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 16:53:07 +0000 Subject: [PATCH 17/67] ignoring phpunit cache --- .gitignore | 3 ++- .phpunit.cache/test-results | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 .phpunit.cache/test-results diff --git a/.gitignore b/.gitignore index a84ab54..73f4e95 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .idea cpresources /src/bin/index.php +.phpunit.cache .phpunit.result.cache /config .env @@ -24,4 +25,4 @@ node_modules /templates /node_modules /.env.example -/cpresources \ No newline at end of file +/cpresources diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results deleted file mode 100644 index 44316d8..0000000 --- a/.phpunit.cache/test-results +++ /dev/null @@ -1 +0,0 @@ -{"version":"pest_2.34.0","defects":{"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":8,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":8,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":8,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":8,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":8,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":8,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":8,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":8},"times":{"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_factory":0.229,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_users_by_email_address":0.048,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_user_objects":0.036,"P\\Tests\\ActingAsTest::__pest_evaluable_it_logs_in_admins_via_shorthand":1.511,"P\\Tests\\ActingAsTest::__pest_evaluable_it_throws_on_missing_users":0.032,"P\\Tests\\ActingAsTest::__pest_evaluable_it_should_not_be_logged_in_on_subsequent_tests":0.026,"P\\Tests\\ActingAsTest::__pest_evaluable_it_acts_as_a_user_on_get_requests":0.224,"P\\Tests\\ActingAsTest::__pest_evaluable_it_creates_admin_users":0.614,"P\\Tests\\ActingAsTest::__pest_evaluable_it_resets_globals_during_twig_parsing":0.188,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_duplicate_queries":0.086,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_query_speed":0.097,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_load_time":0.134,"P\\Tests\\BenchmarkTest::__pest_evaluable_it_benchmarks_memory_usage":0.205,"P\\Tests\\BootstrapTest::__pest_evaluable_it_can_bootstrap_craft":0.04,"P\\Tests\\CookieTest::__pest_evaluable_it_receives_cookies":0.069,"P\\Tests\\CookieTest::__pest_evaluable_it_sends_cookies":0.084,"P\\Tests\\CookieTest::__pest_evaluable_it_retains_cookies":0.098,"P\\Tests\\CookieTest::__pest_evaluable_it_doesn_t_have_any_cookies_from_previous_tests":0.071,"P\\Tests\\CoverageTest::__pest_evaluable_it_does_not_run_a_conditional":0.078,"P\\Tests\\CoverageTest::__pest_evaluable_it_runs_a_conditional_via_a_query_var":0.092,"P\\Tests\\CoverageTest::__pest_evaluable_get___loop_test__\u2192_assertOk_":0.131,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content":0.013,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_on_condition":0.153,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_database_content_is_missing":0.004,"P\\Tests\\DatabaseTest::__pest_evaluable_it_asserts_trashed":0.065,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_valid":0.055,"P\\Tests\\ElementTest::__pest_evaluable_it_asserts_invalid":0.029,"P\\Tests\\EntryQueryTest::__pest_evaluable_it_counts_entries":0.029,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_volumes_and_assets":0.579,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_create_an_asset_from_a_source":0.411,"P\\Tests\\FactoryAssetTest::__pest_evaluable_it_can_set_the_folder":0.226,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_with_no_props":0.335,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_disables_posts":0.107,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_post_date":0.12,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_throws_on_bad_post_date":0.029,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_expiry_date":0.209,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_user_object":0.264,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_id":0.161,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_author_by_username":0.197,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_sets_entry_parent":0.037,"P\\Tests\\FactoryEntryTest::__pest_evaluable_it_creates_entries_in_a_sequence":0.041,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_entries_and_rolls_back":0.385,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_creates_fields_and_rolls_back":0.398,"P\\Tests\\FactoryFieldTest::__pest_evaluable_it_errors_when_trying_to_create_fields_after_content_elements":0.03,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields":0.689,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_fields_with_multiple_blocks":0.646,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_create_matrix_fields":0.065,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_shorthand":0.067,"P\\Tests\\FactoryMatrixTest::__pest_evaluable_it_can_fill_matrix_blocks_with_a_magic_shorthand":0.071,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_singles":0.331,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_channels":0.025,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_structures":0.047,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_hasUrls_of_the_section":0.023,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_uriFormat_of_the_section":0.022,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_enabledByDefault_of_the_section":0.023,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_set_template_of_the_section":0.031,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_entries_with_section_id__handle__and_object":0.155,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_fill_an_entries_field":0.417,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_place_fields_in_groups":0.017,"P\\Tests\\FactoryTest::__pest_evaluable_it_can_create_fields":0.317,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via_method#(Closure)":0.233,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_with___count__#(Closure)":0.578,"P\\Tests\\FactoryTest::__pest_evaluable_it_automatically_resolves_factories_via___create___definition#(Closure)":0.326,"P\\Tests\\FactoryTest::__pest_evaluable_it_takes_an_array_of_entries#(Closure)":0.25,"P\\Tests\\FactoryTest::__pest_evaluable_it_allows_you_to_use___set____on_a_factory":0.221,"P\\Tests\\FormFieldTest::__pest_evaluable_it_renders_the_page_with_a_form":0.481,"P\\Tests\\FormFieldTest::__pest_evaluable_it_is_unhappy_when_no_form_found":0.172,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_a_field_and_collect_existing_fields":0.284,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_deal_with_many_forms_on_one_page":0.329,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_fill_fields_with_array_style_names":0.48,"P\\Tests\\FormFieldTest::__pest_evaluable_it_does_not_see_disabled_fields":0.627,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields":0.434,"P\\Tests\\FormFieldTest::__pest_evaluable_it_works_with_select_fields_on_single_form_pages":0.203,"P\\Tests\\FormFieldTest::__pest_evaluable_it_can_create_virtual_fields":0.406,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_with_index_php":0.517,"P\\Tests\\HttpCpTest::__pest_evaluable_it_determines_cp_URLs_without_index_php":0.341,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_path_param":0.224,"P\\Tests\\HttpCpTest::__pest_evaluable_it_supports_non_standard_cpTrigger":0.149,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_plugins":0.083,"P\\Tests\\HttpCpTest::__pest_evaluable_it_gets_web_requests_in_modules":0.087,"P\\Tests\\HttpCpTest::__pest_evaluable_it_posts_action_requests":0.1,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_to_an_action":0.45,"P\\Tests\\RequestBuilderTest::__pest_evaluable_it_posts_json_to_an_action":0.2,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cache_tag":0.186,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_presence":0.24,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_value":0.269,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_cookie_valid":0.185,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_expired_cookies":0.308,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_cookies":0.315,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_201_Created_status_code":0.441,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_seeing_text":0.436,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_a_download":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_exact_json":0.303,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_path":0.548,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing":0.603,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_path":0.327,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_missing_exact":0.526,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count":0.302,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_count_with_path":0.235,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_fragment":0.262,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_json_structure":0.266,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_403_Forbidden_status_code":0.472,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_presence":0.31,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_header_value":0.255,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_missing_header":0.515,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data":0.54,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_flash_data_by_key":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect":0.543,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_to":0.675,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_hostname":0.229,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_redirect_matching_offsite_hostname":0.245,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_a_redirect":0.504,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects":0.511,"P\\Tests\\ResponseTest::__pest_evaluable_it_follows_multiple_redirects_in_one_call":0.502,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_no_content":0.178,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_not_found":0.366,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string":0.294,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_in_order":0.478,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_a_string_without_tags":0.565,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_seeing_strings_without_tags_in_order":0.292,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_status":0.265,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_titles":0.466,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_unauthorized":0.411,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location":0.489,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path":0.497,"P\\Tests\\ResponseTest::__pest_evaluable_it_asserts_location_path_by_shorthand":0.821,"P\\Tests\\ResponseTest::__pest_evaluable_it_returns_HTML_for_exceptions":0.405,"P\\Tests\\ResponseTest::__pest_evaluable_it_can_skip_html_errors_and_bubble_the_actual_exception":0.379,"P\\Tests\\ScenarioTest::__pest_evaluable_it_fails_on_required_fields":0.414,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_function_seeders":0.163,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_name_seeders":0.223,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_class_instance_seeders":0.466,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_multiple_seeders":0.316,"P\\Tests\\SeederTest::__pest_evaluable_it_runs_seed_console_command":0.166,"P\\Tests\\SelectorTest::__pest_evaluable_it_finds_selectors":0.314,"P\\Tests\\SelectorTest::__pest_evaluable_it_expects_selectors":0.331,"P\\Tests\\SelectorTest::__pest_evaluable_it_gets_inner_html_by_class_name":0.363,"P\\Tests\\SelectorTest::__pest_evaluable_it_throws_on_unexpected_property":0.456,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_expectation_API":0.383,"P\\Tests\\SelectorTest::__pest_evaluable_it_selects_multiple_matching_nodes_via_assertion_API":0.406,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_containing_string":0.619,"P\\Tests\\SelectorTest::__pest_evaluable_it_queries_a_nodelist":0.296,"P\\Tests\\SelectorTest::__pest_evaluable_it_clicks_links":0.323,"P\\Tests\\SelectorTest::__pest_evaluable_it_asserts_attributes":0.4,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_html_snapshots":0.862,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_html_snapshots":0.584,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_dom_snapshots":0.413,"P\\Tests\\SnapshotTest::__pest_evaluable_it_expects_dom_snapshots":0.361,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_snapshots":0.223,"P\\Tests\\SnapshotTest::__pest_evaluable_it_asserts_view_dom_snapshots":0.249,"P\\Tests\\SnapshotTest::__pest_evaluable_it_renders_views_with_variables":0.233,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshots":0.46,"P\\Tests\\SnapshotTest::__pest_evaluable_it_includes_postDate_in_snapshot_assertions":0.592,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_entry_snapshots":0.265,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_nested_entry_snapshots":0.575,"P\\Tests\\SnapshotTest::__pest_evaluable_it_matches_collected_snapshots":0.639}} \ No newline at end of file From 3197fa2f83af36781c1970efd710a7c8b851e6d2 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 17:01:18 +0000 Subject: [PATCH 18/67] finding entry type in Craft 4 and 5 --- src/factories/Entry.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 0eb52fd..0a09080 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -160,22 +160,25 @@ public function inferSectionId() */ public function inferTypeId(?int $sectionid): int { + $entryTypes = collect(); + if ($sectionid) { + $section = service(SectionsServiceInterface::class)->getSectionById($sectionid); + $entryTypes = collect($section->getEntryTypes()); + } + if (is_a($this->entryTypeIdentifier, \craft\models\EntryType::class)) { $entryType = $this->entryTypeIdentifier; } elseif (is_numeric($this->entryTypeIdentifier)) { - $entryType = service(SectionsServiceInterface::class)->getEntryTypeById($this->entryTypeIdentifier); + $entryType = $entryTypes->where('id', $this->entryTypeIdentifier)->first(); } elseif (is_string($this->entryTypeIdentifier)) { - $entryType = service(SectionsServiceInterface::class)->getEntryTypeByHandle($this->entryTypeIdentifier); + $entryType = $entryTypes->where('handle', $this->entryTypeIdentifier)->first(); } else { $reflector = new \ReflectionClass($this); $className = $reflector->getShortName(); $typeHandle = lcfirst($className); - $entryType = service(SectionsServiceInterface::class)->getEntryTypeByHandle($typeHandle); - } - - if (empty($entryType) && $sectionid) { - $entryTypes = service(SectionsServiceInterface::class)->getEntryTypesBySectionId($sectionid); - $entryType = reset($entryTypes); + $entryType = $entryTypes->where('handle', $typeHandle)->first() ?? + $entryTypes->where('handle', 'default') ?? + $entryTypes->first(); } return $entryType?->id; From 69e3dbf84289761f7c53eefd2d51ebedc87a3931 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 17:40:28 +0000 Subject: [PATCH 19/67] fixing missing first/bad return --- src/factories/Entry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 0a09080..a253a71 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -177,7 +177,7 @@ public function inferTypeId(?int $sectionid): int $className = $reflector->getShortName(); $typeHandle = lcfirst($className); $entryType = $entryTypes->where('handle', $typeHandle)->first() ?? - $entryTypes->where('handle', 'default') ?? + $entryTypes->where('handle', 'default')->first() ?? $entryTypes->first(); } From feff0bc4490eafe541054511a6baf8ec35b9e43d Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 17:54:38 +0000 Subject: [PATCH 20/67] relaxing types --- src/factories/Entry.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index a253a71..c0d9ee6 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -131,7 +131,7 @@ public function author(\craft\web\User|string|int $user) * * @internal */ - public function inferSectionId() + public function inferSectionId(): ?int { if (is_a($this->sectionIdentifier, \craft\models\Section::class)) { $section = $this->sectionIdentifier; @@ -158,7 +158,7 @@ public function inferSectionId() * * @internal */ - public function inferTypeId(?int $sectionid): int + public function inferTypeId(?int $sectionid): ?int { $entryTypes = collect(); if ($sectionid) { From 88c0dd7b3db26a30f01a4067de30a646041dd30c Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 18:44:16 +0000 Subject: [PATCH 21/67] skips on the right versions --- tests/FactoryMatrixTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index ee146c7..a4d3b6d 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -1,5 +1,7 @@ section('posts') ->matrixField( @@ -18,9 +20,9 @@ ->create(); expect($entry->matrixField->all())->toHaveCount(2); -}); +})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '>5.0.0')); -it('can use old Block factories', function () { +it('can fill matrix fields with Blocks in Craft 4', function () { $entry = EntryFactory::factory() ->section('posts') ->matrixField( @@ -30,7 +32,7 @@ ->create(); expect($entry->matrixField->all())->toHaveCount(2); -}); +})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '<5.0.0')); it('can fill matrix fields with multiple blocks', function () { $entry = EntryFactory::factory() From 1689edfb5fa2ce25426f0af6e04efb722c9b59c6 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 19:07:50 +0000 Subject: [PATCH 22/67] blocks work across 4 and 5 --- tests/FactoryMatrixTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index a4d3b6d..268bc00 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -38,7 +38,7 @@ $entry = EntryFactory::factory() ->section('posts') ->matrixField( - EntryFactory::factory()->type('blockTypeOne')->count(5), + BlockFactory::factory()->type('blockTypeOne')->count(5), ) ->create(); From 348fda23bb96ecce8eea49dfa0d36e92b9a0413c Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 19:09:32 +0000 Subject: [PATCH 23/67] fixing flipped version constraints --- tests/FactoryMatrixTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index 268bc00..d382f3b 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -20,7 +20,7 @@ ->create(); expect($entry->matrixField->all())->toHaveCount(2); -})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '>5.0.0')); +})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '<5.0.0')); it('can fill matrix fields with Blocks in Craft 4', function () { $entry = EntryFactory::factory() @@ -32,7 +32,7 @@ ->create(); expect($entry->matrixField->all())->toHaveCount(2); -})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '<5.0.0')); +})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '>5.0.0')); it('can fill matrix fields with multiple blocks', function () { $entry = EntryFactory::factory() From f01ae5bdf26ff248d49aee9f0a3b8e6c981c504e Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 19:15:02 +0000 Subject: [PATCH 24/67] pint --- src/factories/Entry.php | 1 - src/factories/Field.php | 2 -- src/factories/Section.php | 1 - src/helpers/Craft.php | 6 ++++-- tests/DatabaseTest.php | 2 +- tests/FactoryTest.php | 1 - 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index c0d9ee6..3160eb0 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -3,7 +3,6 @@ namespace markhuot\craftpest\factories; use craft\models\EntryType; -use markhuot\craftpest\factories\Section as FactoriesSection; use markhuot\craftpest\interfaces\SectionsServiceInterface; use markhuot\craftpest\storage\FactoryFields; diff --git a/src/factories/Field.php b/src/factories/Field.php index fe2b407..fe6b368 100644 --- a/src/factories/Field.php +++ b/src/factories/Field.php @@ -2,11 +2,9 @@ namespace markhuot\craftpest\factories; -use Craft; use craft\helpers\StringHelper; use function markhuot\craftpest\helpers\craft\isBeforeCraftFive; -use function markhuot\craftpest\helpers\craft\isCraftFive; /** * @method self name(string $name) diff --git a/src/factories/Section.php b/src/factories/Section.php index 2112f1c..4328323 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -2,7 +2,6 @@ namespace markhuot\craftpest\factories; -use Composer\Semver\Semver; use Craft; use craft\helpers\StringHelper; use craft\models\EntryType; diff --git a/src/helpers/Craft.php b/src/helpers/Craft.php index 7272465..2af8fb2 100644 --- a/src/helpers/Craft.php +++ b/src/helpers/Craft.php @@ -8,11 +8,13 @@ use function markhuot\craftpest\helpers\base\version_greater_than_or_equal_to; -function isCraftFive(): bool { +function isCraftFive(): bool +{ return Semver::satisfies(Craft::$app->version, '~5.0.0'); } -function isBeforeCraftFive(): bool { +function isBeforeCraftFive(): bool +{ return Semver::satisfies(Craft::$app->version, '<5.0.0'); } diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 89c2f15..3bc1ca5 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -21,7 +21,7 @@ it('asserts database content is missing', function () { $table = isCraftFive() ? \craft\db\Table::ELEMENTS_SITES : \craft\db\Table::CONTENT; - $this->assertDatabaseMissing($table, ['title' => 'fooz baz']); + $this->assertDatabaseMissing($table, ['title' => 'fooz baz']); }); it('asserts trashed', function () { diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 0ec56bf..5fde17c 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -4,7 +4,6 @@ use markhuot\craftpest\interfaces\SectionsServiceInterface; use function markhuot\craftpest\helpers\base\service; -use function markhuot\craftpest\helpers\craft\isBeforeCraftFive; use function markhuot\craftpest\helpers\craft\isCraftFive; it('can create singles', function () { From 26993937fd6acc12a28ca243868bbfb0ee816f55 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 18 Feb 2024 19:50:42 +0000 Subject: [PATCH 25/67] skipping old files in craft 5 --- phpstan-craft5.neon | 3 +++ phpstan.neon | 1 + phpstan.php | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 phpstan-craft5.neon create mode 100644 phpstan.php diff --git a/phpstan-craft5.neon b/phpstan-craft5.neon new file mode 100644 index 0000000..84e7adc --- /dev/null +++ b/phpstan-craft5.neon @@ -0,0 +1,3 @@ +parameters: + excludePaths: + - src/factories/BlockType.php \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index cdd9712..c705439 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - vendor/craftcms/phpstan/phpstan.neon + - phpstan.php parameters: paths: diff --git a/phpstan.php b/phpstan.php new file mode 100644 index 0000000..f9e4c36 --- /dev/null +++ b/phpstan.php @@ -0,0 +1,16 @@ + Date: Sun, 18 Feb 2024 21:25:39 +0000 Subject: [PATCH 26/67] separate configs per schema --- .github/workflows/php.yml | 19 ++- ...-0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml | 0 .../f948b9a4-6a4e-43da-84aa-65b91c0cd202.yaml | 0 ...-17685ada-d64c-459c-b9fc-678d43e4bee8.yaml | 0 ...-c148dfb3-a122-49ed-8538-de26d0482663.yaml | 0 ...-c7529b61-60cd-4e18-a272-3084aee7fa89.yaml | 0 ...-7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml | 0 ...-b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml | 0 .../{project => project-4}/project.yaml | 0 ...-ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml | 0 .../b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml | 0 .../bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml | 0 ...-99c2747f-1049-46bc-93e0-424bad0544e5.yaml | 0 ...-bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml | 0 ...-b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml | 80 +++++++++++++ ...-0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml | 110 ++++++++++++++++++ ...-17685ada-d64c-459c-b9fc-678d43e4bee8.yaml | 32 +++++ ...-c148dfb3-a122-49ed-8538-de26d0482663.yaml | 22 ++++ ...-c05f8773-60a8-4f5e-9925-3cc36a064793.yaml | 16 +++ ...-10199d0e-57f0-4724-aefb-1ef4ed73b408.yaml | 16 +++ ...-c7529b61-60cd-4e18-a272-3084aee7fa89.yaml | 19 +++ ...-7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml | 16 +++ stubs/config/project-5/graphql/graphql.yaml | 3 + .../184fa66e-14cd-4045-853d-9a69ecf44e4e.yaml | 2 + ...-b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml | 78 +++++++++++++ stubs/config/project-5/project.yaml | 36 ++++++ ...-ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml | 20 ++++ .../b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml | 1 + .../bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml | 1 + ...-99c2747f-1049-46bc-93e0-424bad0544e5.yaml | 9 ++ ...-bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml | 9 ++ .../4ea4c761-9214-4e32-b594-58e906282652.yaml | 110 ++++++++++++++++++ stubs/config/project-5/users/users.yaml | 5 + ...-3b2c4b24-e463-46ca-be26-7285804ecbb1.yaml | 47 ++++++++ 34 files changed, 646 insertions(+), 5 deletions(-) rename stubs/config/{project => project-4}/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml (100%) rename stubs/config/{project => project-4}/fieldGroups/f948b9a4-6a4e-43da-84aa-65b91c0cd202.yaml (100%) rename stubs/config/{project => project-4}/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml (100%) rename stubs/config/{project => project-4}/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml (100%) rename stubs/config/{project => project-4}/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml (100%) rename stubs/config/{project => project-4}/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml (100%) rename stubs/config/{project => project-4}/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml (100%) rename stubs/config/{project => project-4}/project.yaml (100%) rename stubs/config/{project => project-4}/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml (100%) rename stubs/config/{project => project-4}/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml (100%) rename stubs/config/{project => project-4}/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml (100%) rename stubs/config/{project => project-4}/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml (100%) rename stubs/config/{project => project-4}/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml (100%) create mode 100644 stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml create mode 100644 stubs/config/project-5/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml create mode 100644 stubs/config/project-5/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml create mode 100644 stubs/config/project-5/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml create mode 100644 stubs/config/project-5/fields/fieldOne--c05f8773-60a8-4f5e-9925-3cc36a064793.yaml create mode 100644 stubs/config/project-5/fields/fieldTwo--10199d0e-57f0-4724-aefb-1ef4ed73b408.yaml create mode 100644 stubs/config/project-5/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml create mode 100644 stubs/config/project-5/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml create mode 100644 stubs/config/project-5/graphql/graphql.yaml create mode 100644 stubs/config/project-5/graphql/schemas/184fa66e-14cd-4045-853d-9a69ecf44e4e.yaml create mode 100644 stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml create mode 100644 stubs/config/project-5/project.yaml create mode 100644 stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml create mode 100644 stubs/config/project-5/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml create mode 100644 stubs/config/project-5/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml create mode 100644 stubs/config/project-5/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml create mode 100644 stubs/config/project-5/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml create mode 100644 stubs/config/project-5/users/fieldLayouts/4ea4c761-9214-4e32-b594-58e906282652.yaml create mode 100644 stubs/config/project-5/users/users.yaml create mode 100644 stubs/config/project-5/volumes/local--3b2c4b24-e463-46ca-be26-7285804ecbb1.yaml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index eb11fc2..319eaf0 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -15,7 +15,15 @@ jobs: strategy: matrix: - version: [~4.5.0, ~4.6.0, ~4.7.0, ~5.0.0] + version: + - constraint: ~4.5.0 + config: 4 + - constraint: ~4.6.0 + config: 4 + - constraint: ~4.7.0 + config: 4 + - constraint: ~5.0.0 + config: 5 env: CRAFT_APP_ID: pest @@ -66,18 +74,19 @@ jobs: path: | composer.lock vendor - key: ${{ runner.os }}-craft-${{ matrix.version }}-vendor-${{ hashFiles('composer.json') }} + key: ${{ runner.os }}-craft-${{ matrix.version.constraint }}-vendor-${{ hashFiles('composer.json') }} - name: Install dependencies run: | - composer require "craftcms/cms:${{ matrix.version }}" --prefer-dist --no-progress + composer require "craftcms/cms:${{ matrix.version.constraint }}" --prefer-dist --no-progress ./bin/post-clone.sh - name: Copy config files run: | mkdir -p ./storage - cp -r ./stubs/config ./ - cat config/app.php + cp -r ./stubs/config/app.php ./config/app.php + cp -r ./stubs/config/general.php ./config/general.php + cp -r ./stubs/config/project-${{ matrix.version.config }}/ ./config/project/ - name: Wait for MySQL run: until mysqladmin ping -h 127.0.0.1 -u root -proot; do sleep 1; done diff --git a/stubs/config/project/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml b/stubs/config/project-4/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml similarity index 100% rename from stubs/config/project/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml rename to stubs/config/project-4/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml diff --git a/stubs/config/project/fieldGroups/f948b9a4-6a4e-43da-84aa-65b91c0cd202.yaml b/stubs/config/project-4/fieldGroups/f948b9a4-6a4e-43da-84aa-65b91c0cd202.yaml similarity index 100% rename from stubs/config/project/fieldGroups/f948b9a4-6a4e-43da-84aa-65b91c0cd202.yaml rename to stubs/config/project-4/fieldGroups/f948b9a4-6a4e-43da-84aa-65b91c0cd202.yaml diff --git a/stubs/config/project/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml b/stubs/config/project-4/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml similarity index 100% rename from stubs/config/project/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml rename to stubs/config/project-4/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml diff --git a/stubs/config/project/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml b/stubs/config/project-4/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml similarity index 100% rename from stubs/config/project/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml rename to stubs/config/project-4/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml diff --git a/stubs/config/project/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml b/stubs/config/project-4/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml similarity index 100% rename from stubs/config/project/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml rename to stubs/config/project-4/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml diff --git a/stubs/config/project/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml b/stubs/config/project-4/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml similarity index 100% rename from stubs/config/project/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml rename to stubs/config/project-4/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml diff --git a/stubs/config/project/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml b/stubs/config/project-4/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml similarity index 100% rename from stubs/config/project/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml rename to stubs/config/project-4/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml diff --git a/stubs/config/project/project.yaml b/stubs/config/project-4/project.yaml similarity index 100% rename from stubs/config/project/project.yaml rename to stubs/config/project-4/project.yaml diff --git a/stubs/config/project/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml b/stubs/config/project-4/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml similarity index 100% rename from stubs/config/project/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml rename to stubs/config/project-4/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml diff --git a/stubs/config/project/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml b/stubs/config/project-4/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml similarity index 100% rename from stubs/config/project/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml rename to stubs/config/project-4/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml diff --git a/stubs/config/project/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml b/stubs/config/project-4/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml similarity index 100% rename from stubs/config/project/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml rename to stubs/config/project-4/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml diff --git a/stubs/config/project/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml b/stubs/config/project-4/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml similarity index 100% rename from stubs/config/project/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml rename to stubs/config/project-4/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml diff --git a/stubs/config/project/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml b/stubs/config/project-4/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml similarity index 100% rename from stubs/config/project/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml rename to stubs/config/project-4/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml diff --git a/stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml b/stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml new file mode 100644 index 0000000..8c1fbd3 --- /dev/null +++ b/stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml @@ -0,0 +1,80 @@ +color: null +fieldLayouts: + 2f77cf1c-a3db-4396-8d2f-efff2172466e: + tabs: + - + elementCondition: null + elements: + - + autocapitalize: true + autocomplete: false + autocorrect: true + class: null + disabled: false + elementCondition: null + id: null + includeInCards: false + inputType: null + instructions: null + label: null + max: null + min: null + name: null + orientation: null + placeholder: null + providesThumbs: false + readonly: false + requirable: false + size: null + step: null + tip: null + title: null + type: craft\fieldlayoutelements\entries\EntryTitleField + uid: 463de371-8db2-4f1d-b9b1-b9aca58b5c86 + userCondition: null + warning: null + width: 100 + - + elementCondition: null + fieldUid: c05f8773-60a8-4f5e-9925-3cc36a064793 # Matrix Field - Block Type One - Field One + handle: null + includeInCards: true + instructions: null + label: 'Field One' + providesThumbs: false + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: 6a242257-5d04-4ffb-8afb-f0b091472335 + userCondition: null + warning: null + width: 100 + - + elementCondition: null + fieldUid: 10199d0e-57f0-4724-aefb-1ef4ed73b408 # Matrix Field - Block Type One - Field Two + handle: null + includeInCards: false + instructions: null + label: 'Field Two' + providesThumbs: false + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: 4b8f210d-545c-4d57-9777-08cdb93862df + userCondition: null + warning: null + width: 100 + name: Content + uid: aad92478-a4a8-49e5-b88b-5fff4734eb2c + userCondition: null +handle: blockTypeOne +hasTitleField: false +icon: null +name: 'Block Type One' +showSlugField: true +showStatusField: true +slugTranslationKeyFormat: null +slugTranslationMethod: site +titleFormat: null +titleTranslationKeyFormat: null +titleTranslationMethod: site diff --git a/stubs/config/project-5/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml b/stubs/config/project-5/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml new file mode 100644 index 0000000..df084dd --- /dev/null +++ b/stubs/config/project-5/entryTypes/default--0193fbbc-6912-4ff6-a3d5-e60ea03c8590.yaml @@ -0,0 +1,110 @@ +color: null +fieldLayouts: + 50cdf242-1476-44dc-ab8b-e3ad70ef3163: + tabs: + - + elementCondition: null + elements: + - + autocapitalize: true + autocomplete: false + autocorrect: true + class: null + disabled: false + elementCondition: null + id: null + includeInCards: false + inputType: null + instructions: null + label: null + max: null + min: null + name: null + orientation: null + placeholder: null + providesThumbs: false + readonly: false + requirable: false + size: null + step: null + tip: null + title: null + type: craft\fieldlayoutelements\entries\EntryTitleField + uid: 880e50a3-79fb-4456-836b-89c970af40b9 + userCondition: null + warning: null + width: 100 + - + elementCondition: null + fieldUid: c7529b61-60cd-4e18-a272-3084aee7fa89 # Matrix Field + handle: null + includeInCards: false + instructions: null + label: null + providesThumbs: false + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: 90a7fa0d-77cd-4612-92f9-4fafd4c1a66d + userCondition: null + warning: null + width: 100 + - + elementCondition: null + fieldUid: c148dfb3-a122-49ed-8538-de26d0482663 # Entries Field + handle: null + includeInCards: false + instructions: null + label: null + providesThumbs: false + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: efbdd2ca-b829-4604-bd1e-f66fad9093e2 + userCondition: null + warning: null + width: 100 + - + elementCondition: null + fieldUid: 7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e # Text Field + handle: null + includeInCards: false + instructions: null + label: null + providesThumbs: false + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: 189519d9-7809-47fc-bc54-d2441a85ae9d + userCondition: null + warning: null + width: 100 + - + elementCondition: null + fieldUid: 17685ada-d64c-459c-b9fc-678d43e4bee8 # Dropdown Field + handle: null + includeInCards: false + instructions: null + label: null + providesThumbs: false + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: 1440d116-5fe9-45a3-8031-7f3c9b71ef9d + userCondition: null + warning: null + width: 100 + name: Content + uid: a914e695-0910-4b04-841b-cbe6f689856b + userCondition: null +handle: default +hasTitleField: true +icon: null +name: Default +showSlugField: true +showStatusField: true +slugTranslationKeyFormat: null +slugTranslationMethod: site +titleFormat: null +titleTranslationKeyFormat: null +titleTranslationMethod: site diff --git a/stubs/config/project-5/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml b/stubs/config/project-5/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml new file mode 100644 index 0000000..54c1fe3 --- /dev/null +++ b/stubs/config/project-5/fields/dropdownField--17685ada-d64c-459c-b9fc-678d43e4bee8.yaml @@ -0,0 +1,32 @@ +columnSuffix: vqczhrcp +handle: dropdownField +instructions: null +name: 'Dropdown Field' +searchable: false +settings: + options: + - + __assoc__: + - + - label + - One + - + - value + - one + - + - default + - '' + - + __assoc__: + - + - label + - Two + - + - value + - two + - + - default + - '' +translationKeyFormat: null +translationMethod: none +type: craft\fields\Dropdown diff --git a/stubs/config/project-5/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml b/stubs/config/project-5/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml new file mode 100644 index 0000000..b186836 --- /dev/null +++ b/stubs/config/project-5/fields/entriesField--c148dfb3-a122-49ed-8538-de26d0482663.yaml @@ -0,0 +1,22 @@ +columnSuffix: null +handle: entriesField +instructions: null +name: 'Entries Field' +searchable: false +settings: + allowSelfRelations: false + branchLimit: null + localizeRelations: false + maintainHierarchy: false + maxRelations: null + minRelations: null + selectionLabel: null + showCardsInGrid: false + showSiteMenu: false + sources: '*' + targetSiteId: null + validateRelatedElements: false + viewMode: null +translationKeyFormat: null +translationMethod: site +type: craft\fields\Entries diff --git a/stubs/config/project-5/fields/fieldOne--c05f8773-60a8-4f5e-9925-3cc36a064793.yaml b/stubs/config/project-5/fields/fieldOne--c05f8773-60a8-4f5e-9925-3cc36a064793.yaml new file mode 100644 index 0000000..a079266 --- /dev/null +++ b/stubs/config/project-5/fields/fieldOne--c05f8773-60a8-4f5e-9925-3cc36a064793.yaml @@ -0,0 +1,16 @@ +columnSuffix: jnvscjst +handle: fieldOne +instructions: null +name: 'Matrix Field - Block Type One - Field One' +searchable: false +settings: + byteLimit: null + charLimit: null + code: false + initialRows: 4 + multiline: false + placeholder: null + uiMode: normal +translationKeyFormat: null +translationMethod: none +type: craft\fields\PlainText diff --git a/stubs/config/project-5/fields/fieldTwo--10199d0e-57f0-4724-aefb-1ef4ed73b408.yaml b/stubs/config/project-5/fields/fieldTwo--10199d0e-57f0-4724-aefb-1ef4ed73b408.yaml new file mode 100644 index 0000000..3417eed --- /dev/null +++ b/stubs/config/project-5/fields/fieldTwo--10199d0e-57f0-4724-aefb-1ef4ed73b408.yaml @@ -0,0 +1,16 @@ +columnSuffix: swmzeype +handle: fieldTwo +instructions: null +name: 'Matrix Field - Block Type One - Field Two' +searchable: false +settings: + byteLimit: null + charLimit: null + code: false + initialRows: 4 + multiline: false + placeholder: null + uiMode: normal +translationKeyFormat: null +translationMethod: none +type: craft\fields\PlainText diff --git a/stubs/config/project-5/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml b/stubs/config/project-5/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml new file mode 100644 index 0000000..df84700 --- /dev/null +++ b/stubs/config/project-5/fields/matrixField--c7529b61-60cd-4e18-a272-3084aee7fa89.yaml @@ -0,0 +1,19 @@ +columnSuffix: null +handle: matrixField +instructions: null +name: 'Matrix Field' +searchable: false +settings: + entryTypes: + - b5c238dd-588f-4f0a-b9e4-8a988f0e7468 # Block Type One + includeTableView: false + maxEntries: null + minEntries: null + pageSize: null + propagationKeyFormat: null + propagationMethod: all + showCardsInGrid: false + viewMode: blocks +translationKeyFormat: null +translationMethod: site +type: craft\fields\Matrix diff --git a/stubs/config/project-5/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml b/stubs/config/project-5/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml new file mode 100644 index 0000000..04c6255 --- /dev/null +++ b/stubs/config/project-5/fields/textField--7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e.yaml @@ -0,0 +1,16 @@ +columnSuffix: irlrybem +handle: textField +instructions: null +name: 'Text Field' +searchable: false +settings: + byteLimit: null + charLimit: null + code: false + initialRows: 4 + multiline: false + placeholder: null + uiMode: normal +translationKeyFormat: null +translationMethod: none +type: craft\fields\PlainText diff --git a/stubs/config/project-5/graphql/graphql.yaml b/stubs/config/project-5/graphql/graphql.yaml new file mode 100644 index 0000000..fd4ca55 --- /dev/null +++ b/stubs/config/project-5/graphql/graphql.yaml @@ -0,0 +1,3 @@ +publicToken: + enabled: false + expiryDate: null diff --git a/stubs/config/project-5/graphql/schemas/184fa66e-14cd-4045-853d-9a69ecf44e4e.yaml b/stubs/config/project-5/graphql/schemas/184fa66e-14cd-4045-853d-9a69ecf44e4e.yaml new file mode 100644 index 0000000..6288789 --- /dev/null +++ b/stubs/config/project-5/graphql/schemas/184fa66e-14cd-4045-853d-9a69ecf44e4e.yaml @@ -0,0 +1,2 @@ +isPublic: true +name: 'Public Schema' diff --git a/stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml b/stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml new file mode 100644 index 0000000..f095f71 --- /dev/null +++ b/stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml @@ -0,0 +1,78 @@ +field: c7529b61-60cd-4e18-a272-3084aee7fa89 # Matrix Field +fieldLayouts: + 2f77cf1c-a3db-4396-8d2f-efff2172466e: + tabs: + - + elementCondition: null + elements: + - + elementCondition: null + fieldUid: c05f8773-60a8-4f5e-9925-3cc36a064793 # Matrix Field - Block Type One - Field One + instructions: null + label: null + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: 6a242257-5d04-4ffb-8afb-f0b091472335 + userCondition: null + warning: null + width: 100 + - + elementCondition: null + fieldUid: 10199d0e-57f0-4724-aefb-1ef4ed73b408 # Matrix Field - Block Type One - Field Two + instructions: null + label: null + required: false + tip: null + type: craft\fieldlayoutelements\CustomField + uid: 4b8f210d-545c-4d57-9777-08cdb93862df + userCondition: null + warning: null + width: 100 + name: Content + uid: aad92478-a4a8-49e5-b88b-5fff4734eb2c + userCondition: null +fields: + 10199d0e-57f0-4724-aefb-1ef4ed73b408: # Matrix Field - Block Type One - Field Two + columnSuffix: swmzeype + contentColumnType: text + fieldGroup: null + handle: fieldTwo + instructions: null + name: 'Field Two' + searchable: false + settings: + byteLimit: null + charLimit: null + code: false + columnType: null + initialRows: 4 + multiline: false + placeholder: null + uiMode: normal + translationKeyFormat: null + translationMethod: none + type: craft\fields\PlainText + c05f8773-60a8-4f5e-9925-3cc36a064793: # Matrix Field - Block Type One - Field One + columnSuffix: jnvscjst + contentColumnType: text + fieldGroup: null + handle: fieldOne + instructions: null + name: 'Field One' + searchable: false + settings: + byteLimit: null + charLimit: null + code: false + columnType: null + initialRows: 4 + multiline: false + placeholder: null + uiMode: normal + translationKeyFormat: null + translationMethod: none + type: craft\fields\PlainText +handle: blockTypeOne +name: 'Block Type One' +sortOrder: 1 diff --git a/stubs/config/project-5/project.yaml b/stubs/config/project-5/project.yaml new file mode 100644 index 0000000..71dfd63 --- /dev/null +++ b/stubs/config/project-5/project.yaml @@ -0,0 +1,36 @@ +dateModified: 1708290694 +email: + fromEmail: michael@bluth.com + fromName: Pest + transportType: craft\mail\transportadapters\Sendmail +fs: + local: + hasUrls: true + name: Local + settings: + path: /workspaces/craft-pest-core/web/volumes/local + type: craft\fs\Local + url: 'http://localhost:8080/volumes/local/' +meta: + __names__: + 3b2c4b24-e463-46ca-be26-7285804ecbb1: Local # Local + 7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e: 'Text Field' # Text Field + 99c2747f-1049-46bc-93e0-424bad0544e5: Pest # Pest + 184fa66e-14cd-4045-853d-9a69ecf44e4e: 'Public Schema' + 0193fbbc-6912-4ff6-a3d5-e60ea03c8590: Default # Default + 10199d0e-57f0-4724-aefb-1ef4ed73b408: 'Field Two' # Matrix Field - Block Type One - Field Two + 17685ada-d64c-459c-b9fc-678d43e4bee8: 'Dropdown Field' # Dropdown Field + ae919370-04f6-4e2d-8d42-f255cc1b6a75: Posts # Posts + b5c238dd-588f-4f0a-b9e4-8a988f0e7468: 'Block Type One' # Block Type One + b11e9b16-d6b0-4771-86bb-3fe962b4596d: Pest # Pest + bda4d299-4f91-43c1-91d1-48abd1dd5fb4: Pest # Pest + bdde35b2-daab-45e7-aef7-43fd8b221aa2: Pest # Pest + c05f8773-60a8-4f5e-9925-3cc36a064793: 'Field One' # Matrix Field - Block Type One - Field One + c148dfb3-a122-49ed-8538-de26d0482663: 'Entries Field' # Entries Field + c7529b61-60cd-4e18-a272-3084aee7fa89: 'Matrix Field' # Matrix Field +system: + edition: solo + live: true + name: Pest + schemaVersion: 5.0.0.19 + timeZone: America/Los_Angeles diff --git a/stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml b/stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml new file mode 100644 index 0000000..03a5adc --- /dev/null +++ b/stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml @@ -0,0 +1,20 @@ +defaultPlacement: end +enableVersioning: true +entryTypes: + - 0193fbbc-6912-4ff6-a3d5-e60ea03c8590 # Default +handle: posts +maxAuthors: 1 +name: Posts +propagationMethod: all +siteSettings: + 99c2747f-1049-46bc-93e0-424bad0544e5: # Pest + enabledByDefault: true + hasUrls: true + template: posts/_entry + uriFormat: 'posts/{slug}' + bda4d299-4f91-43c1-91d1-48abd1dd5fb4: # Pest + enabledByDefault: true + hasUrls: true + template: posts/_entry + uriFormat: 'posts/{slug}' +type: channel diff --git a/stubs/config/project-5/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml b/stubs/config/project-5/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml new file mode 100644 index 0000000..ed2ddb7 --- /dev/null +++ b/stubs/config/project-5/siteGroups/b11e9b16-d6b0-4771-86bb-3fe962b4596d.yaml @@ -0,0 +1 @@ +name: Pest diff --git a/stubs/config/project-5/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml b/stubs/config/project-5/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml new file mode 100644 index 0000000..ed2ddb7 --- /dev/null +++ b/stubs/config/project-5/siteGroups/bdde35b2-daab-45e7-aef7-43fd8b221aa2.yaml @@ -0,0 +1 @@ +name: Pest diff --git a/stubs/config/project-5/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml b/stubs/config/project-5/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml new file mode 100644 index 0000000..063150f --- /dev/null +++ b/stubs/config/project-5/sites/default--99c2747f-1049-46bc-93e0-424bad0544e5.yaml @@ -0,0 +1,9 @@ +baseUrl: $PRIMARY_SITE_URL +enabled: true +handle: default +hasUrls: true +language: en-US +name: Pest +primary: true +siteGroup: bdde35b2-daab-45e7-aef7-43fd8b221aa2 # Pest +sortOrder: 1 diff --git a/stubs/config/project-5/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml b/stubs/config/project-5/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml new file mode 100644 index 0000000..dda612b --- /dev/null +++ b/stubs/config/project-5/sites/default--bda4d299-4f91-43c1-91d1-48abd1dd5fb4.yaml @@ -0,0 +1,9 @@ +baseUrl: $PRIMARY_SITE_URL +enabled: '1' +handle: default +hasUrls: true +language: en-US +name: Pest +primary: false +siteGroup: b11e9b16-d6b0-4771-86bb-3fe962b4596d # Pest +sortOrder: 1 diff --git a/stubs/config/project-5/users/fieldLayouts/4ea4c761-9214-4e32-b594-58e906282652.yaml b/stubs/config/project-5/users/fieldLayouts/4ea4c761-9214-4e32-b594-58e906282652.yaml new file mode 100644 index 0000000..757ccce --- /dev/null +++ b/stubs/config/project-5/users/fieldLayouts/4ea4c761-9214-4e32-b594-58e906282652.yaml @@ -0,0 +1,110 @@ +tabs: + - + elementCondition: null + elements: + - + autocapitalize: true + autocomplete: false + autocorrect: true + class: null + disabled: false + elementCondition: null + id: null + includeInCards: false + inputType: null + instructions: null + label: null + max: null + min: null + name: null + orientation: null + placeholder: null + providesThumbs: false + readonly: false + requirable: false + size: null + step: null + tip: null + title: null + type: craft\fieldlayoutelements\users\UsernameField + uid: 8d4db13b-bf33-4fcb-a4b3-465419ff6554 + userCondition: null + warning: null + width: 100 + - + attribute: fullName + autocapitalize: true + autocomplete: false + autocorrect: true + class: null + disabled: false + elementCondition: null + id: null + includeInCards: false + inputType: null + instructions: null + label: null + max: null + min: null + name: null + orientation: null + placeholder: null + providesThumbs: false + readonly: false + requirable: true + required: false + size: null + step: null + tip: null + title: null + type: craft\fieldlayoutelements\users\FullNameField + uid: 40cd1617-0f35-489c-bc2a-508347941659 + userCondition: null + warning: null + width: 100 + - + elementCondition: null + id: null + includeInCards: false + instructions: null + label: null + orientation: null + providesThumbs: false + requirable: false + tip: null + type: craft\fieldlayoutelements\users\PhotoField + uid: 1e08b8ec-6f86-482b-89fe-8ec91608e9a2 + userCondition: null + warning: null + width: 100 + - + autocapitalize: true + autocomplete: false + autocorrect: true + class: null + disabled: false + elementCondition: null + id: null + includeInCards: false + inputType: null + instructions: null + label: null + max: null + min: null + name: null + orientation: null + placeholder: null + providesThumbs: false + readonly: false + requirable: false + size: null + step: null + tip: null + title: null + type: craft\fieldlayoutelements\users\EmailField + uid: 54368c30-4e82-4caa-b568-ea6d72ac8e1c + userCondition: null + width: 100 + name: Content + uid: 5d3a7ac6-f14a-453a-9ac9-9f6cda4c594e + userCondition: null diff --git a/stubs/config/project-5/users/users.yaml b/stubs/config/project-5/users/users.yaml new file mode 100644 index 0000000..5ffedb3 --- /dev/null +++ b/stubs/config/project-5/users/users.yaml @@ -0,0 +1,5 @@ +allowPublicRegistration: false +defaultGroup: null +photoSubpath: null +photoVolumeUid: null +requireEmailVerification: true diff --git a/stubs/config/project-5/volumes/local--3b2c4b24-e463-46ca-be26-7285804ecbb1.yaml b/stubs/config/project-5/volumes/local--3b2c4b24-e463-46ca-be26-7285804ecbb1.yaml new file mode 100644 index 0000000..72ba152 --- /dev/null +++ b/stubs/config/project-5/volumes/local--3b2c4b24-e463-46ca-be26-7285804ecbb1.yaml @@ -0,0 +1,47 @@ +fieldLayouts: + 7948cc32-6d40-46b7-af5d-39b77f566df7: + tabs: + - + elementCondition: null + elements: + - + autocapitalize: true + autocomplete: false + autocorrect: true + class: null + disabled: false + elementCondition: null + id: null + includeInCards: false + inputType: null + instructions: null + label: null + max: null + min: null + name: null + orientation: null + placeholder: null + providesThumbs: false + readonly: false + requirable: false + size: null + step: null + tip: null + title: null + type: craft\fieldlayoutelements\assets\AssetTitleField + uid: 8c8df736-809a-41c5-a4f1-e48f3392078d + userCondition: null + warning: null + width: 100 + name: Content + uid: 1e2b784c-d10c-4014-831d-d78877cf8580 + userCondition: null +fs: local +handle: local +name: Local +sortOrder: 1 +subpath: '' +titleTranslationKeyFormat: null +titleTranslationMethod: site +transformFs: null +transformSubpath: '' From abafb54815958759b73d189c296377ae91bdccd8 Mon Sep 17 00:00:00 2001 From: markhuot Date: Sat, 9 Mar 2024 19:25:36 -0500 Subject: [PATCH 27/67] fixing matrix field factories in craft 5 --- src/factories/EntryType.php | 45 +++++++++++++ src/factories/MatrixField.php | 88 +++---------------------- src/factories/MatrixFieldBlocks.php | 96 ++++++++++++++++++++++++++++ src/factories/MatrixFieldEntries.php | 96 ++++++++++++++++++++++++++++ src/test/RefreshesDatabase.php | 8 ++- tests/FactoryMatrixTest.php | 14 ++-- 6 files changed, 262 insertions(+), 85 deletions(-) create mode 100644 src/factories/EntryType.php create mode 100644 src/factories/MatrixFieldBlocks.php create mode 100644 src/factories/MatrixFieldEntries.php diff --git a/src/factories/EntryType.php b/src/factories/EntryType.php new file mode 100644 index 0000000..a8431ba --- /dev/null +++ b/src/factories/EntryType.php @@ -0,0 +1,45 @@ +faker->words(2, true); + + return [ + 'name' => $name, + ]; + } + + public function inferences(array $definition = []) + { + if (empty($definition['handle']) && ! empty($definition['name'])) { + $definition['handle'] = StringHelper::toCamelCase($definition['name']); + } + + return $definition; + } + + public function newElement() + { + return new EntryTypeModel(); + } + + public function store($entryType) + { + return Craft::$app->getEntries()->saveEntryType($entryType); + } +} diff --git a/src/factories/MatrixField.php b/src/factories/MatrixField.php index 25b53b8..2693383 100644 --- a/src/factories/MatrixField.php +++ b/src/factories/MatrixField.php @@ -2,95 +2,23 @@ namespace markhuot\craftpest\factories; -use craft\fields\Matrix; -use craft\models\MatrixBlockType; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use function markhuot\craftpest\helpers\base\version_greater_than_or_equal_to; class MatrixField extends Field { - protected $blockTypes = []; - - public function blockTypes(...$blockTypes) + public static function factory() { - if (is_array($blockTypes[0])) { - $this->blockTypes = array_merge($this->blockTypes, $blockTypes[0]); - } else { - $this->blockTypes = array_merge($this->blockTypes, $blockTypes); + if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0.0')) { + return MatrixFieldEntries::factory(); } - return $this; - } - - public function addBlockType($blockType) - { - $this->blockTypes[] = $blockType; - - return $this; - } - - /** - * Get the element to be generated - */ - public function newElement() - { - return new \craft\fields\Matrix; - } - - /** - * @param Matrix $element - */ - public function store($element): bool - { - // Push the block types in to the field - $element->setBlockTypes( - collect($this->blockTypes) - ->map - ->make() - ->flatten() - ->each(function ($blockType, $index) use ($element) { - $blockType->fieldId = $element->id; - $blockType->sortOrder = $index; - }) - ->toArray() - ); - - // Store the field, which also saves the block types - $result = parent::store($element); - - // If we have an error, stop here because it will be impossible to save - // block types on an unsaved/errored matrix field - if ($result === false) { - return $result; + if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0')) { + return MatrixFieldBlocks::factory(); } - // Add the fields in to the block types - collect($this->blockTypes) - ->zip($element->getBlockTypes()) - ->each(function ($props) { - /** @var MatrixBlockType $blockType */ - [$factory, $blockType] = $props; - $factory->storeFields($blockType->fieldLayout, $blockType); - - if (version_greater_than_or_equal_to(\Craft::$app->version, '3')) { - $blockType->fieldLayoutId = $blockType->fieldLayout->id; - \Craft::$app->matrix->saveBlockType($blockType); - } - }); - - // In Craft 3.7 the Matrix Field model stores a reference to the `_blockTypes` of the - // matrix. Inside that reference the block type stores a reference to its `fieldLayoutId`. - // - // The reference to the Matrix Field is cached in to \Craft::$app->fields->_fields when the - // field is created and it's cached without a valid `fieldLayoutId`. - // - // The following grabs the global \Craft::$app->fields->field reference to this matrix field - // and updates the block types by pulling them fresh from the database. This ensures everything - // is up to date and there are no null fieldLayoutId values. - /** @var Matrix $cachedMatrixField */ - $cachedMatrixField = \Craft::$app->fields->getFieldById($element->id); - $cachedMatrixField->setBlockTypes(\Craft::$app->matrix->getBlockTypesByFieldId($element->id)); - - return $result; + throw new \RuntimeException('bad version'); } } diff --git a/src/factories/MatrixFieldBlocks.php b/src/factories/MatrixFieldBlocks.php new file mode 100644 index 0000000..3c44d46 --- /dev/null +++ b/src/factories/MatrixFieldBlocks.php @@ -0,0 +1,96 @@ +blockTypes = array_merge($this->blockTypes, $blockTypes[0]); + } else { + $this->blockTypes = array_merge($this->blockTypes, $blockTypes); + } + + return $this; + } + + public function addBlockType($blockType) + { + $this->blockTypes[] = $blockType; + + return $this; + } + + /** + * Get the element to be generated + */ + public function newElement() + { + return new \craft\fields\Matrix; + } + + /** + * @param Matrix $element + */ + public function store($element): bool + { + // Push the block types in to the field + $element->setBlockTypes( + collect($this->blockTypes) + ->map + ->make() + ->flatten() + ->each(function ($blockType, $index) use ($element) { + $blockType->fieldId = $element->id; + $blockType->sortOrder = $index; + }) + ->toArray() + ); + + // Store the field, which also saves the block types + $result = parent::store($element); + + // If we have an error, stop here because it will be impossible to save + // block types on an unsaved/errored matrix field + if ($result === false) { + return $result; + } + + // Add the fields in to the block types + collect($this->blockTypes) + ->zip($element->getBlockTypes()) + ->each(function ($props) { + /** @var MatrixBlockType $blockType */ + [$factory, $blockType] = $props; + $factory->storeFields($blockType->fieldLayout, $blockType); + + if (version_greater_than_or_equal_to(\Craft::$app->version, '3')) { + $blockType->fieldLayoutId = $blockType->fieldLayout->id; + \Craft::$app->matrix->saveBlockType($blockType); + } + }); + + // In Craft 3.7 the Matrix Field model stores a reference to the `_blockTypes` of the + // matrix. Inside that reference the block type stores a reference to its `fieldLayoutId`. + // + // The reference to the Matrix Field is cached in to \Craft::$app->fields->_fields when the + // field is created and it's cached without a valid `fieldLayoutId`. + // + // The following grabs the global \Craft::$app->fields->field reference to this matrix field + // and updates the block types by pulling them fresh from the database. This ensures everything + // is up to date and there are no null fieldLayoutId values. + /** @var Matrix $cachedMatrixField */ + $cachedMatrixField = \Craft::$app->fields->getFieldById($element->id); + $cachedMatrixField->setBlockTypes(\Craft::$app->matrix->getBlockTypesByFieldId($element->id)); + + return $result; + } +} diff --git a/src/factories/MatrixFieldEntries.php b/src/factories/MatrixFieldEntries.php new file mode 100644 index 0000000..ea83b5c --- /dev/null +++ b/src/factories/MatrixFieldEntries.php @@ -0,0 +1,96 @@ +entryTypes = array_merge($this->entryTypes, $entryTypes[0]); + } else { + $this->entryTypes = array_merge($this->entryTypes, $entryTypes); + } + + return $this; + } + + public function addEntryType($entryType) + { + $this->entryTypes[] = $entryType; + + return $this; + } + + /** + * Get the element to be generated + */ + public function newElement() + { + return new \craft\fields\Matrix; + } + + /** + * @param Matrix $element + */ + public function store($element): bool + { + // Push the block types in to the field + $element->setEntryTypes( + collect($this->entryTypes) + ->map + ->create() + ->flatten() + // ->each(function ($entryType, $index) use ($element) { + // $entryType->fieldId = $element->id; + // $entryType->sortOrder = $index; + // }) + ->toArray() + ); + + // Store the field, which also saves the block types + $result = parent::store($element); + + // If we have an error, stop here because it will be impossible to save + // block types on an unsaved/errored matrix field + if ($result === false) { + return $result; + } + + // Add the fields in to the block types + //dd($element->getEntryTypes()[0]->fieldLayout); + collect($this->entryTypes) + ->zip($element->getEntryTypes()) + ->each(function ($props) { + /** @var \craft\models\EntryType $entryType */ + [$factory, $entryType] = $props; + $factory->storeFields($entryType->fieldLayout, $entryType); + + $entryType->fieldLayoutId = $entryType->fieldLayout->id; + \Craft::$app->getEntries()->saveEntryType($entryType); + }); + + // In Craft 3.7 the Matrix Field model stores a reference to the `_blockTypes` of the + // matrix. Inside that reference the block type stores a reference to its `fieldLayoutId`. + // + // The reference to the Matrix Field is cached in to \Craft::$app->fields->_fields when the + // field is created and it's cached without a valid `fieldLayoutId`. + // + // The following grabs the global \Craft::$app->fields->field reference to this matrix field + // and updates the block types by pulling them fresh from the database. This ensures everything + // is up to date and there are no null fieldLayoutId values. + /** @var Matrix $cachedMatrixField */ + // $cachedMatrixField = \Craft::$app->fields->getFieldById($element->id); + // $cachedMatrixField->setEntryTypes(\Craft::$app->matrix->getEntryTypesByFieldId($element->id)); + + return $result; + } +} diff --git a/src/test/RefreshesDatabase.php b/src/test/RefreshesDatabase.php index 653f800..6147cf7 100644 --- a/src/test/RefreshesDatabase.php +++ b/src/test/RefreshesDatabase.php @@ -2,6 +2,8 @@ namespace markhuot\craftpest\test; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use markhuot\craftpest\events\FactoryStoreEvent; use markhuot\craftpest\events\RollbackTransactionEvent; use markhuot\craftpest\exceptions\AutoCommittingFieldsException; @@ -77,8 +79,12 @@ protected function stopListeningForStores() public function beforeStore(FactoryStoreEvent $event) { $isFieldFactory = is_a($event->sender, Field::class) || is_subclass_of($event->sender, Field::class); + $isCraft4 = InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0'); - if ($isFieldFactory && $this->hasStoredNonFieldContent) { + // We don't need to worry about autocommiting fields in Craft 5 because there is no longer + // a dynamic content table. The field data goes in a JSON field so the DB schema never + // changes! + if ($isCraft4 && $isFieldFactory && $this->hasStoredNonFieldContent) { throw new AutoCommittingFieldsException('You can not create fields after creating elements while refreshesDatabase is in use.'); } diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index d382f3b..1abed95 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -6,6 +6,7 @@ use markhuot\craftpest\factories\Block as BlockFactory; use markhuot\craftpest\factories\BlockType as BlockTypeFactory; use markhuot\craftpest\factories\Entry as EntryFactory; +use markhuot\craftpest\factories\EntryType; use markhuot\craftpest\factories\Field as FieldFactory; use markhuot\craftpest\factories\MatrixField as MatrixFieldFactory; use markhuot\craftpest\factories\Section as SectionFactory; @@ -45,18 +46,19 @@ expect($entry->matrixField->all())->toHaveCount(5); }); -it('can create matrix fields', function () { +it('can create matrix fields in Craft 5', function () { $plainTextOne = FieldFactory::factory() ->type(PlainTextField::class); $plainTextTwo = FieldFactory::factory() ->type(PlainTextField::class); - $blockType = BlockTypeFactory::factory() + $blockType = EntryType::factory() + ->hasTitleField(false) ->fields($plainTextOne, $plainTextTwo); $matrix = MatrixFieldFactory::factory() - ->blockTypes($blockType) + ->entryTypes($blockType) ->create(); $section = SectionFactory::factory() @@ -84,7 +86,11 @@ $firstBlock = $blocks[0]; expect($firstBlock->{$plainTextOneHandle})->toBe('foo'); expect($firstBlock->{$plainTextTwoHandle})->toBe('bar'); -})->skip(); +})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0')); + +it('tests matrix blocks in craft 4', function () { + +})->todo(); it('can fill matrix blocks with a shorthand', function () { $plainTextOne = FieldFactory::factory()->type(PlainTextField::class); From 030c2e9a35053bee24c28bcdebc7caa537f42ea1 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 15:55:56 -0400 Subject: [PATCH 28/67] passing craft 5 tests --- src/factories/Entry.php | 9 +++++++-- tests/FactoryFieldTest.php | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 3160eb0..0ff16a0 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -198,8 +198,13 @@ public function newElement() */ public function inferences(array $definition = []) { - $sectionId = $this->inferSectionId(); - $typeId = $this->inferTypeId($sectionId); + if (empty($this->entryTypeIdentifier)) { + $sectionId = $this->inferSectionId(); + $typeId = $this->inferTypeId($sectionId); + } else { + $sectionId = null; + $typeId = \Craft::$app->getEntries()->getEntryTypeByHandle($this->entryTypeIdentifier)->id; + } return array_merge($definition, [ 'sectionId' => $sectionId, diff --git a/tests/FactoryFieldTest.php b/tests/FactoryFieldTest.php index 3115497..0737490 100644 --- a/tests/FactoryFieldTest.php +++ b/tests/FactoryFieldTest.php @@ -1,5 +1,7 @@ count())->toBe($entryCount); }); -it('errors when trying to create fields after content elements', function () { +it('errors when trying to create fields after content elements in Craft 4', function () { $this->expectException(\markhuot\craftpest\exceptions\AutoCommittingFieldsException::class); Section::factory()->create(); Field::factory()->type(\craft\fields\PlainText::class)->create(); -}); +})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '>=5.0.0')); From 90738e770c7c6a79a73eb9aea0df217b3776fbe1 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 15:59:22 -0400 Subject: [PATCH 29/67] phpstan update for craft 4 --- phpstan-craft4.neon | 3 +++ phpstan.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 phpstan-craft4.neon diff --git a/phpstan-craft4.neon b/phpstan-craft4.neon new file mode 100644 index 0000000..b3faeda --- /dev/null +++ b/phpstan-craft4.neon @@ -0,0 +1,3 @@ +parameters: + excludePaths: + - src/factories/EntryType.php diff --git a/phpstan.php b/phpstan.php index f9e4c36..477c38a 100644 --- a/phpstan.php +++ b/phpstan.php @@ -6,7 +6,7 @@ $config = []; if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0')) { - + $config['includes'][] = 'phpstan-craft4.neon'; } if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0.0')) { From 6061036ed6cd06a5a876af173f770353c7be001e Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 15:59:51 -0400 Subject: [PATCH 30/67] phpstan update for craft 4 --- phpstan-craft4.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan-craft4.neon b/phpstan-craft4.neon index b3faeda..eac525d 100644 --- a/phpstan-craft4.neon +++ b/phpstan-craft4.neon @@ -1,3 +1,4 @@ parameters: excludePaths: - src/factories/EntryType.php + - src/factories/MatrixFieldEntries.php From 8c3c20645e761e7cf6ae29e916560b07ddedfd19 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:01:58 -0400 Subject: [PATCH 31/67] Remove unused helpers from Matrix factories Removed references to `version_greater_than_or_equal_to` from `MatrixField.php` and `MatrixFieldEntries.php` as they were unused, thus cleaning up the imports section of both files. This leads to a minor reduction in complexity and potential for errors. --- src/factories/MatrixField.php | 2 -- src/factories/MatrixFieldEntries.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/factories/MatrixField.php b/src/factories/MatrixField.php index 2693383..35bba52 100644 --- a/src/factories/MatrixField.php +++ b/src/factories/MatrixField.php @@ -5,8 +5,6 @@ use Composer\InstalledVersions; use Composer\Semver\VersionParser; -use function markhuot\craftpest\helpers\base\version_greater_than_or_equal_to; - class MatrixField extends Field { public static function factory() diff --git a/src/factories/MatrixFieldEntries.php b/src/factories/MatrixFieldEntries.php index ea83b5c..440762b 100644 --- a/src/factories/MatrixFieldEntries.php +++ b/src/factories/MatrixFieldEntries.php @@ -3,9 +3,7 @@ namespace markhuot\craftpest\factories; use craft\fields\Matrix; -use craft\models\MatrixBlockType; -use function markhuot\craftpest\helpers\base\version_greater_than_or_equal_to; use function markhuot\craftpest\helpers\test\dd; class MatrixFieldEntries extends Field From cae70167c099c5104acc61fddc9bb99bd4ddfe80 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:04:58 -0400 Subject: [PATCH 32/67] Fix factory class in matrix block test Changed the incorrectly used BlockFactory to EntryFactory within the matrix block test, and extended version skip logic to support versions below Craft CMS 5.0.0. Added new test cases to ensure matrix blocks work as expected in Craft CMS 4. --- tests/FactoryMatrixTest.php | 41 +++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index 1abed95..10519ca 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -72,7 +72,7 @@ $entry = EntryFactory::factory() ->section($section->handle) ->{$matrix->handle}( - BlockFactory::factory() + EntryFactory::factory() ->type($blockTypeHandle) ->{$plainTextOneHandle}('foo') ->{$plainTextTwoHandle}('bar') @@ -86,10 +86,47 @@ $firstBlock = $blocks[0]; expect($firstBlock->{$plainTextOneHandle})->toBe('foo'); expect($firstBlock->{$plainTextTwoHandle})->toBe('bar'); -})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0')); +})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '<5.0.0')); it('tests matrix blocks in craft 4', function () { + $plainTextOne = FieldFactory::factory() + ->type(PlainTextField::class); + + $plainTextTwo = FieldFactory::factory() + ->type(PlainTextField::class); + + $blockType = BlockTypeFactory::factory() + ->fields($plainTextOne, $plainTextTwo); + + $matrix = MatrixFieldFactory::factory() + ->entryTypes($blockType) + ->create(); + + $section = SectionFactory::factory() + ->fields($matrix) + ->create(); + + $blockTypeHandle = $blockType->getMadeModels()->first()->handle; + $plainTextOneHandle = $plainTextOne->getMadeModels()->first()->handle; + $plainTextTwoHandle = $plainTextTwo->getMadeModels()->first()->handle; + + $entry = EntryFactory::factory() + ->section($section->handle) + ->{$matrix->handle}( + \markhuot\craftpest\factories\Block::factory() + ->type($blockTypeHandle) + ->{$plainTextOneHandle}('foo') + ->{$plainTextTwoHandle}('bar') + ->count(5) + ) + ->create(); + $blocks = $entry->{$matrix->handle}->all(); + expect($blocks)->toHaveCount(5); + + $firstBlock = $blocks[0]; + expect($firstBlock->{$plainTextOneHandle})->toBe('foo'); + expect($firstBlock->{$plainTextTwoHandle})->toBe('bar'); })->todo(); it('can fill matrix blocks with a shorthand', function () { From c0044df8955bed02ee3ed44e57374cd17f8afe70 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:08:11 -0400 Subject: [PATCH 33/67] craft seems to have force-updated their tags. updating our version constraint to be compliant --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 59e1446..81d1f39 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "prefer-stable": true, "require-dev": { "craftcms/phpstan": "dev-main", - "craftcms/craft": "^2.0|^5.0.0-alpha.1", + "craftcms/craft": "^4.0.0|^5.0.0-alpha.1", "symfony/var-dumper": "^5.0|^6.0", "laravel/pint": "^1.13" } From 6aa2833ff45b06395b2262b6f23fd6bee4762b16 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:11:20 -0400 Subject: [PATCH 34/67] refactor to use sectionserviceinterface so it satisfies PHPStan on v4 and v5 --- src/factories/Entry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 0ff16a0..34f471a 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -203,7 +203,7 @@ public function inferences(array $definition = []) $typeId = $this->inferTypeId($sectionId); } else { $sectionId = null; - $typeId = \Craft::$app->getEntries()->getEntryTypeByHandle($this->entryTypeIdentifier)->id; + $typeId = service(SectionsServiceInterface::class)->getEntryTypeByHandle($this->entryTypeIdentifier)->id; } return array_merge($definition, [ From 9c91a16aea4ff930500ed6638e8e6af7fb0e512d Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:19:16 -0400 Subject: [PATCH 35/67] fixing phpstan version constraints --- composer.json | 2 +- phpstan.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 81d1f39..4992d32 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "symfony/process": "^5.3|^6.0", "pestphp/pest": "^2.26", "vlucas/phpdotenv": "^2.4|^3.4|^5.4", - "craftcms/cms": "^4.5|^5.0.0-beta.1", + "craftcms/cms": "~4.6.0", "illuminate/support": "^9.52|^10.0", "composer/composer": "^2.7", "composer/semver": "^3.4" diff --git a/phpstan.php b/phpstan.php index 477c38a..cb00f87 100644 --- a/phpstan.php +++ b/phpstan.php @@ -5,11 +5,11 @@ $config = []; -if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0')) { +if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0')) { $config['includes'][] = 'phpstan-craft4.neon'; } -if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0.0')) { +if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0')) { $config['includes'][] = 'phpstan-craft5.neon'; } From d5b7ae34eb0871506359f6ebd86b9023d4f0f32c Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:25:13 -0400 Subject: [PATCH 36/67] fixing semver constraints --- src/Pest.php | 2 +- src/factories/MatrixField.php | 4 ++-- src/helpers/Craft.php | 4 ++-- src/test/RefreshesDatabase.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Pest.php b/src/Pest.php index 81d748e..d7de25d 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -56,7 +56,7 @@ function (DefineBehaviorsEvent $event) { ); Craft::$container->set(SectionsServiceInterface::class, function () { - return Semver::satisfies(Craft::$app->version, '~5.0.0') ? + return Semver::satisfies(Craft::$app->version, '~5.0') ? Craft::$app->getEntries() : // @phpstan-ignore-line Craft::$app->getSections(); // @phpstan-ignore-line }); diff --git a/src/factories/MatrixField.php b/src/factories/MatrixField.php index 35bba52..27142d0 100644 --- a/src/factories/MatrixField.php +++ b/src/factories/MatrixField.php @@ -9,11 +9,11 @@ class MatrixField extends Field { public static function factory() { - if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0.0')) { + if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0')) { return MatrixFieldEntries::factory(); } - if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0')) { + if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0')) { return MatrixFieldBlocks::factory(); } diff --git a/src/helpers/Craft.php b/src/helpers/Craft.php index 2af8fb2..6484fed 100644 --- a/src/helpers/Craft.php +++ b/src/helpers/Craft.php @@ -10,12 +10,12 @@ function isCraftFive(): bool { - return Semver::satisfies(Craft::$app->version, '~5.0.0'); + return Semver::satisfies(Craft::$app->version, '~5.0'); } function isBeforeCraftFive(): bool { - return Semver::satisfies(Craft::$app->version, '<5.0.0'); + return Semver::satisfies(Craft::$app->version, '<5.0'); } /** diff --git a/src/test/RefreshesDatabase.php b/src/test/RefreshesDatabase.php index 6147cf7..2eb16c9 100644 --- a/src/test/RefreshesDatabase.php +++ b/src/test/RefreshesDatabase.php @@ -79,7 +79,7 @@ protected function stopListeningForStores() public function beforeStore(FactoryStoreEvent $event) { $isFieldFactory = is_a($event->sender, Field::class) || is_subclass_of($event->sender, Field::class); - $isCraft4 = InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0.0'); + $isCraft4 = InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0'); // We don't need to worry about autocommiting fields in Craft 5 because there is no longer // a dynamic content table. The field data goes in a JSON field so the DB schema never From 0ed273c270c064aca59fe63a78d2b8e56e4f8730 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:32:21 -0400 Subject: [PATCH 37/67] replacing composer constraint --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4992d32..81d1f39 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "symfony/process": "^5.3|^6.0", "pestphp/pest": "^2.26", "vlucas/phpdotenv": "^2.4|^3.4|^5.4", - "craftcms/cms": "~4.6.0", + "craftcms/cms": "^4.5|^5.0.0-beta.1", "illuminate/support": "^9.52|^10.0", "composer/composer": "^2.7", "composer/semver": "^3.4" From 1df3583df3d815d418a1317645f576386508f6ed Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:47:11 -0400 Subject: [PATCH 38/67] fixing project config for beta10 --- ...kTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml | 4 ++-- ...kTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml | 8 ++++---- stubs/config/project-5/project.yaml | 10 +++++----- .../posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml | 9 +++++++++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml b/stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml index 8c1fbd3..d8d2701 100644 --- a/stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml +++ b/stubs/config/project-5/entryTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml @@ -36,7 +36,7 @@ fieldLayouts: width: 100 - elementCondition: null - fieldUid: c05f8773-60a8-4f5e-9925-3cc36a064793 # Matrix Field - Block Type One - Field One + fieldUid: c05f8773-60a8-4f5e-9925-3cc36a064793 # Field One handle: null includeInCards: true instructions: null @@ -51,7 +51,7 @@ fieldLayouts: width: 100 - elementCondition: null - fieldUid: 10199d0e-57f0-4724-aefb-1ef4ed73b408 # Matrix Field - Block Type One - Field Two + fieldUid: 10199d0e-57f0-4724-aefb-1ef4ed73b408 # Field Two handle: null includeInCards: false instructions: null diff --git a/stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml b/stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml index f095f71..a95c29e 100644 --- a/stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml +++ b/stubs/config/project-5/matrixBlockTypes/blockTypeOne--b5c238dd-588f-4f0a-b9e4-8a988f0e7468.yaml @@ -7,7 +7,7 @@ fieldLayouts: elements: - elementCondition: null - fieldUid: c05f8773-60a8-4f5e-9925-3cc36a064793 # Matrix Field - Block Type One - Field One + fieldUid: c05f8773-60a8-4f5e-9925-3cc36a064793 # Field One instructions: null label: null required: false @@ -19,7 +19,7 @@ fieldLayouts: width: 100 - elementCondition: null - fieldUid: 10199d0e-57f0-4724-aefb-1ef4ed73b408 # Matrix Field - Block Type One - Field Two + fieldUid: 10199d0e-57f0-4724-aefb-1ef4ed73b408 # Field Two instructions: null label: null required: false @@ -33,7 +33,7 @@ fieldLayouts: uid: aad92478-a4a8-49e5-b88b-5fff4734eb2c userCondition: null fields: - 10199d0e-57f0-4724-aefb-1ef4ed73b408: # Matrix Field - Block Type One - Field Two + 10199d0e-57f0-4724-aefb-1ef4ed73b408: # Field Two columnSuffix: swmzeype contentColumnType: text fieldGroup: null @@ -53,7 +53,7 @@ fields: translationKeyFormat: null translationMethod: none type: craft\fields\PlainText - c05f8773-60a8-4f5e-9925-3cc36a064793: # Matrix Field - Block Type One - Field One + c05f8773-60a8-4f5e-9925-3cc36a064793: # Field One columnSuffix: jnvscjst contentColumnType: text fieldGroup: null diff --git a/stubs/config/project-5/project.yaml b/stubs/config/project-5/project.yaml index 71dfd63..621b7d4 100644 --- a/stubs/config/project-5/project.yaml +++ b/stubs/config/project-5/project.yaml @@ -1,4 +1,4 @@ -dateModified: 1708290694 +dateModified: 1710967569 email: fromEmail: michael@bluth.com fromName: Pest @@ -16,21 +16,21 @@ meta: 3b2c4b24-e463-46ca-be26-7285804ecbb1: Local # Local 7d1a7bf3-c346-48bc-bb77-f7d76fcacf2e: 'Text Field' # Text Field 99c2747f-1049-46bc-93e0-424bad0544e5: Pest # Pest - 184fa66e-14cd-4045-853d-9a69ecf44e4e: 'Public Schema' + 184fa66e-14cd-4045-853d-9a69ecf44e4e: 'Public Schema' # Public Schema 0193fbbc-6912-4ff6-a3d5-e60ea03c8590: Default # Default - 10199d0e-57f0-4724-aefb-1ef4ed73b408: 'Field Two' # Matrix Field - Block Type One - Field Two + 10199d0e-57f0-4724-aefb-1ef4ed73b408: 'Field Two' # Field Two 17685ada-d64c-459c-b9fc-678d43e4bee8: 'Dropdown Field' # Dropdown Field ae919370-04f6-4e2d-8d42-f255cc1b6a75: Posts # Posts b5c238dd-588f-4f0a-b9e4-8a988f0e7468: 'Block Type One' # Block Type One b11e9b16-d6b0-4771-86bb-3fe962b4596d: Pest # Pest bda4d299-4f91-43c1-91d1-48abd1dd5fb4: Pest # Pest bdde35b2-daab-45e7-aef7-43fd8b221aa2: Pest # Pest - c05f8773-60a8-4f5e-9925-3cc36a064793: 'Field One' # Matrix Field - Block Type One - Field One + c05f8773-60a8-4f5e-9925-3cc36a064793: 'Field One' # Field One c148dfb3-a122-49ed-8538-de26d0482663: 'Entries Field' # Entries Field c7529b61-60cd-4e18-a272-3084aee7fa89: 'Matrix Field' # Matrix Field system: edition: solo live: true name: Pest - schemaVersion: 5.0.0.19 + schemaVersion: 5.0.0.20 timeZone: America/Los_Angeles diff --git a/stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml b/stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml index 03a5adc..54728c7 100644 --- a/stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml +++ b/stubs/config/project-5/sections/posts--ae919370-04f6-4e2d-8d42-f255cc1b6a75.yaml @@ -5,6 +5,15 @@ entryTypes: handle: posts maxAuthors: 1 name: Posts +previewTargets: + - + __assoc__: + - + - label + - 'Primary entry page' + - + - urlFormat + - '{url}' propagationMethod: all siteSettings: 99c2747f-1049-46bc-93e0-424bad0544e5: # Pest From 05d6e5f37a2b061350249e95fcd804aff91e4e90 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:52:12 -0400 Subject: [PATCH 39/67] phpstan fixes --- phpstan-craft5.neon | 4 +++- src/factories/MatrixFieldEntries.php | 26 +++++--------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/phpstan-craft5.neon b/phpstan-craft5.neon index 84e7adc..51a5c96 100644 --- a/phpstan-craft5.neon +++ b/phpstan-craft5.neon @@ -1,3 +1,5 @@ parameters: excludePaths: - - src/factories/BlockType.php \ No newline at end of file + - src/factories/AddsMatrixBlocks.php + - src/factories/BlockType.php + - src/factories/MatrixFieldBlocks.php diff --git a/src/factories/MatrixFieldEntries.php b/src/factories/MatrixFieldEntries.php index 440762b..d27908e 100644 --- a/src/factories/MatrixFieldEntries.php +++ b/src/factories/MatrixFieldEntries.php @@ -8,6 +8,9 @@ class MatrixFieldEntries extends Field { + /** + * @var EntryType[] + */ protected $entryTypes = []; public function entryTypes(...$entryTypes) @@ -44,13 +47,8 @@ public function store($element): bool // Push the block types in to the field $element->setEntryTypes( collect($this->entryTypes) - ->map - ->create() - ->flatten() - // ->each(function ($entryType, $index) use ($element) { - // $entryType->fieldId = $element->id; - // $entryType->sortOrder = $index; - // }) + ->map(fn (EntryType $entryType) => $entryType->create()) + ->flatten(1) ->toArray() ); @@ -64,7 +62,6 @@ public function store($element): bool } // Add the fields in to the block types - //dd($element->getEntryTypes()[0]->fieldLayout); collect($this->entryTypes) ->zip($element->getEntryTypes()) ->each(function ($props) { @@ -76,19 +73,6 @@ public function store($element): bool \Craft::$app->getEntries()->saveEntryType($entryType); }); - // In Craft 3.7 the Matrix Field model stores a reference to the `_blockTypes` of the - // matrix. Inside that reference the block type stores a reference to its `fieldLayoutId`. - // - // The reference to the Matrix Field is cached in to \Craft::$app->fields->_fields when the - // field is created and it's cached without a valid `fieldLayoutId`. - // - // The following grabs the global \Craft::$app->fields->field reference to this matrix field - // and updates the block types by pulling them fresh from the database. This ensures everything - // is up to date and there are no null fieldLayoutId values. - /** @var Matrix $cachedMatrixField */ - // $cachedMatrixField = \Craft::$app->fields->getFieldById($element->id); - // $cachedMatrixField->setEntryTypes(\Craft::$app->matrix->getEntryTypesByFieldId($element->id)); - return $result; } } From cf9a5020ad9e0c230560f6f43b79a0c708cdaf2b Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 16:59:16 -0400 Subject: [PATCH 40/67] allowing var_dump output for easier adoption --- phpunit.xml | 8 +++++++- stubs/init/phpunit.xml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 680bc7c..6e93a83 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,11 @@ - + ./tests diff --git a/stubs/init/phpunit.xml b/stubs/init/phpunit.xml index a04832d..eaac926 100644 --- a/stubs/init/phpunit.xml +++ b/stubs/init/phpunit.xml @@ -3,6 +3,7 @@ xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" + beStrictAboutOutputDuringTests="false" > From 53ccf4ff87e06aa5993e58a0b829da6f9d8146ab Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 20 Mar 2024 17:31:41 -0400 Subject: [PATCH 41/67] rerun pint --- src/factories/MatrixFieldEntries.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/factories/MatrixFieldEntries.php b/src/factories/MatrixFieldEntries.php index d27908e..f7377e2 100644 --- a/src/factories/MatrixFieldEntries.php +++ b/src/factories/MatrixFieldEntries.php @@ -4,8 +4,6 @@ use craft\fields\Matrix; -use function markhuot\craftpest\helpers\test\dd; - class MatrixFieldEntries extends Field { /** From 0bfde23b58d839981cbbc2b92e7d91b222ae28ef Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Thu, 21 Mar 2024 10:29:12 +0000 Subject: [PATCH 42/67] removing old helper --- src/factories/Field.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/factories/Field.php b/src/factories/Field.php index fe6b368..0974fa1 100644 --- a/src/factories/Field.php +++ b/src/factories/Field.php @@ -2,10 +2,10 @@ namespace markhuot\craftpest\factories; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use craft\helpers\StringHelper; -use function markhuot\craftpest\helpers\craft\isBeforeCraftFive; - /** * @method self name(string $name) * @method self handle(string $name) @@ -62,7 +62,7 @@ public function definition(int $index = 0) 'name' => $name, ]; - if (isBeforeCraftFive()) { + if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0')) { $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; // @phpstan-ignore-line $definition['groupId'] = $firstFieldGroupId; } From 684f4b8dd580ecd5a79e21dffaec611ecc2ff091 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Thu, 21 Mar 2024 10:35:54 +0000 Subject: [PATCH 43/67] removing old helper and reusing name --- src/factories/Section.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/factories/Section.php b/src/factories/Section.php index 4328323..530d414 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -2,16 +2,16 @@ namespace markhuot\craftpest\factories; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use Craft; use craft\helpers\StringHelper; use craft\models\EntryType; use craft\models\Section_SiteSettings; -use Faker\Factory as Faker; use Illuminate\Support\Collection; use markhuot\craftpest\interfaces\SectionsServiceInterface; use function markhuot\craftpest\helpers\base\service; -use function markhuot\craftpest\helpers\craft\isCraftFive; /** * @method self name(string $name) @@ -107,10 +107,10 @@ public function inferences(array $definition = []) return [$site->id => $settings]; })->toArray(); - if (isCraftFive()) { + if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0')) { if (empty($definition['entryTypes'])) { $entryType = new EntryType([ - 'name' => $name = $this->faker->words(3, true), + 'name' => $name, 'handle' => StringHelper::toHandle($name), ]); service(SectionsServiceInterface::class)->saveEntryType($entryType); From b8ee49f79798003307a23df54bf7c2fa97a641ab Mon Sep 17 00:00:00 2001 From: markhuot Date: Thu, 21 Mar 2024 10:03:56 -0400 Subject: [PATCH 44/67] removing unused code --- src/factories/Entry.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 34f471a..61da8c0 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -211,13 +211,4 @@ public function inferences(array $definition = []) 'typeId' => $typeId, ]); } - - public function toArray() - { - return [ - 'type' => $this->entryTypeIdentifier, - 'enabled' => true, - 'fields' => $this->attributes, - ]; - } } From e0309184b132dcb0cec70d793fedcc6660e2ad11 Mon Sep 17 00:00:00 2001 From: markhuot Date: Thu, 21 Mar 2024 19:46:40 -0400 Subject: [PATCH 45/67] bringing back types for factories --- phpstan-craft4.neon | 1 + phpstan-craft5.neon | 1 + src/Pest.php | 15 ++++- ...es.php => RenderCraft4CompiledClasses.php} | 6 +- src/actions/RenderCraft5CompiledClasses.php | 58 +++++++++++++++++++ src/console/IdeController.php | 37 ------------ src/console/PestController.php | 24 ++++---- .../RenderCompiledClassesInterface.php | 8 +++ src/test/TestCase.php | 23 ++++---- stubs/compiled_classes/FactoryFields.twig | 4 +- 10 files changed, 109 insertions(+), 68 deletions(-) rename src/actions/{RenderCompiledClasses.php => RenderCraft4CompiledClasses.php} (91%) create mode 100644 src/actions/RenderCraft5CompiledClasses.php delete mode 100644 src/console/IdeController.php create mode 100644 src/interfaces/RenderCompiledClassesInterface.php diff --git a/phpstan-craft4.neon b/phpstan-craft4.neon index eac525d..9dd0e85 100644 --- a/phpstan-craft4.neon +++ b/phpstan-craft4.neon @@ -1,4 +1,5 @@ parameters: excludePaths: + - src/actions/RenderCraft5CompiledClasses.php - src/factories/EntryType.php - src/factories/MatrixFieldEntries.php diff --git a/phpstan-craft5.neon b/phpstan-craft5.neon index 51a5c96..aa20a7d 100644 --- a/phpstan-craft5.neon +++ b/phpstan-craft5.neon @@ -1,5 +1,6 @@ parameters: excludePaths: + - src/actions/RenderCraft4CompiledClasses.php - src/factories/AddsMatrixBlocks.php - src/factories/BlockType.php - src/factories/MatrixFieldBlocks.php diff --git a/src/Pest.php b/src/Pest.php index d7de25d..3d92ccd 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -8,11 +8,14 @@ use craft\elements\db\ElementQuery; use craft\elements\Entry; use craft\events\DefineBehaviorsEvent; +use markhuot\craftpest\actions\RenderCraft4CompiledClasses; +use markhuot\craftpest\actions\RenderCraft5CompiledClasses; use markhuot\craftpest\behaviors\ExpectableBehavior; use markhuot\craftpest\behaviors\FieldTypeHintBehavior; use markhuot\craftpest\behaviors\TestableElementBehavior; use markhuot\craftpest\behaviors\TestableElementQueryBehavior; use markhuot\craftpest\console\PestController; +use markhuot\craftpest\interfaces\RenderCompiledClassesInterface; use markhuot\craftpest\interfaces\SectionsServiceInterface; use yii\base\BootstrapInterface; use yii\base\Event; @@ -56,9 +59,15 @@ function (DefineBehaviorsEvent $event) { ); Craft::$container->set(SectionsServiceInterface::class, function () { - return Semver::satisfies(Craft::$app->version, '~5.0') ? - Craft::$app->getEntries() : // @phpstan-ignore-line - Craft::$app->getSections(); // @phpstan-ignore-line + return Semver::satisfies(Craft::$app->version, '~5.0') + ? Craft::$app->getEntries() // @phpstan-ignore-line + : Craft::$app->getSections(); // @phpstan-ignore-line + }); + + Craft::$container->set(RenderCompiledClassesInterface::class, function () { + return Semver::satisfies(Craft::$app->version, '~5.0') + ? Craft::$container->get(RenderCraft5CompiledClasses::class) // @phpstan-ignore-line + : Craft::$container->get(RenderCraft4CompiledClasses::class); // @phpstan-ignore-line }); } } diff --git a/src/actions/RenderCompiledClasses.php b/src/actions/RenderCraft4CompiledClasses.php similarity index 91% rename from src/actions/RenderCompiledClasses.php rename to src/actions/RenderCraft4CompiledClasses.php index 0844624..15cbe09 100644 --- a/src/actions/RenderCompiledClasses.php +++ b/src/actions/RenderCraft4CompiledClasses.php @@ -2,13 +2,13 @@ namespace markhuot\craftpest\actions; -use craft\db\Table; use craft\helpers\FileHelper; use craft\helpers\StringHelper; +use markhuot\craftpest\interfaces\RenderCompiledClassesInterface; -class RenderCompiledClasses +class RenderCraft4CompiledClasses implements RenderCompiledClassesInterface { - public function handle($forceRecreate = false) + public function handle(bool $forceRecreate = false) { $contentService = \Craft::$app->getContent(); $originalContentTable = $contentService->contentTable; diff --git a/src/actions/RenderCraft5CompiledClasses.php b/src/actions/RenderCraft5CompiledClasses.php new file mode 100644 index 0000000..1b00c9c --- /dev/null +++ b/src/actions/RenderCraft5CompiledClasses.php @@ -0,0 +1,58 @@ +render($forceRecreate); + + return true; + } + + protected function render(bool $forceRecreate) + { + $storedFieldVersion = \Craft::$app->getFields()->getFieldVersion(); + $compiledClassesPath = \Craft::$app->getPath()->getCompiledClassesPath(); + $fieldVersionExists = $storedFieldVersion !== null; + if (! $fieldVersionExists) { + $storedFieldVersion = StringHelper::randomString(12); + } + + $compiledClassPath = $compiledClassesPath.DIRECTORY_SEPARATOR.'FactoryFields_'.$storedFieldVersion.'.php'; + + if (file_exists($compiledClassPath) && ! $forceRecreate) { + return false; + } + + $this->cleanupOldMixins('FactoryFields_'.$storedFieldVersion.'.php'); + + $template = file_get_contents(__DIR__.'/../../stubs/compiled_classes/FactoryFields.twig'); + + $compiledClass = \Craft::$app->view->renderString($template, [ + 'fields' => \Craft::$app->fields->getAllFields(), + ]); + + file_put_contents($compiledClassPath, $compiledClass); + } + + protected function cleanupOldMixins(?string $except = null) + { + $compiledClassesPath = __DIR__.'/../storage/'; + + FileHelper::clearDirectory($compiledClassesPath, [ + 'filter' => function (string $path) use ($except): bool { + $b = basename($path); + + return + str_starts_with($b, 'FactoryFields') && + ($except === null || $b !== $except); + }, + ]); + } +} diff --git a/src/console/IdeController.php b/src/console/IdeController.php deleted file mode 100644 index ffc2ecf..0000000 --- a/src/console/IdeController.php +++ /dev/null @@ -1,37 +0,0 @@ -handle($this->force); - $result = false; - - // @phpstan-ignore-next-line - if ($result) { - echo "Mixins successfully generated!\n"; - } else { - echo "Mixins already exist, skipping.\n"; - } - - return ExitCode::OK; - } -} diff --git a/src/console/PestController.php b/src/console/PestController.php index a20dcbd..04137fa 100644 --- a/src/console/PestController.php +++ b/src/console/PestController.php @@ -2,9 +2,11 @@ namespace markhuot\craftpest\console; +use Craft; use craft\console\Controller; use craft\helpers\FileHelper; -use markhuot\craftpest\actions\RenderCompiledClasses; +use markhuot\craftpest\actions\RenderCraft4CompiledClasses; +use markhuot\craftpest\interfaces\RenderCompiledClassesInterface; use markhuot\craftpest\Pest; use Symfony\Component\Process\Process; use yii\console\ExitCode; @@ -112,7 +114,7 @@ protected function runTests() public function actionCompileTemplates() { - $compiledTemplatesDir = \Craft::$app->path->getCompiledTemplatesPath(); + $compiledTemplatesDir = Craft::$app->path->getCompiledTemplatesPath(); FileHelper::removeDirectory($compiledTemplatesDir); $compileTemplates = function ($path, $base = '') { @@ -128,32 +130,30 @@ public function actionCompileTemplates() if ($logicalName === 'index.twig' || $logicalName === 'index.html') { $logicalName = ''; } - $oldTemplateMode = \Craft::$app->view->getTemplateMode(); - \Craft::$app->view->setTemplateMode('site'); - $twig = \Craft::$app->view->twig; - if (version_greater_than_or_equal_to(\Craft::$app->version, '4')) { + $oldTemplateMode = Craft::$app->view->getTemplateMode(); + Craft::$app->view->setTemplateMode('site'); + $twig = Craft::$app->view->twig; + if (version_greater_than_or_equal_to(Craft::$app->version, '4')) { // @phpstan-ignore-next-line Ignored because one of these will fail based on the installed version of Craft $twig->loadTemplate($twig->getTemplateClass($logicalName), $logicalName); - } elseif (version_greater_than_or_equal_to(\Craft::$app->version, '3')) { + } elseif (version_greater_than_or_equal_to(Craft::$app->version, '3')) { // @phpstan-ignore-next-line Ignored because one of these will fail based on the installed version of Craft $twig->loadTemplate($logicalName); } - \Craft::$app->view->setTemplateMode($oldTemplateMode); + Craft::$app->view->setTemplateMode($oldTemplateMode); } }; // hack - $compileTemplates(\Craft::getAlias('@templates')); + $compileTemplates(Craft::getAlias('@templates')); return 0; } public function actionGenerateMixins() { - // $result = (new RenderCompiledClasses)->handle($this->force); - $result = false; + $result = Craft::$container->get(RenderCompiledClassesInterface::class)->handle($this->force); - // @phpstan-ignore-next-line if ($result) { echo "Mixins successfully generated!\n"; } else { diff --git a/src/interfaces/RenderCompiledClassesInterface.php b/src/interfaces/RenderCompiledClassesInterface.php new file mode 100644 index 0000000..193012d --- /dev/null +++ b/src/interfaces/RenderCompiledClassesInterface.php @@ -0,0 +1,8 @@ +needsRequireStatements()) { - return \Craft::$app; + return Craft::$app; } $this->requireCraft(); $needsRefresh = false; - if (! \Craft::$app->getIsInstalled(true)) { + if (! Craft::$app->getIsInstalled(true)) { $this->craftInstall(); $needsRefresh = true; } if ( - \Craft::$app->getMigrator()->getNewMigrations() || - \Craft::$app->getContentMigrator()->getNewMigrations() + Craft::$app->getMigrator()->getNewMigrations() || + Craft::$app->getContentMigrator()->getNewMigrations() ) { $this->craftMigrateAll(); $needsRefresh = true; @@ -87,8 +88,8 @@ public function createApplication() // tests you'll reach in to the same cache as the dev side and pull that the project config is unchanged // even though it actually _is_ changed. This ensures that there isn't any cache sharing between dev // and test. - \Craft::$app->getCache()->flush(); - if (\Craft::$app->getProjectConfig()->areChangesPending(null, true)) { + Craft::$app->getCache()->flush(); + if (Craft::$app->getProjectConfig()->areChangesPending(null, true)) { $this->craftProjectConfigApply(); $needsRefresh = true; } @@ -99,7 +100,7 @@ public function createApplication() exit($this->reRunPest()); } - return \Craft::$app; + return Craft::$app; } protected function craftInstall() @@ -111,7 +112,7 @@ protected function craftInstall() '--interactive='.(App::env('CRAFT_INSTALL_INTERACTIVE') ?? '0'), ]; - if (! file_exists(\Craft::getAlias('@config/project/project.yaml'))) { + if (! file_exists(Craft::getAlias('@config/project/project.yaml'))) { $args = array_merge($args, [ '--siteName='.(App::env('CRAFT_INSTALL_SITENAME') ?? '"Craft CMS"'), '--siteUrl='.(App::env('CRAFT_INSTALL_SITEURL') ?? 'http://localhost:8080'), @@ -200,7 +201,7 @@ protected function reRunPest() public function renderCompiledClasses() { - // (new RenderCompiledClasses)->handle(); + Craft::$container->get(RenderCompiledClassesInterface::class)->handle(); } protected function needsRequireStatements() @@ -248,7 +249,7 @@ public function console(array|string $command) public function renderTemplate(...$args) { - $content = \Craft::$app->getView()->renderTemplate(...$args); + $content = Craft::$app->getView()->renderTemplate(...$args); return new \markhuot\craftpest\web\TestableResponse(['content' => $content]); } diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 2f1e89e..2d7c745 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -4,11 +4,11 @@ namespace markhuot\craftpest\storage; /** {% for field in fields %} - * @method $this {{ field.handle }}({{ field.factoryTypeHint|default('mixed $value') }}) Sets the {{ field.name }} custom field {{ field.valueType }} + * @method $this {{ field.handle }}({{ field.factoryTypeHint|default('mixed $value') }}): {{ field.phpType() }} Sets the {{ field.name }} custom field {% endfor %} * {% for field in fields %} - {% if 'craft\\elements\\db\\MatrixBlockQuery' in field.valueType %} + {% if 'craft\\elements\\db\\MatrixBlockQuery' in field.phpType() %} {% for blockType in field.blockTypes %} {% if loop.first %} * @method $this addBlockTo{{ field.handle|ucfirst }}({{ blockType.fieldLayout.getCustomFieldElements()|map(f => f.getField().factoryTypeHint|default('mixed $value'))|join(', ') }}) From d1624284697d83f12d9c0f95f7bca9588396d5e4 Mon Sep 17 00:00:00 2001 From: markhuot Date: Thu, 21 Mar 2024 19:50:31 -0400 Subject: [PATCH 46/67] replacing missing import --- src/actions/RenderCraft4CompiledClasses.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/actions/RenderCraft4CompiledClasses.php b/src/actions/RenderCraft4CompiledClasses.php index 15cbe09..a811717 100644 --- a/src/actions/RenderCraft4CompiledClasses.php +++ b/src/actions/RenderCraft4CompiledClasses.php @@ -2,6 +2,7 @@ namespace markhuot\craftpest\actions; +use craft\db\Table; use craft\helpers\FileHelper; use craft\helpers\StringHelper; use markhuot\craftpest\interfaces\RenderCompiledClassesInterface; From ff835b1e4c5f267f8632c7469650def9f7cebc70 Mon Sep 17 00:00:00 2001 From: markhuot Date: Thu, 21 Mar 2024 19:52:34 -0400 Subject: [PATCH 47/67] pint --- src/console/PestController.php | 1 - src/test/TestCase.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/console/PestController.php b/src/console/PestController.php index 04137fa..f7db290 100644 --- a/src/console/PestController.php +++ b/src/console/PestController.php @@ -5,7 +5,6 @@ use Craft; use craft\console\Controller; use craft\helpers\FileHelper; -use markhuot\craftpest\actions\RenderCraft4CompiledClasses; use markhuot\craftpest\interfaces\RenderCompiledClassesInterface; use markhuot\craftpest\Pest; use Symfony\Component\Process\Process; diff --git a/src/test/TestCase.php b/src/test/TestCase.php index c3e8291..e06c8b7 100644 --- a/src/test/TestCase.php +++ b/src/test/TestCase.php @@ -201,7 +201,7 @@ protected function reRunPest() public function renderCompiledClasses() { - Craft::$container->get(RenderCompiledClassesInterface::class)->handle(); + Craft::$container->get(RenderCompiledClassesInterface::class)->handle(); } protected function needsRequireStatements() From 2b16314693d3ae370635d466af9476100664e4f3 Mon Sep 17 00:00:00 2001 From: markhuot Date: Thu, 21 Mar 2024 19:55:23 -0400 Subject: [PATCH 48/67] v4 v.s. v5 method name --- stubs/compiled_classes/FactoryFields.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 2d7c745..4fc8281 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -4,11 +4,11 @@ namespace markhuot\craftpest\storage; /** {% for field in fields %} - * @method $this {{ field.handle }}({{ field.factoryTypeHint|default('mixed $value') }}): {{ field.phpType() }} Sets the {{ field.name }} custom field + * @method $this {{ field.handle }}({{ field.factoryTypeHint|default('mixed $value') }}): {{ field.valueType|default(field.phpType)|default('mixed') }} Sets the {{ field.name }} custom field {% endfor %} * {% for field in fields %} - {% if 'craft\\elements\\db\\MatrixBlockQuery' in field.phpType() %} + {% if 'craft\\elements\\db\\MatrixBlockQuery' in field.valueType|default(field.phpType)|default('mixed') %} {% for blockType in field.blockTypes %} {% if loop.first %} * @method $this addBlockTo{{ field.handle|ucfirst }}({{ blockType.fieldLayout.getCustomFieldElements()|map(f => f.getField().factoryTypeHint|default('mixed $value'))|join(', ') }}) From e10c68f9df72e7dafc868b3ae09da347fa06534a Mon Sep 17 00:00:00 2001 From: markhuot Date: Thu, 21 Mar 2024 20:02:13 -0400 Subject: [PATCH 49/67] v4 v.s. v5 method name --- stubs/compiled_classes/FactoryFields.twig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 4fc8281..65036f6 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -4,11 +4,18 @@ namespace markhuot\craftpest\storage; /** {% for field in fields %} - * @method $this {{ field.handle }}({{ field.factoryTypeHint|default('mixed $value') }}): {{ field.valueType|default(field.phpType)|default('mixed') }} Sets the {{ field.name }} custom field + {% if attribute(field, 'valueType') is defined %} +{% set type = field.valueType() %} +{% elseif attribute(field, 'phpType') is defined %} +{% set type = field.phpType() %} +{% else %} +{% set type = 'mixed' %} +{% endif %} + * @method $this {{ field.handle }}({{ field.factoryTypeHint|default('mixed $value') }}): {{ type }} Sets the {{ field.name }} custom field {% endfor %} * {% for field in fields %} - {% if 'craft\\elements\\db\\MatrixBlockQuery' in field.valueType|default(field.phpType)|default('mixed') %} + {% if 'craft\\elements\\db\\MatrixBlockQuery' in type %} {% for blockType in field.blockTypes %} {% if loop.first %} * @method $this addBlockTo{{ field.handle|ucfirst }}({{ blockType.fieldLayout.getCustomFieldElements()|map(f => f.getField().factoryTypeHint|default('mixed $value'))|join(', ') }}) From 81343e1c8036ce94eda3e38cd9f5e19f97f565a6 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Mon, 8 Apr 2024 08:37:57 -0600 Subject: [PATCH 50/67] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 81d1f39..aa0e889 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "pestphp/pest": "^2.26", "vlucas/phpdotenv": "^2.4|^3.4|^5.4", "craftcms/cms": "^4.5|^5.0.0-beta.1", - "illuminate/support": "^9.52|^10.0", + "illuminate/support": "^9.52|^10.0|^11.0", "composer/composer": "^2.7", "composer/semver": "^3.4" }, From ee96a9715a2cf80bdf2c3303cfcc988a600d5912 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Mon, 8 Apr 2024 09:26:12 -0600 Subject: [PATCH 51/67] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index aa0e889..9d0c1bf 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "pestphp/pest": "^2.26", "vlucas/phpdotenv": "^2.4|^3.4|^5.4", "craftcms/cms": "^4.5|^5.0.0-beta.1", - "illuminate/support": "^9.52|^10.0|^11.0", + "illuminate/support": "^9.52|^10.0|^v11.0", "composer/composer": "^2.7", "composer/semver": "^3.4" }, From f1f032ae880f0a3f3490fb1d7ba64c81f846ad38 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Mon, 8 Apr 2024 09:28:26 -0600 Subject: [PATCH 52/67] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9d0c1bf..aa0e889 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "pestphp/pest": "^2.26", "vlucas/phpdotenv": "^2.4|^3.4|^5.4", "craftcms/cms": "^4.5|^5.0.0-beta.1", - "illuminate/support": "^9.52|^10.0|^v11.0", + "illuminate/support": "^9.52|^10.0|^11.0", "composer/composer": "^2.7", "composer/semver": "^3.4" }, From 62ce5e04c1810ec5c4856b4efa5087911ed3e6a7 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Thu, 2 May 2024 20:01:18 -0600 Subject: [PATCH 53/67] Update FactoryFields.twig --- stubs/compiled_classes/FactoryFields.twig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 65036f6..0fefeab 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -3,10 +3,11 @@ namespace markhuot\craftpest\storage; /** + {% set type = '' %} {% for field in fields %} - {% if attribute(field, 'valueType') is defined %} + {% if craft.app.version < 5 %} {% set type = field.valueType() %} -{% elseif attribute(field, 'phpType') is defined %} +{% elseif craft.app.version > 5 %} {% set type = field.phpType() %} {% else %} {% set type = 'mixed' %} From 65c06128ba93400855bb8c84820cfd11004c03af Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Thu, 2 May 2024 20:08:25 -0600 Subject: [PATCH 54/67] Update FactoryFields.twig --- stubs/compiled_classes/FactoryFields.twig | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 0fefeab..3a53300 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -3,7 +3,6 @@ namespace markhuot\craftpest\storage; /** - {% set type = '' %} {% for field in fields %} {% if craft.app.version < 5 %} {% set type = field.valueType() %} From 4f96b5ad6a3201182b7dc7aeaf266bf96eabbeb6 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Thu, 2 May 2024 20:14:25 -0600 Subject: [PATCH 55/67] Update FactoryFields.twig --- stubs/compiled_classes/FactoryFields.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 3a53300..0fefeab 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -3,6 +3,7 @@ namespace markhuot\craftpest\storage; /** + {% set type = '' %} {% for field in fields %} {% if craft.app.version < 5 %} {% set type = field.valueType() %} From 96d1261886029051d9851f3d25fc2132f252e102 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Thu, 2 May 2024 20:16:55 -0600 Subject: [PATCH 56/67] Update FactoryFields.twig --- stubs/compiled_classes/FactoryFields.twig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 0fefeab..8cec8ab 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -3,14 +3,12 @@ namespace markhuot\craftpest\storage; /** - {% set type = '' %} + {% set type = 'mixed' %} {% for field in fields %} {% if craft.app.version < 5 %} {% set type = field.valueType() %} {% elseif craft.app.version > 5 %} {% set type = field.phpType() %} -{% else %} -{% set type = 'mixed' %} {% endif %} * @method $this {{ field.handle }}({{ field.factoryTypeHint|default('mixed $value') }}): {{ type }} Sets the {{ field.name }} custom field {% endfor %} From af34e1dd34449eefc276c5096f1b75cf7dc3a2e3 Mon Sep 17 00:00:00 2001 From: markhuot Date: Wed, 15 May 2024 16:06:01 -0400 Subject: [PATCH 57/67] fixes for Craft 4 --- src/factories/Entry.php | 20 +++++++++----------- src/interfaces/SectionsServiceInterface.php | 2 ++ stubs/compiled_classes/FactoryFields.twig | 9 ++++++++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 61da8c0..8fdd473 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -145,10 +145,6 @@ public function inferSectionId(): ?int $section = service(SectionsServiceInterface::class)->getSectionByHandle($sectionHandle); } - if (empty($section)) { - $section = Section::factory()->create(); - } - return $section?->id; } @@ -159,10 +155,11 @@ public function inferSectionId(): ?int */ public function inferTypeId(?int $sectionid): ?int { - $entryTypes = collect(); if ($sectionid) { $section = service(SectionsServiceInterface::class)->getSectionById($sectionid); $entryTypes = collect($section->getEntryTypes()); + } else { + $entryTypes = collect(service(SectionsServiceInterface::class)->getAllEntryTypes()); } if (is_a($this->entryTypeIdentifier, \craft\models\EntryType::class)) { @@ -198,12 +195,13 @@ public function newElement() */ public function inferences(array $definition = []) { - if (empty($this->entryTypeIdentifier)) { - $sectionId = $this->inferSectionId(); - $typeId = $this->inferTypeId($sectionId); - } else { - $sectionId = null; - $typeId = service(SectionsServiceInterface::class)->getEntryTypeByHandle($this->entryTypeIdentifier)->id; + $sectionId = $this->inferSectionId(); + $typeId = $this->inferTypeId($sectionId); + + // If you couldn't infer anything, then create a new section/type + if (empty($sectionId) && empty($typeId)) { + $sectionId = ($section = Section::factory()->create())->id; + $typeId = collect($section->getEntryTypes())->first()?->id; } return array_merge($definition, [ diff --git a/src/interfaces/SectionsServiceInterface.php b/src/interfaces/SectionsServiceInterface.php index a87f813..b94850b 100644 --- a/src/interfaces/SectionsServiceInterface.php +++ b/src/interfaces/SectionsServiceInterface.php @@ -15,6 +15,8 @@ public function getSectionById(int $id): ?Section; public function getSectionByHandle(string $handle): ?Section; + public function getAllEntryTypes(): array; + public function getEntryTypeById(int $id): ?EntryType; public function getEntryTypeByHandle(string $handle): ?EntryType; diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 65036f6..4b88f9a 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -15,7 +15,14 @@ namespace markhuot\craftpest\storage; {% endfor %} * {% for field in fields %} - {% if 'craft\\elements\\db\\MatrixBlockQuery' in type %} + {% if attribute(field, 'valueType') is defined %} +{% set type = field.valueType() %} +{% elseif attribute(field, 'phpType') is defined %} +{% set type = field.phpType() %} +{% else %} +{% set type = 'mixed' %} +{% endif %} + {% if 'craft\\elements\\db\\MatrixBlockQuery' == type %} {% for blockType in field.blockTypes %} {% if loop.first %} * @method $this addBlockTo{{ field.handle|ucfirst }}({{ blockType.fieldLayout.getCustomFieldElements()|map(f => f.getField().factoryTypeHint|default('mixed $value'))|join(', ') }}) From 417e22ac8997842a9fe822743400442ff4d0e637 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:23:02 +0200 Subject: [PATCH 58/67] Update FactoryFields.twig --- stubs/compiled_classes/FactoryFields.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/compiled_classes/FactoryFields.twig b/stubs/compiled_classes/FactoryFields.twig index 25e503b..f6341cc 100644 --- a/stubs/compiled_classes/FactoryFields.twig +++ b/stubs/compiled_classes/FactoryFields.twig @@ -14,9 +14,9 @@ namespace markhuot\craftpest\storage; {% endfor %} * {% for field in fields %} - {% if attribute(field, 'valueType') is defined %} + {% if craft.app.version < 5 %} {% set type = field.valueType() %} -{% elseif attribute(field, 'phpType') is defined %} +{% elseif craft.app.version > 5 %} {% set type = field.phpType() %} {% else %} {% set type = 'mixed' %} From 85c31e4bb1ee1a825bdf099494e90a439caae670 Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 12:37:38 -0400 Subject: [PATCH 59/67] phpstan adjustment --- src/bin/generate-docs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/generate-docs.php b/src/bin/generate-docs.php index 108e01c..0554620 100644 --- a/src/bin/generate-docs.php +++ b/src/bin/generate-docs.php @@ -59,7 +59,7 @@ function parseClass(string $className) function parseComment(string $comment) { preg_match_all('/@see\s+(.+)$/m', $comment, $sees); - foreach (($sees[1] ?? []) as $index => $otherClass) { + foreach ($sees[1] as $index => $otherClass) { $comment = str_replace($sees[0][$index], 'SEE['.$otherClass.']', $comment); } @@ -71,7 +71,7 @@ function parseComment(string $comment) $comment = preg_replace('/(^\s+|\s+$)/', '', $comment); preg_match_all('/^SEE\[(.+)\]$/m', $comment, $sees); - foreach (($sees[1] ?? []) as $index => $otherClass) { + foreach ($sees[1] as $index => $otherClass) { $comment = str_replace($sees[0][$index], "\n\n".implode("\n\n", parseClass($otherClass))."\n\n", $comment); } From 981d5cfdd6f2d5c93c8c98f94ae07f0878750c3a Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 12:51:23 -0400 Subject: [PATCH 60/67] pint --- bin/create-default-fs.php | 2 +- src/overrides/Config.php | 4 +--- src/overrides/ProjectConfig.php | 4 +--- src/pest/PhpReporter.php | 4 +--- src/test/DatabaseAssertions.php | 2 +- src/test/RefreshesDatabase.php | 2 +- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/bin/create-default-fs.php b/bin/create-default-fs.php index f47a1b0..43ef82d 100755 --- a/bin/create-default-fs.php +++ b/bin/create-default-fs.php @@ -22,7 +22,7 @@ $volume = $app->volumes->getVolumeByHandle('local'); if (! $volume) { - $volume = new \craft\models\Volume(); + $volume = new \craft\models\Volume; $volume->name = 'Local'; $volume->handle = 'local'; $volume->fs = $fs; diff --git a/src/overrides/Config.php b/src/overrides/Config.php index 8ee1675..9664291 100644 --- a/src/overrides/Config.php +++ b/src/overrides/Config.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\overrides; -class Config extends \craft\services\Config -{ -} +class Config extends \craft\services\Config {} diff --git a/src/overrides/ProjectConfig.php b/src/overrides/ProjectConfig.php index 64d524f..ad8495e 100644 --- a/src/overrides/ProjectConfig.php +++ b/src/overrides/ProjectConfig.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\overrides; -class ProjectConfig extends \craft\services\Config -{ -} +class ProjectConfig extends \craft\services\Config {} diff --git a/src/pest/PhpReporter.php b/src/pest/PhpReporter.php index 7c8f963..abcff2a 100644 --- a/src/pest/PhpReporter.php +++ b/src/pest/PhpReporter.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\pest; -class PhpReporter extends Reporter -{ -} +class PhpReporter extends Reporter {} diff --git a/src/test/DatabaseAssertions.php b/src/test/DatabaseAssertions.php index e43a8cc..fa47769 100644 --- a/src/test/DatabaseAssertions.php +++ b/src/test/DatabaseAssertions.php @@ -22,7 +22,7 @@ trait DatabaseAssertions */ public function assertDatabaseCount(string $tableName, int $expectedCount) { - $actualCount = (new Query())->from($tableName)->count(); + $actualCount = (new Query)->from($tableName)->count(); $this->assertEquals($expectedCount, $actualCount); } diff --git a/src/test/RefreshesDatabase.php b/src/test/RefreshesDatabase.php index 2eb16c9..d51c485 100644 --- a/src/test/RefreshesDatabase.php +++ b/src/test/RefreshesDatabase.php @@ -129,7 +129,7 @@ public function rollBackTransaction() $this->transaction->rollBack(); - $event = new RollbackTransactionEvent(); + $event = new RollbackTransactionEvent; $event->sender = $this; Event::trigger(RefreshesDatabase::class, 'EVENT_ROLLBACK_TRANSACTION', $event); From 62ac020ad7f015c73dd16f3e2ec1e2469652474e Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 12:54:27 -0400 Subject: [PATCH 61/67] pint --- src/console/TestableResponse.php | 3 +-- src/events/RollbackTransactionEvent.php | 4 +--- src/exceptions/AutoCommittingFieldsException.php | 4 +--- src/factories/Asset.php | 2 +- src/factories/BlockType.php | 2 +- src/factories/Category.php | 2 +- src/factories/Entry.php | 2 +- src/factories/EntryType.php | 2 +- src/factories/Fieldable.php | 2 +- src/factories/Section.php | 4 ++-- src/helpers/Craft.php | 2 +- src/http/requests/GetRequest.php | 4 +--- src/http/requests/PostRequest.php | 4 +--- src/web/BenchmarkResult.php | 3 +-- 14 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/console/TestableResponse.php b/src/console/TestableResponse.php index 4861fef..0b9314e 100644 --- a/src/console/TestableResponse.php +++ b/src/console/TestableResponse.php @@ -10,8 +10,7 @@ public function __construct( protected int $exitCode, protected string $stdout, protected string $stderr, - ) { - } + ) {} public function assertSuccesful() { diff --git a/src/events/RollbackTransactionEvent.php b/src/events/RollbackTransactionEvent.php index add3448..18d2d7b 100644 --- a/src/events/RollbackTransactionEvent.php +++ b/src/events/RollbackTransactionEvent.php @@ -4,6 +4,4 @@ use yii\base\Event; -class RollbackTransactionEvent extends Event -{ -} +class RollbackTransactionEvent extends Event {} diff --git a/src/exceptions/AutoCommittingFieldsException.php b/src/exceptions/AutoCommittingFieldsException.php index 2d9158d..ff89255 100644 --- a/src/exceptions/AutoCommittingFieldsException.php +++ b/src/exceptions/AutoCommittingFieldsException.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\exceptions; -class AutoCommittingFieldsException extends \Exception -{ -} +class AutoCommittingFieldsException extends \Exception {} diff --git a/src/factories/Asset.php b/src/factories/Asset.php index 9190709..d7eff35 100644 --- a/src/factories/Asset.php +++ b/src/factories/Asset.php @@ -78,7 +78,7 @@ public function source(string $source) public function newElement() { - return new \craft\elements\Asset(); + return new \craft\elements\Asset; } public function definition(int $index = 0) diff --git a/src/factories/BlockType.php b/src/factories/BlockType.php index aaa1354..824f6d7 100644 --- a/src/factories/BlockType.php +++ b/src/factories/BlockType.php @@ -33,7 +33,7 @@ public function inferences(array $definition = []) public function newElement() { - return new MatrixBlockType(); + return new MatrixBlockType; } public function store($blockType) diff --git a/src/factories/Category.php b/src/factories/Category.php index c041b08..204dca2 100644 --- a/src/factories/Category.php +++ b/src/factories/Category.php @@ -22,7 +22,7 @@ public function group($handle) public function newElement() { - return new \craft\elements\Category(); + return new \craft\elements\Category; } public function definition(int $index = 0) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 8fdd473..444dcb3 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -187,7 +187,7 @@ public function inferTypeId(?int $sectionid): ?int */ public function newElement() { - return new \craft\elements\Entry(); + return new \craft\elements\Entry; } /** diff --git a/src/factories/EntryType.php b/src/factories/EntryType.php index a8431ba..68caf14 100644 --- a/src/factories/EntryType.php +++ b/src/factories/EntryType.php @@ -35,7 +35,7 @@ public function inferences(array $definition = []) public function newElement() { - return new EntryTypeModel(); + return new EntryTypeModel; } public function store($entryType) diff --git a/src/factories/Fieldable.php b/src/factories/Fieldable.php index 41461b4..fa21954 100644 --- a/src/factories/Fieldable.php +++ b/src/factories/Fieldable.php @@ -55,7 +55,7 @@ public function storeFields(FieldLayout $fieldLayout, $context = null) ->toArray(); if (empty($fieldLayout->getTabs()[0])) { - $fieldLayoutTab = new FieldLayoutTab(); + $fieldLayoutTab = new FieldLayoutTab; $fieldLayoutTab->name = 'Content'; $fieldLayoutTab->sortOrder = 1; $fieldLayout->setTabs([$fieldLayoutTab]); diff --git a/src/factories/Section.php b/src/factories/Section.php index 530d414..6d75cdf 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -66,7 +66,7 @@ public function template(string $template) */ public function newElement() { - return new \craft\models\Section(); + return new \craft\models\Section; } /** @@ -94,7 +94,7 @@ public function inferences(array $definition = []) $handle = $definition['handle']; $definition['siteSettings'] = collect(Craft::$app->sites->getAllSites()) ->mapWithkeys(function ($site) use ($name, $handle) { - $settings = new Section_SiteSettings(); + $settings = new Section_SiteSettings; $settings->siteId = $site->id; $settings->hasUrls = $this->hasUrls; $settings->uriFormat = $this->uriFormat; diff --git a/src/helpers/Craft.php b/src/helpers/Craft.php index 6484fed..96d5b8e 100644 --- a/src/helpers/Craft.php +++ b/src/helpers/Craft.php @@ -80,7 +80,7 @@ function createVolume() function volumeDefinition(array $definition = []) { if (version_greater_than_or_equal_to(\Craft::$app->version, '4')) { - $fileSystem = new \craft\fs\Local(); // @phpstan-ignore-line + $fileSystem = new \craft\fs\Local; // @phpstan-ignore-line $fileSystem->name = $definition['name'].' FS'; // @phpstan-ignore-line $fileSystem->handle = $definition['handle'].'Fs'; // @phpstan-ignore-line $fileSystem->path = \Craft::getAlias('@storage').'/volumes/'.$definition['handle'].'/'; // @phpstan-ignore-line diff --git a/src/http/requests/GetRequest.php b/src/http/requests/GetRequest.php index 1675c23..e85b0b2 100644 --- a/src/http/requests/GetRequest.php +++ b/src/http/requests/GetRequest.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\http\requests; -class GetRequest extends WebRequest -{ -} +class GetRequest extends WebRequest {} diff --git a/src/http/requests/PostRequest.php b/src/http/requests/PostRequest.php index 59502fa..8f70355 100644 --- a/src/http/requests/PostRequest.php +++ b/src/http/requests/PostRequest.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\http\requests; -class PostRequest extends WebRequest -{ -} +class PostRequest extends WebRequest {} diff --git a/src/web/BenchmarkResult.php b/src/web/BenchmarkResult.php index 6f7fa20..33056d6 100644 --- a/src/web/BenchmarkResult.php +++ b/src/web/BenchmarkResult.php @@ -29,8 +29,7 @@ class BenchmarkResult public function __construct( public int $startProfileAt, public int $endProfileAt, - ) { - } + ) {} // function summary() // { From 43bef3dbde052cefcebb7394964d39c0306bfc05 Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 13:11:20 -0400 Subject: [PATCH 62/67] only infer entry types if a section is defined. Otherwise Craft 5 will try to infer type ids from "matrix" types --- src/factories/Entry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 444dcb3..19ab72a 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -168,7 +168,7 @@ public function inferTypeId(?int $sectionid): ?int $entryType = $entryTypes->where('id', $this->entryTypeIdentifier)->first(); } elseif (is_string($this->entryTypeIdentifier)) { $entryType = $entryTypes->where('handle', $this->entryTypeIdentifier)->first(); - } else { + } elseif ($sectionid) { $reflector = new \ReflectionClass($this); $className = $reflector->getShortName(); $typeHandle = lcfirst($className); From 30ed0f57e5a6eca5eb2278c0f3a8bcc8d4c7aaa6 Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 13:15:56 -0400 Subject: [PATCH 63/67] fixing improper null check --- src/factories/Entry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 19ab72a..f59d5b1 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -177,7 +177,7 @@ public function inferTypeId(?int $sectionid): ?int $entryTypes->first(); } - return $entryType?->id; + return $entryType->id ?? null; } /** From a7989d005170c2037a706d106ff37ecb13bff61c Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 13:37:41 -0400 Subject: [PATCH 64/67] using safeEmail instead of potentially real email addresses --- src/factories/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factories/User.php b/src/factories/User.php index 8ad3f39..f312064 100644 --- a/src/factories/User.php +++ b/src/factories/User.php @@ -14,7 +14,7 @@ public function newElement() public function definition(int $index = 0) { - $email = $this->faker->email(); + $email = $this->faker->safeEmail(); return [ 'email' => $email, From 6267702e7ae52475848dacb16ba4bc06fa2f9991 Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 13:45:10 -0400 Subject: [PATCH 65/67] update edition to fix user tests --- stubs/config/project-5/project.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/config/project-5/project.yaml b/stubs/config/project-5/project.yaml index 621b7d4..9f82c73 100644 --- a/stubs/config/project-5/project.yaml +++ b/stubs/config/project-5/project.yaml @@ -1,4 +1,4 @@ -dateModified: 1710967569 +dateModified: 1727718254 email: fromEmail: michael@bluth.com fromName: Pest @@ -29,7 +29,7 @@ meta: c148dfb3-a122-49ed-8538-de26d0482663: 'Entries Field' # Entries Field c7529b61-60cd-4e18-a272-3084aee7fa89: 'Matrix Field' # Matrix Field system: - edition: solo + edition: pro live: true name: Pest schemaVersion: 5.0.0.20 From 4757dbba9abefae9edce1386fd5a294144a831cb Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 13:54:51 -0400 Subject: [PATCH 66/67] update to pest 3 now with mutation testing... --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2fb9c81..75dcc3a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "symfony/css-selector": "^5.3|^6.0", "symfony/dom-crawler": "^6.0.3", "symfony/process": "^5.3|^6.0", - "pestphp/pest": "^2.26", + "pestphp/pest": "^3.0", "vlucas/phpdotenv": "^2.4|^3.4|^5.4", "craftcms/cms": "^4.5|^5.0.0-beta.1", "illuminate/support": "^9.52|^10.0|^11.0", From 4615a9f19bb0365dbbb54244c5a0a3c14e1265c5 Mon Sep 17 00:00:00 2001 From: markhuot Date: Mon, 30 Sep 2024 13:57:13 -0400 Subject: [PATCH 67/67] bumping to 8.3 --- .github/workflows/docs.yml | 4 ++++ .github/workflows/php.yml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3c012b0..441a54b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,6 +16,10 @@ jobs: with: ref: ${{ github.head_ref }} + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + - name: Validate composer.json and composer.lock run: composer validate --strict diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 319eaf0..8af361b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -62,7 +62,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.3' - name: Validate composer.json and composer.lock run: composer validate --strict