Skip to content

Commit 88a6118

Browse files
authored
Merge pull request #1052 from cakephp/3.x-fixture-factories
Dont add fixtures if fixture factories are used.
2 parents 5bcb261 + eab420a commit 88a6118

28 files changed

+51
-34
lines changed

src/Command/TestCommand.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,13 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo
242242
$prefix = $this->getPrefix($args);
243243
$fullClassName = $this->getRealClassName($type, $className, $prefix);
244244

245+
// Check if fixture factories plugin is available
246+
$hasFixtureFactories = $this->hasFixtureFactories();
247+
245248
if (!$args->getOption('no-fixture')) {
246-
if ($args->getOption('fixtures')) {
249+
if ($hasFixtureFactories) {
250+
$io->info('Fixture Factories plugin detected - skipping fixture property generation.');
251+
} elseif ($args->getOption('fixtures')) {
247252
$fixtures = array_map('trim', explode(',', $args->getOption('fixtures')));
248253
$this->_fixtures = array_filter($fixtures);
249254
} elseif ($this->typeCanDetectFixtures($type) && class_exists($fullClassName)) {
@@ -277,6 +282,7 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo
277282
$contents = $this->createTemplateRenderer()
278283
->set('fixtures', $this->_fixtures)
279284
->set('plugin', $this->plugin)
285+
->set('hasFixtureFactories', $hasFixtureFactories)
280286
->set(compact(
281287
'subject',
282288
'className',
@@ -305,6 +311,17 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo
305311
return false;
306312
}
307313

314+
/**
315+
* Check if the CakePHP Fixture Factories plugin is available
316+
*
317+
* @return bool
318+
*/
319+
protected function hasFixtureFactories(): bool
320+
{
321+
return class_exists('CakephpFixtureFactories\Plugin')
322+
|| class_exists('CakephpFixtureFactories\CakephpFixtureFactoriesPlugin');
323+
}
324+
308325
/**
309326
* Checks whether the chosen type can find its own fixtures.
310327
* Currently only model, and controller are supported

src/Utility/SubsetSchemaCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SubsetSchemaCollection implements CollectionInterface
3333
protected CollectionInterface $collection;
3434

3535
/**
36-
* @var list<string>
36+
* @var array<string>
3737
*/
3838
protected array $tables = [];
3939

templates/bake/Model/entity.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implem
5959
/**
6060
* Fields that are excluded from JSON versions of the entity.
6161
*
62-
* @var list<string>
62+
* @var array<string>
6363
*/
6464
protected array $_hidden = {{ Bake.exportVar(hidden, 1)|raw }};
6565
{% endif %}

templates/bake/tests/test_case.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ class {{ className }}Test extends TestCase
6363
{% endfor %}
6464
{% endif %}
6565

66-
{%- if fixtures %}
66+
{%- if fixtures and not (hasFixtureFactories|default(false)) %}
6767
/**
6868
* Fixtures
6969
*
70-
* @var list<string>
70+
* @var array<string>
7171
*/
7272
protected array $fixtures = {{ Bake.exportVar(fixtures|values, 1)|raw }};
7373
{% if construction or methods %}

tests/TestCase/Command/AllCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class AllCommandTest extends TestCase
2929
/**
3030
* fixtures
3131
*
32-
* @var list<string>
32+
* @var array<string>
3333
*/
3434
protected array $fixtures = [
3535
'plugin.Bake.Products',
3636
'plugin.Bake.ProductVersions',
3737
];
3838

3939
/**
40-
* @var list<string>
40+
* @var array<string>
4141
*/
4242
protected array $tables = ['products', 'product_versions'];
4343

tests/TestCase/Command/ControllerAllCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class ControllerAllCommandTest extends TestCase
3030
/**
3131
* fixtures
3232
*
33-
* @var list<string>
33+
* @var array<string>
3434
*/
3535
protected array $fixtures = [
3636
'plugin.Bake.BakeArticles',
3737
'plugin.Bake.BakeComments',
3838
];
3939

4040
/**
41-
* @var list<string>
41+
* @var array<string>
4242
*/
4343
protected array $tables = ['bake_articles', 'bake_comments'];
4444

tests/TestCase/Command/ControllerCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ControllerCommandTest extends TestCase
3232
/**
3333
* fixtures
3434
*
35-
* @var list<string>
35+
* @var array<string>
3636
*/
3737
protected array $fixtures = [
3838
'plugin.Bake.BakeArticles',

tests/TestCase/Command/FixtureAllCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class FixtureAllCommandTest extends TestCase
3030
/**
3131
* fixtures
3232
*
33-
* @var list<string>
33+
* @var array<string>
3434
*/
3535
protected array $fixtures = [
3636
'plugin.Bake.Articles',
3737
'plugin.Bake.Comments',
3838
];
3939

4040
/**
41-
* @var list<string>
41+
* @var array<string>
4242
*/
4343
protected array $tables = ['articles', 'comments'];
4444

tests/TestCase/Command/FixtureCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FixtureCommandTest extends TestCase
3535
/**
3636
* fixtures
3737
*
38-
* @var list<string>
38+
* @var array<string>
3939
*/
4040
protected array $fixtures = [
4141
'plugin.Bake.Articles',

tests/TestCase/Command/ModelAllCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class ModelAllCommandTest extends TestCase
3030
/**
3131
* fixtures
3232
*
33-
* @var list<string>
33+
* @var array<string>
3434
*/
3535
protected array $fixtures = [
3636
'plugin.Bake.TodoTasks',
3737
'plugin.Bake.TodoItems',
3838
];
3939

4040
/**
41-
* @var list<string>
41+
* @var array<string>
4242
*/
4343
protected array $tables = ['todo_tasks', 'todo_items'];
4444

0 commit comments

Comments
 (0)