Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -305,6 +311,17 @@ 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
{
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
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/SubsetSchemaCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SubsetSchemaCollection implements CollectionInterface
protected CollectionInterface $collection;

/**
* @var list<string>
* @var array<string>
*/
protected array $tables = [];

Expand Down
2 changes: 1 addition & 1 deletion templates/bake/Model/entity.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implem
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var list<string>
* @var array<string>
*/
protected array $_hidden = {{ Bake.exportVar(hidden, 1)|raw }};
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/bake/tests/test_case.twig
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class {{ className }}Test extends TestCase
{% endfor %}
{% endif %}

{%- if fixtures %}
{%- if fixtures and not (hasFixtureFactories|default(false)) %}
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = {{ Bake.exportVar(fixtures|values, 1)|raw }};
{% if construction or methods %}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/AllCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class AllCommandTest extends TestCase
/**
* fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Products',
'plugin.Bake.ProductVersions',
];

/**
* @var list<string>
* @var array<string>
*/
protected array $tables = ['products', 'product_versions'];

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/ControllerAllCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class ControllerAllCommandTest extends TestCase
/**
* fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.BakeArticles',
'plugin.Bake.BakeComments',
];

/**
* @var list<string>
* @var array<string>
*/
protected array $tables = ['bake_articles', 'bake_comments'];

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/ControllerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ControllerCommandTest extends TestCase
/**
* fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.BakeArticles',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/FixtureAllCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class FixtureAllCommandTest extends TestCase
/**
* fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Articles',
'plugin.Bake.Comments',
];

/**
* @var list<string>
* @var array<string>
*/
protected array $tables = ['articles', 'comments'];

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/FixtureCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FixtureCommandTest extends TestCase
/**
* fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Articles',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/ModelAllCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class ModelAllCommandTest extends TestCase
/**
* fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.TodoTasks',
'plugin.Bake.TodoItems',
];

/**
* @var list<string>
* @var array<string>
*/
protected array $tables = ['todo_tasks', 'todo_items'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Categories',
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/ModelCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Articles',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/TemplateAllCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class TemplateAllCommandTest extends TestCase
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Articles',
'plugin.Bake.Comments',
];

/**
* @var list<string>
* @var array<string>
*/
protected array $tables = ['articles', 'comments'];

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/TemplateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TemplateCommandTest extends TestCase
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Articles',
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class TestCase extends BaseTestCase
protected $generatedFile = '';

/**
* @var list<string>
* @var array<string>
*/
protected $generatedFiles = [];

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Utility/Model/AssociationFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Authors',
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Utility/TableScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class TableScannerTest extends TestCase
{
/**
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.TodoTasks',
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/BakeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.BakeArticles',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeEntityCustomHidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class User extends Entity
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var list<string>
* @var array<string>
*/
protected array $_hidden = [
'foo',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeEntityFullContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class User extends Entity
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var list<string>
* @var array<string>
*/
protected array $_hidden = [
'password',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeEntityHidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class User extends Entity
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var list<string>
* @var array<string>
*/
protected array $_hidden = [
'password',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeEntityWithPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class User extends Entity
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var list<string>
* @var array<string>
*/
protected array $_hidden = [
'password',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Model/testBakeUpdateEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TodoItem extends Entity implements IdentityInterface
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var list<string>
* @var array<string>
*/
protected array $_hidden = [
'user_id',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Test/testBakeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PostsControllerTest extends TestCase
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'app.Posts',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Test/testBakeFixturesParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AuthorsTableTest extends TestCase
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'app.Posts',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Test/testBakeModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ArticlesTableTest extends TestCase
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'app.Articles',
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Test/testBakePrefixControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PostsControllerTest extends TestCase
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'app.Posts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PostsControllerTest extends TestCase
/**
* Fixtures
*
* @var list<string>
* @var array<string>
*/
protected array $fixtures = [
'app.Posts',
Expand Down