diff --git a/composer.json b/composer.json index c105201f..f7a4a2d0 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,14 @@ "require": { "php": ">=8.1", "brick/varexporter": "^0.5.0", - "cakephp/cakephp": "^5.0.3", + "cakephp/cakephp": "dev-5.next as 5.1.0", "cakephp/twig-view": "^2.0.0", "nikic/php-parser": "^5.0.0" }, "require-dev": { "cakephp/cakephp-codesniffer": "^5.0.0", "cakephp/debug_kit": "^5.0.0", - "phpunit/phpunit": "^10.1.0" + "phpunit/phpunit": "^10.5.5 || ^11.1.3" }, "autoload": { "psr-4": { diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index dfd50d19..34eeeeeb 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -111,7 +111,8 @@ public function execute(Arguments $args, ConsoleIo $io): ?int } foreach ($tables as $table) { - $subArgs = new Arguments([$table], $options, ['name']); + $parser = $command->getOptionParser(); + $subArgs = new Arguments([$table], $options, $parser->argumentNames()); $command->execute($subArgs, $io); } } diff --git a/src/Command/TemplateAllCommand.php b/src/Command/TemplateAllCommand.php index 6253e1af..4be17e5b 100644 --- a/src/Command/TemplateAllCommand.php +++ b/src/Command/TemplateAllCommand.php @@ -66,7 +66,13 @@ public function execute(Arguments $args, ConsoleIo $io): int $scanner = new TableScanner($connection); foreach ($scanner->listUnskipped() as $table) { - $templateArgs = new Arguments([$table], $args->getOptions(), ['name']); + $parser = $this->templateCommand->getOptionParser(); + $templateArgs = new Arguments( + [$table], + $args->getOptions(), + $parser->argumentNames() + ); + $this->templateCommand->execute($templateArgs, $io); } diff --git a/src/View/BakeView.php b/src/View/BakeView.php index 31f0a95a..84186543 100644 --- a/src/View/BakeView.php +++ b/src/View/BakeView.php @@ -128,7 +128,7 @@ public function dispatchEvent(string $name, array $data = [], ?object $subject = * * @param ?string $plugin Optional plugin name to scan for view files. * @param bool $cached Set to false to force a refresh of view paths. Default true. - * @return array paths + * @return list paths */ protected function _paths(?string $plugin = null, bool $cached = true): array { diff --git a/tests/TestCase/Command/ControllerCommandTest.php b/tests/TestCase/Command/ControllerCommandTest.php index 547e7309..6aa597f6 100644 --- a/tests/TestCase/Command/ControllerCommandTest.php +++ b/tests/TestCase/Command/ControllerCommandTest.php @@ -22,6 +22,7 @@ use Cake\Console\Arguments; use Cake\Console\CommandInterface; use Cake\Core\Plugin; +use PHPUnit\Framework\Attributes\DataProvider; /** * ControllerCommand Test @@ -380,9 +381,9 @@ public static function nameVariations() /** * test that both plural and singular forms work for controller baking. * - * @dataProvider nameVariations * @return void */ + #[DataProvider('nameVariations')] public function testMainWithControllerNameVariations($name) { $this->generatedFile = APP . 'Controller/BakeArticlesController.php'; diff --git a/tests/TestCase/Command/ModelCommandTest.php b/tests/TestCase/Command/ModelCommandTest.php index 0a97ae0c..c63f5496 100644 --- a/tests/TestCase/Command/ModelCommandTest.php +++ b/tests/TestCase/Command/ModelCommandTest.php @@ -31,6 +31,7 @@ use Cake\Database\Driver\Sqlite; use Cake\Database\Driver\Sqlserver; use Cake\Datasource\ConnectionManager; +use PHPUnit\Framework\Attributes\DataProvider; /** * ModelCommand test class @@ -1971,8 +1972,13 @@ public function testBakeEntityFullContext() public function testBakeEntityWithPropertyTypeHints() { $model = $this->getTableLocator()->get('TodoItems'); + $model->associations()->removeAll(); + $model->belongsTo('Users'); + $model->hasOne('TodoReminders'); $model->hasMany('BakeTest.TodoTasks'); + $model->hasMany('TodoLabels'); + $model->getSchema()->addColumn('array_type', [ 'type' => 'array', ]); @@ -2383,9 +2389,9 @@ public static function nameVariations() /** * test that execute passes with different inflections of the same name. * - * @dataProvider nameVariations * @return void */ + #[DataProvider('nameVariations')] public function testMainWithNamedModelVariations($name) { $this->generatedFiles = [ diff --git a/tests/TestCase/Command/SimpleBakeCommandTest.php b/tests/TestCase/Command/SimpleBakeCommandTest.php index c4fd4c1a..1475e8cc 100644 --- a/tests/TestCase/Command/SimpleBakeCommandTest.php +++ b/tests/TestCase/Command/SimpleBakeCommandTest.php @@ -19,6 +19,7 @@ use Bake\Test\TestCase\TestCase; use Cake\Console\CommandInterface; use Cake\Core\Plugin; +use PHPUnit\Framework\Attributes\DataProvider; /** * SimpleBakeCommandTest class @@ -148,6 +149,7 @@ public static function subclassProvider() * @dataProvider subclassProvider * @return void */ + #[DataProvider('subclassProvider')] public function testImplementations($class) { $task = new $class(); diff --git a/tests/TestCase/Command/TemplateCommandTest.php b/tests/TestCase/Command/TemplateCommandTest.php index 7c0e47b0..f77f22a0 100644 --- a/tests/TestCase/Command/TemplateCommandTest.php +++ b/tests/TestCase/Command/TemplateCommandTest.php @@ -29,6 +29,7 @@ use Cake\Core\Plugin; use Cake\Database\Type\EnumType; use Cake\View\Exception\MissingTemplateException; +use PHPUnit\Framework\Attributes\DataProvider; /** * TemplateCommand test @@ -106,9 +107,9 @@ public function testController() * Test the controller() method. * * @param string $name - * @dataProvider nameVariations * @return void */ + #[DataProvider('nameVariations')] public function testControllerVariations($name) { $command = new TemplateCommand(); @@ -482,7 +483,7 @@ public function testBakeViewEnum() public function testBakeViewEnumNoLabel() { $table = $this->fetchTable('Articles'); - $table->getSchema()->setColumnType('status', EnumType::from(ArticleStatus::class)); + $table->getSchema()->setColumnType('published', EnumType::from(ArticleStatus::class)); $this->generatedFile = ROOT . 'templates/Articles/view.php'; $this->exec('bake template articles view'); @@ -624,7 +625,7 @@ public function testBakeIndexWithEnumWithLabel() public function testBakeIndexWithEnumNoLabel() { $table = $this->fetchTable('Articles'); - $table->getSchema()->setColumnType('status', EnumType::from(ArticleStatus::class)); + $table->getSchema()->setColumnType('published', EnumType::from(ArticleStatus::class)); $this->generatedFile = ROOT . 'templates/Articles/index.php'; $this->exec('bake template articles index'); diff --git a/tests/TestCase/Command/TestCommandTest.php b/tests/TestCase/Command/TestCommandTest.php index 3aa6ea9a..59533f65 100644 --- a/tests/TestCase/Command/TestCommandTest.php +++ b/tests/TestCase/Command/TestCommandTest.php @@ -24,6 +24,7 @@ use Cake\Console\CommandInterface; use Cake\Core\Plugin; use Cake\Http\ServerRequest as Request; +use PHPUnit\Framework\Attributes\DataProvider; /** * TestCommandTest class @@ -291,9 +292,9 @@ public static function realClassProvider() /** * test that resolving class names works * - * @dataProvider realClassProvider * @return void */ + #[DataProvider('realClassProvider')] public function testGetRealClassname($type, $name, $expected) { $this->setAppNamespace('App'); @@ -659,9 +660,9 @@ public static function caseFileNameProvider() /** * Test filename generation for each type + plugins * - * @dataProvider caseFileNameProvider * @return void */ + #[DataProvider('caseFileNameProvider')] public function testTestCaseFileName($type, $class, $expected) { $this->setAppNamespace('App'); @@ -712,9 +713,9 @@ public static function mapTypeProvider() /** * Test that mapType returns the correct package names. * - * @dataProvider mapTypeProvider * @return void */ + #[DataProvider('mapTypeProvider')] public function testMapType($original, $expected) { $command = new TestCommand(); diff --git a/tests/TestCase/PluginTest.php b/tests/TestCase/PluginTest.php index 397fe5fe..fb6ab69b 100644 --- a/tests/TestCase/PluginTest.php +++ b/tests/TestCase/PluginTest.php @@ -18,6 +18,7 @@ use Bake\BakePlugin; use Cake\Console\CommandCollection; +use Cake\Core\Plugin; use Cake\Routing\RouteBuilder; use Cake\Routing\RouteCollection; @@ -44,6 +45,7 @@ public function testRoutes() public function testConsoleDiscoverBakeCommands() { + Plugin::getCollection()->add(new BakePlugin()); $commands = new CommandCollection(); $plugin = new BakePlugin(); $commands = $plugin->console($commands); diff --git a/tests/TestCase/TestCase.php b/tests/TestCase/TestCase.php index a2844d68..bc12e03b 100644 --- a/tests/TestCase/TestCase.php +++ b/tests/TestCase/TestCase.php @@ -67,18 +67,25 @@ public function tearDown(): void * Load a plugin from the tests folder, and add to the autoloader * * @param string $name plugin name to load + * @param bool $loadBake Whether or not to load the Bake plugin as well. * @return void */ - protected function _loadTestPlugin($name) + protected function _loadTestPlugin(string $name, bool $loadBake = false): void { $root = dirname(dirname(__FILE__)) . DS; $path = $root . 'test_app' . DS . 'Plugin' . DS . $name . DS; - $this->loadPlugins([ + $plugins = [ $name => [ 'path' => $path, ], - ]); + ]; + + if ($loadBake) { + $plugins[] = 'Bake'; + } + + $this->loadPlugins($plugins); } /** diff --git a/tests/TestCase/Utility/TemplateRendererTest.php b/tests/TestCase/Utility/TemplateRendererTest.php index 5194cdf2..05807740 100644 --- a/tests/TestCase/Utility/TemplateRendererTest.php +++ b/tests/TestCase/Utility/TemplateRendererTest.php @@ -72,7 +72,7 @@ public function testGenerate() */ public function testGenerateWithTemplateOverride() { - $this->_loadTestPlugin('TestBakeTheme'); + $this->_loadTestPlugin('TestBakeTheme', true); $renderer = new TemplateRenderer('TestBakeTheme'); $renderer->set([ 'plugin' => 'Special', @@ -89,7 +89,7 @@ public function testGenerateWithTemplateOverride() */ public function testGenerateWithTemplateFallbacks() { - $this->_loadTestPlugin('TestBakeTheme'); + $this->_loadTestPlugin('TestBakeTheme', true); $renderer = new TemplateRenderer('TestBakeTheme'); $renderer->set([ 'name' => 'Articles', diff --git a/tests/TestCase/View/Helper/DocBlockHelperTest.php b/tests/TestCase/View/Helper/DocBlockHelperTest.php index 57ac5425..a2c692ab 100644 --- a/tests/TestCase/View/Helper/DocBlockHelperTest.php +++ b/tests/TestCase/View/Helper/DocBlockHelperTest.php @@ -26,12 +26,12 @@ use Cake\ORM\Association\HasMany; use Cake\ORM\Association\HasOne; use Cake\TestSuite\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; /** * DocBlockHelper Test - * - * @coversDefaultClass \Bake\View\Helper\DocBlockHelper */ +#[CoversClass(DocBlockHelper::class)] class DocBlockHelperTest extends TestCase { /** @@ -74,7 +74,6 @@ public function tearDown(): void * Tests the classDescription method including annotation spacing * * @return void - * @covers ::classDescription */ public function testClassDescription() { @@ -94,7 +93,6 @@ public function testClassDescription() * Tests the associatedEntityTypeToHintType method * * @return void - * @covers ::associatedEntityTypeToHintType */ public function testAssociatedEntityTypeToHintType() { @@ -198,8 +196,6 @@ public function testBuildEntityPropertyHintTypeMap() * Tests the buildEntityAssociationHintTypeMap method * * @return void - * @covers ::buildEntityAssociationHintTypeMap - * @covers ::_insertAfter */ public function testBuildEntityAssociationHintTypeMap() { @@ -210,7 +206,6 @@ public function testBuildEntityAssociationHintTypeMap() * Tests the columnTypeToHintType method * * @return void - * @covers ::columnTypeToHintType */ public function testColumnTypeToHintType() { @@ -221,7 +216,6 @@ public function testColumnTypeToHintType() * Tests the propertyHints method * * @return void - * @covers ::propertyHints */ public function testPropertyHints() { @@ -232,7 +226,6 @@ public function testPropertyHints() * Tests the buildTableAnnotations method * * @return void - * @covers ::buildTableAnnotations */ public function testBuildTableAnnotations() { diff --git a/tests/test_app/App/Controller/UsersController.php b/tests/test_app/App/Controller/UsersController.php index 3435d632..2663a906 100644 --- a/tests/test_app/App/Controller/UsersController.php +++ b/tests/test_app/App/Controller/UsersController.php @@ -31,10 +31,7 @@ public function index() */ public function view($id = null) { - $user = $this->Users->get($id, [ - 'contain' => [], - ]); - + $user = $this->Users->get($id, contain: []); $this->set(compact('user')); } @@ -67,9 +64,7 @@ public function add() */ public function edit($id = null) { - $user = $this->Users->get($id, [ - 'contain' => [], - ]); + $user = $this->Users->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { $user = $this->Users->patchEntity($user, $this->request->getData()); if ($this->Users->save($user)) {