From c3070a24721d664856cfd6f02390e1223293565d Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Mon, 12 Oct 2026 20:18:21 +0200 Subject: [PATCH] Use CakePHP 6 property and method names in templates The form template still generated `_buildSchema()` and `_execute()`, which are never called in CakePHP 6 (`buildSchema()` and `process()`). The component, behavior and helper templates still declared `$_defaultConfig`, which is ignored now that it is named `$defaultConfig`. --- templates/bake/Command/helper.twig | 2 +- templates/bake/Controller/component.twig | 2 +- templates/bake/Form/form.twig | 4 ++-- templates/bake/Model/behavior.twig | 2 +- templates/bake/View/helper.twig | 2 +- tests/TestCase/Command/FormCommandTest.php | 2 ++ tests/comparisons/Command/testBakeCommandHelper.php | 2 +- tests/comparisons/Command/testBakeCommandHelperPlugin.php | 2 +- tests/comparisons/Plugin/Simple/testBake.php | 2 +- tests/comparisons/Plugin/Simple/testBakePlugin.php | 2 +- 10 files changed, 12 insertions(+), 10 deletions(-) diff --git a/templates/bake/Command/helper.twig b/templates/bake/Command/helper.twig index 94781585f..a455d325d 100644 --- a/templates/bake/Command/helper.twig +++ b/templates/bake/Command/helper.twig @@ -26,7 +26,7 @@ class {{ name }}Helper extends Helper { /** - * This method should output content using `$this->_io`. + * This method should output content using `$this->io`. * * @param array $args The arguments for the helper. * @return void diff --git a/templates/bake/Controller/component.twig b/templates/bake/Controller/component.twig index f7861b8da..f2e52b123 100644 --- a/templates/bake/Controller/component.twig +++ b/templates/bake/Controller/component.twig @@ -31,5 +31,5 @@ class {{ name }}Component extends Component * * @var array */ - protected array $_defaultConfig = []; + protected array $defaultConfig = []; } diff --git a/templates/bake/Form/form.twig b/templates/bake/Form/form.twig index 5f8c64de6..e3c66c032 100644 --- a/templates/bake/Form/form.twig +++ b/templates/bake/Form/form.twig @@ -33,7 +33,7 @@ class {{ name }}Form extends Form * @param \Cake\Form\Schema $schema From schema * @return \Cake\Form\Schema */ - protected function _buildSchema(Schema $schema): Schema + protected function buildSchema(Schema $schema): Schema { return $schema; } @@ -55,7 +55,7 @@ class {{ name }}Form extends Form * @param array $data Form data. * @return bool */ - protected function _execute(array $data): bool + protected function process(array $data): bool { return true; } diff --git a/templates/bake/Model/behavior.twig b/templates/bake/Model/behavior.twig index c314e7f96..88d16a364 100644 --- a/templates/bake/Model/behavior.twig +++ b/templates/bake/Model/behavior.twig @@ -31,5 +31,5 @@ class {{ name }}Behavior extends Behavior * * @var array */ - protected array $_defaultConfig = []; + protected array $defaultConfig = []; } diff --git a/templates/bake/View/helper.twig b/templates/bake/View/helper.twig index e47adae6e..bd2e42ac6 100644 --- a/templates/bake/View/helper.twig +++ b/templates/bake/View/helper.twig @@ -31,5 +31,5 @@ class {{ name }}Helper extends Helper * * @var array */ - protected array $_defaultConfig = []; + protected array $defaultConfig = []; } diff --git a/tests/TestCase/Command/FormCommandTest.php b/tests/TestCase/Command/FormCommandTest.php index cf642614c..7b0451ffd 100644 --- a/tests/TestCase/Command/FormCommandTest.php +++ b/tests/TestCase/Command/FormCommandTest.php @@ -51,5 +51,7 @@ public function testCommand(): void $this->assertExitCode(CommandInterface::CODE_SUCCESS); $this->assertFilesExist($this->generatedFiles); $this->assertFileContains('class TestForm extends Form', $this->generatedFiles[0]); + $this->assertFileContains('protected function buildSchema(Schema $schema): Schema', $this->generatedFiles[0]); + $this->assertFileContains('protected function process(array $data): bool', $this->generatedFiles[0]); } } diff --git a/tests/comparisons/Command/testBakeCommandHelper.php b/tests/comparisons/Command/testBakeCommandHelper.php index 12aae49ab..11fa48106 100644 --- a/tests/comparisons/Command/testBakeCommandHelper.php +++ b/tests/comparisons/Command/testBakeCommandHelper.php @@ -11,7 +11,7 @@ class ErrorHelper extends Helper { /** - * This method should output content using `$this->_io`. + * This method should output content using `$this->io`. * * @param array $args The arguments for the helper. * @return void diff --git a/tests/comparisons/Command/testBakeCommandHelperPlugin.php b/tests/comparisons/Command/testBakeCommandHelperPlugin.php index 33381e070..81cc7483d 100644 --- a/tests/comparisons/Command/testBakeCommandHelperPlugin.php +++ b/tests/comparisons/Command/testBakeCommandHelperPlugin.php @@ -11,7 +11,7 @@ class ErrorHelper extends Helper { /** - * This method should output content using `$this->_io`. + * This method should output content using `$this->io`. * * @param array $args The arguments for the helper. * @return void diff --git a/tests/comparisons/Plugin/Simple/testBake.php b/tests/comparisons/Plugin/Simple/testBake.php index bd4dbf0ed..a5174de84 100644 --- a/tests/comparisons/Plugin/Simple/testBake.php +++ b/tests/comparisons/Plugin/Simple/testBake.php @@ -16,5 +16,5 @@ class ExampleBehavior extends Behavior * * @var array */ - protected array $_defaultConfig = []; + protected array $defaultConfig = []; } diff --git a/tests/comparisons/Plugin/Simple/testBakePlugin.php b/tests/comparisons/Plugin/Simple/testBakePlugin.php index 99b4e6408..55d58cbf8 100644 --- a/tests/comparisons/Plugin/Simple/testBakePlugin.php +++ b/tests/comparisons/Plugin/Simple/testBakePlugin.php @@ -16,5 +16,5 @@ class ExampleBehavior extends Behavior * * @var array */ - protected array $_defaultConfig = []; + protected array $defaultConfig = []; }