From a19c7bab045a98a33242d76f9721d78460e979ef Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 20 Aug 2025 17:06:09 +0200 Subject: [PATCH 1/3] Dont add fixtures if fixture factories are used. --- src/Command/TestCommand.php | 20 ++++++++++++++++++- src/Utility/SubsetSchemaCollection.php | 2 +- templates/bake/Model/entity.twig | 2 +- templates/bake/tests/test_case.twig | 4 ++-- tests/TestCase/Command/AllCommandTest.php | 4 ++-- .../Command/ControllerAllCommandTest.php | 4 ++-- .../Command/ControllerCommandTest.php | 2 +- .../Command/FixtureAllCommandTest.php | 4 ++-- tests/TestCase/Command/FixtureCommandTest.php | 2 +- .../TestCase/Command/ModelAllCommandTest.php | 4 ++-- .../ModelCommandAssociationDetectionTest.php | 2 +- tests/TestCase/Command/ModelCommandTest.php | 2 +- .../Command/TemplateAllCommandTest.php | 4 ++-- .../TestCase/Command/TemplateCommandTest.php | 2 +- tests/TestCase/TestCase.php | 2 +- .../Utility/Model/AssociationFilterTest.php | 2 +- tests/TestCase/Utility/TableScannerTest.php | 2 +- tests/TestCase/View/Helper/BakeHelperTest.php | 2 +- .../Model/testBakeEntityCustomHidden.php | 2 +- .../Model/testBakeEntityFullContext.php | 2 +- .../Model/testBakeEntityHidden.php | 2 +- .../Model/testBakeEntityWithPlugin.php | 2 +- .../Model/testBakeUpdateEntity.php | 2 +- .../Test/testBakeControllerTest.php | 2 +- .../Test/testBakeFixturesParam.php | 2 +- tests/comparisons/Test/testBakeModelTest.php | 2 +- .../Test/testBakePrefixControllerTest.php | 2 +- ...tBakePrefixControllerTestWithCliOption.php | 2 +- 28 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index bc3c42921..d9a23d523 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -242,8 +242,13 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo $prefix = $this->getPrefix($args); $fullClassName = $this->getRealClassName($type, $className, $prefix); + // Check if fixture factories plugin is available + $hasFixtureFactories = $this->hasFixtureFactories(); + if (!$args->getOption('no-fixture')) { - if ($args->getOption('fixtures')) { + if ($hasFixtureFactories) { + $io->info('Fixture Factories plugin detected - skipping fixture property generation.'); + } elseif ($args->getOption('fixtures')) { $fixtures = array_map('trim', explode(',', $args->getOption('fixtures'))); $this->_fixtures = array_filter($fixtures); } elseif ($this->typeCanDetectFixtures($type) && class_exists($fullClassName)) { @@ -277,6 +282,7 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo $contents = $this->createTemplateRenderer() ->set('fixtures', $this->_fixtures) ->set('plugin', $this->plugin) + ->set('hasFixtureFactories', $hasFixtureFactories) ->set(compact( 'subject', 'className', @@ -305,6 +311,18 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo return false; } + /** + * Check if the CakePHP Fixture Factories plugin is available + * + * @return bool + */ + protected function hasFixtureFactories(): bool + { + // Check if the CakephpFixtureFactories plugin class exists + return class_exists('CakephpFixtureFactories\Plugin') || + class_exists('CakephpFixtureFactories\CakephpFixtureFactoriesPlugin'); + } + /** * Checks whether the chosen type can find its own fixtures. * Currently only model, and controller are supported diff --git a/src/Utility/SubsetSchemaCollection.php b/src/Utility/SubsetSchemaCollection.php index 290332159..ca1b83524 100644 --- a/src/Utility/SubsetSchemaCollection.php +++ b/src/Utility/SubsetSchemaCollection.php @@ -33,7 +33,7 @@ class SubsetSchemaCollection implements CollectionInterface protected CollectionInterface $collection; /** - * @var list + * @var array */ protected array $tables = []; diff --git a/templates/bake/Model/entity.twig b/templates/bake/Model/entity.twig index 2524788ee..0885b7fca 100644 --- a/templates/bake/Model/entity.twig +++ b/templates/bake/Model/entity.twig @@ -59,7 +59,7 @@ class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implem /** * Fields that are excluded from JSON versions of the entity. * - * @var list + * @var array */ protected array $_hidden = {{ Bake.exportVar(hidden, 1)|raw }}; {% endif %} diff --git a/templates/bake/tests/test_case.twig b/templates/bake/tests/test_case.twig index 464f308b7..615a8ad95 100644 --- a/templates/bake/tests/test_case.twig +++ b/templates/bake/tests/test_case.twig @@ -63,11 +63,11 @@ class {{ className }}Test extends TestCase {% endfor %} {% endif %} -{%- if fixtures %} +{%- if fixtures and not (hasFixtureFactories|default(false)) %} /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = {{ Bake.exportVar(fixtures|values, 1)|raw }}; {% if construction or methods %} diff --git a/tests/TestCase/Command/AllCommandTest.php b/tests/TestCase/Command/AllCommandTest.php index 7e30df809..7aebae109 100644 --- a/tests/TestCase/Command/AllCommandTest.php +++ b/tests/TestCase/Command/AllCommandTest.php @@ -29,7 +29,7 @@ class AllCommandTest extends TestCase /** * fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Products', @@ -37,7 +37,7 @@ class AllCommandTest extends TestCase ]; /** - * @var list + * @var array */ protected array $tables = ['products', 'product_versions']; diff --git a/tests/TestCase/Command/ControllerAllCommandTest.php b/tests/TestCase/Command/ControllerAllCommandTest.php index 06428cbcc..d456cc029 100644 --- a/tests/TestCase/Command/ControllerAllCommandTest.php +++ b/tests/TestCase/Command/ControllerAllCommandTest.php @@ -30,7 +30,7 @@ class ControllerAllCommandTest extends TestCase /** * fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.BakeArticles', @@ -38,7 +38,7 @@ class ControllerAllCommandTest extends TestCase ]; /** - * @var list + * @var array */ protected array $tables = ['bake_articles', 'bake_comments']; diff --git a/tests/TestCase/Command/ControllerCommandTest.php b/tests/TestCase/Command/ControllerCommandTest.php index 2433bec57..ae6ec044d 100644 --- a/tests/TestCase/Command/ControllerCommandTest.php +++ b/tests/TestCase/Command/ControllerCommandTest.php @@ -32,7 +32,7 @@ class ControllerCommandTest extends TestCase /** * fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.BakeArticles', diff --git a/tests/TestCase/Command/FixtureAllCommandTest.php b/tests/TestCase/Command/FixtureAllCommandTest.php index 82883375e..735eba07c 100644 --- a/tests/TestCase/Command/FixtureAllCommandTest.php +++ b/tests/TestCase/Command/FixtureAllCommandTest.php @@ -30,7 +30,7 @@ class FixtureAllCommandTest extends TestCase /** * fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Articles', @@ -38,7 +38,7 @@ class FixtureAllCommandTest extends TestCase ]; /** - * @var list + * @var array */ protected array $tables = ['articles', 'comments']; diff --git a/tests/TestCase/Command/FixtureCommandTest.php b/tests/TestCase/Command/FixtureCommandTest.php index 94b996e60..a265731bd 100644 --- a/tests/TestCase/Command/FixtureCommandTest.php +++ b/tests/TestCase/Command/FixtureCommandTest.php @@ -35,7 +35,7 @@ class FixtureCommandTest extends TestCase /** * fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Articles', diff --git a/tests/TestCase/Command/ModelAllCommandTest.php b/tests/TestCase/Command/ModelAllCommandTest.php index 1ebb7c91e..768428dce 100644 --- a/tests/TestCase/Command/ModelAllCommandTest.php +++ b/tests/TestCase/Command/ModelAllCommandTest.php @@ -30,7 +30,7 @@ class ModelAllCommandTest extends TestCase /** * fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.TodoTasks', @@ -38,7 +38,7 @@ class ModelAllCommandTest extends TestCase ]; /** - * @var list + * @var array */ protected array $tables = ['todo_tasks', 'todo_items']; diff --git a/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php b/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php index b7725d5a4..80558cc80 100644 --- a/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php +++ b/tests/TestCase/Command/ModelCommandAssociationDetectionTest.php @@ -36,7 +36,7 @@ class ModelCommandAssociationDetectionTest extends TestCase * Don't sort this list alphabetically - otherwise there are table constraints * which fail when using postgres * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Categories', diff --git a/tests/TestCase/Command/ModelCommandTest.php b/tests/TestCase/Command/ModelCommandTest.php index 91cce3a30..fe2d14c98 100644 --- a/tests/TestCase/Command/ModelCommandTest.php +++ b/tests/TestCase/Command/ModelCommandTest.php @@ -44,7 +44,7 @@ class ModelCommandTest extends TestCase * Don't sort this list alphabetically - otherwise there are table constraints * which fail when using postgres * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Articles', diff --git a/tests/TestCase/Command/TemplateAllCommandTest.php b/tests/TestCase/Command/TemplateAllCommandTest.php index 34e06c98f..d8ce1c46f 100644 --- a/tests/TestCase/Command/TemplateAllCommandTest.php +++ b/tests/TestCase/Command/TemplateAllCommandTest.php @@ -30,7 +30,7 @@ class TemplateAllCommandTest extends TestCase /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Articles', @@ -38,7 +38,7 @@ class TemplateAllCommandTest extends TestCase ]; /** - * @var list + * @var array */ protected array $tables = ['articles', 'comments']; diff --git a/tests/TestCase/Command/TemplateCommandTest.php b/tests/TestCase/Command/TemplateCommandTest.php index cd99d0bba..e730bf0d4 100644 --- a/tests/TestCase/Command/TemplateCommandTest.php +++ b/tests/TestCase/Command/TemplateCommandTest.php @@ -39,7 +39,7 @@ class TemplateCommandTest extends TestCase /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Articles', diff --git a/tests/TestCase/TestCase.php b/tests/TestCase/TestCase.php index bc12e03b3..32b8b15d5 100644 --- a/tests/TestCase/TestCase.php +++ b/tests/TestCase/TestCase.php @@ -32,7 +32,7 @@ abstract class TestCase extends BaseTestCase protected $generatedFile = ''; /** - * @var list + * @var array */ protected $generatedFiles = []; diff --git a/tests/TestCase/Utility/Model/AssociationFilterTest.php b/tests/TestCase/Utility/Model/AssociationFilterTest.php index d36359c77..d87c97f50 100644 --- a/tests/TestCase/Utility/Model/AssociationFilterTest.php +++ b/tests/TestCase/Utility/Model/AssociationFilterTest.php @@ -30,7 +30,7 @@ class AssociationFilterTest extends TestCase * Don't sort this list alphabetically - otherwise there are table constraints * which fail when using postgres * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.Authors', diff --git a/tests/TestCase/Utility/TableScannerTest.php b/tests/TestCase/Utility/TableScannerTest.php index 4591032e4..ab14bec0e 100644 --- a/tests/TestCase/Utility/TableScannerTest.php +++ b/tests/TestCase/Utility/TableScannerTest.php @@ -23,7 +23,7 @@ class TableScannerTest extends TestCase { /** - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.TodoTasks', diff --git a/tests/TestCase/View/Helper/BakeHelperTest.php b/tests/TestCase/View/Helper/BakeHelperTest.php index 5155a938e..a0bafee60 100644 --- a/tests/TestCase/View/Helper/BakeHelperTest.php +++ b/tests/TestCase/View/Helper/BakeHelperTest.php @@ -33,7 +33,7 @@ class BakeHelperTest extends TestCase * Don't sort this list alphabetically - otherwise there are table constraints * which fail when using postgres * - * @var list + * @var array */ protected array $fixtures = [ 'plugin.Bake.BakeArticles', diff --git a/tests/comparisons/Model/testBakeEntityCustomHidden.php b/tests/comparisons/Model/testBakeEntityCustomHidden.php index 8ca1a19ef..cce168ac3 100644 --- a/tests/comparisons/Model/testBakeEntityCustomHidden.php +++ b/tests/comparisons/Model/testBakeEntityCustomHidden.php @@ -23,7 +23,7 @@ class User extends Entity /** * Fields that are excluded from JSON versions of the entity. * - * @var list + * @var array */ protected array $_hidden = [ 'foo', diff --git a/tests/comparisons/Model/testBakeEntityFullContext.php b/tests/comparisons/Model/testBakeEntityFullContext.php index 4a4388eae..1229c8bfb 100644 --- a/tests/comparisons/Model/testBakeEntityFullContext.php +++ b/tests/comparisons/Model/testBakeEntityFullContext.php @@ -42,7 +42,7 @@ class User extends Entity /** * Fields that are excluded from JSON versions of the entity. * - * @var list + * @var array */ protected array $_hidden = [ 'password', diff --git a/tests/comparisons/Model/testBakeEntityHidden.php b/tests/comparisons/Model/testBakeEntityHidden.php index fe51ce0cd..602b70721 100644 --- a/tests/comparisons/Model/testBakeEntityHidden.php +++ b/tests/comparisons/Model/testBakeEntityHidden.php @@ -23,7 +23,7 @@ class User extends Entity /** * Fields that are excluded from JSON versions of the entity. * - * @var list + * @var array */ protected array $_hidden = [ 'password', diff --git a/tests/comparisons/Model/testBakeEntityWithPlugin.php b/tests/comparisons/Model/testBakeEntityWithPlugin.php index a9efefbe1..d7139c3c3 100644 --- a/tests/comparisons/Model/testBakeEntityWithPlugin.php +++ b/tests/comparisons/Model/testBakeEntityWithPlugin.php @@ -42,7 +42,7 @@ class User extends Entity /** * Fields that are excluded from JSON versions of the entity. * - * @var list + * @var array */ protected array $_hidden = [ 'password', diff --git a/tests/comparisons/Model/testBakeUpdateEntity.php b/tests/comparisons/Model/testBakeUpdateEntity.php index e2ed113a7..f9d673f98 100644 --- a/tests/comparisons/Model/testBakeUpdateEntity.php +++ b/tests/comparisons/Model/testBakeUpdateEntity.php @@ -35,7 +35,7 @@ class TodoItem extends Entity implements IdentityInterface /** * Fields that are excluded from JSON versions of the entity. * - * @var list + * @var array */ protected array $_hidden = [ 'user_id', diff --git a/tests/comparisons/Test/testBakeControllerTest.php b/tests/comparisons/Test/testBakeControllerTest.php index 73c457616..8fd6d5a30 100644 --- a/tests/comparisons/Test/testBakeControllerTest.php +++ b/tests/comparisons/Test/testBakeControllerTest.php @@ -19,7 +19,7 @@ class PostsControllerTest extends TestCase /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'app.Posts', diff --git a/tests/comparisons/Test/testBakeFixturesParam.php b/tests/comparisons/Test/testBakeFixturesParam.php index e78cb54c2..8b34120df 100644 --- a/tests/comparisons/Test/testBakeFixturesParam.php +++ b/tests/comparisons/Test/testBakeFixturesParam.php @@ -21,7 +21,7 @@ class AuthorsTableTest extends TestCase /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'app.Posts', diff --git a/tests/comparisons/Test/testBakeModelTest.php b/tests/comparisons/Test/testBakeModelTest.php index 1f5d6a980..07589c1fb 100644 --- a/tests/comparisons/Test/testBakeModelTest.php +++ b/tests/comparisons/Test/testBakeModelTest.php @@ -21,7 +21,7 @@ class ArticlesTableTest extends TestCase /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'app.Articles', diff --git a/tests/comparisons/Test/testBakePrefixControllerTest.php b/tests/comparisons/Test/testBakePrefixControllerTest.php index 5c464445b..7056f1f41 100644 --- a/tests/comparisons/Test/testBakePrefixControllerTest.php +++ b/tests/comparisons/Test/testBakePrefixControllerTest.php @@ -19,7 +19,7 @@ class PostsControllerTest extends TestCase /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'app.Posts', diff --git a/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php b/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php index 5c464445b..7056f1f41 100644 --- a/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php +++ b/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php @@ -19,7 +19,7 @@ class PostsControllerTest extends TestCase /** * Fixtures * - * @var list + * @var array */ protected array $fixtures = [ 'app.Posts', From b5a2eb6715a7f55ecd334f719410d414970d319a Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 20 Aug 2025 17:18:20 +0200 Subject: [PATCH 2/3] Fix CS --- src/Command/TestCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index d9a23d523..51185e578 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -244,7 +244,7 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo // Check if fixture factories plugin is available $hasFixtureFactories = $this->hasFixtureFactories(); - + if (!$args->getOption('no-fixture')) { if ($hasFixtureFactories) { $io->info('Fixture Factories plugin detected - skipping fixture property generation.'); From eab420ab93d99cf4d97924e4ba1b31b4c517f586 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 20 Aug 2025 17:20:07 +0200 Subject: [PATCH 3/3] Fix CS --- src/Command/TestCommand.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index 51185e578..be2c4c283 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -318,9 +318,8 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo */ protected function hasFixtureFactories(): bool { - // Check if the CakephpFixtureFactories plugin class exists - return class_exists('CakephpFixtureFactories\Plugin') || - class_exists('CakephpFixtureFactories\CakephpFixtureFactoriesPlugin'); + return class_exists('CakephpFixtureFactories\Plugin') + || class_exists('CakephpFixtureFactories\CakephpFixtureFactoriesPlugin'); } /**