Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix common options missing and warning #231

Merged
merged 3 commits into from
Oct 11, 2023

Conversation

LordSimal
Copy link
Contributor

@LordSimal LordSimal commented Oct 10, 2023

See https://discourse.cakephp.org/t/connection-problem-with-fixture-factory-v3-0/11569

I didn't test baking a new factory 😅

-> % cake bake fixture_factory Categories
2023-10-10 07:38:49 error: [TypeError] Cannot assign null to property Bake\Command\BakeCommand::$connection of type string in /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/bake/src/Utility/CommonOptionsTrait.php on line 77
Stack Trace:
- /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/vierge-noire/cakephp-fixture-factories/src/Command/BakeFixtureFactoryCommand.php:219
- /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/BaseCommand.php:192
- /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/CommandRunner.php:327
- /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/CommandRunner.php:168
- /Users/kevinpfeifer/Documents/Sunlime/alfred/bin/cake.php:12
- [main]:

[TypeError] Cannot assign null to property Bake\Command\BakeCommand::$connection of type string in /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/bake/src/Utility/CommonOptionsTrait.php on line 77

Stack Trace:

Bake\Command\BakeCommand->extractCommonProperties() - ROOT/vendor/vierge-noire/cakephp-fixture-factories/src/Command/BakeFixtureFactoryCommand.php, line 219
CakephpFixtureFactories\Command\BakeFixtureFactoryCommand->execute() - CORE/src/Console/BaseCommand.php, line 192
Cake\Console\BaseCommand->run() - CORE/src/Console/CommandRunner.php, line 327
Cake\Console\CommandRunner->runCommand() - CORE/src/Console/CommandRunner.php, line 168
Cake\Console\CommandRunner->run() - ROOT/bin/cake.php, line 12
[main] - [main], line 0

also there is another warning as well which this PR fixes

-> % cake bake fixture_factory Categories
2023-10-10 07:20:43 warning: Undefined array key "useStatements"
Trace:
CakephpFixtureFactories\Command\BakeFixtureFactoryCommand->templateData() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/vierge-noire/cakephp-fixture-factories/src/Command/BakeFixtureFactoryCommand.php, line 273
CakephpFixtureFactories\Command\BakeFixtureFactoryCommand->bakeFixtureFactory() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/vierge-noire/cakephp-fixture-factories/src/Command/BakeFixtureFactoryCommand.php, line 253
CakephpFixtureFactories\Command\BakeFixtureFactoryCommand->execute() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/BaseCommand.php, line 192
Cake\Console\BaseCommand->run() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 327
Cake\Console\CommandRunner->runCommand() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 168
Cake\Console\CommandRunner->run() /Users/kevinpfeifer/Documents/Sunlime/alfred/bin/cake.php, line 12
[main]

warning: 2 :: Undefined array key "useStatements" on line 327 of /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/vierge-noire/cakephp-fixture-factories/src/Command/BakeFixtureFactoryCommand.php
Stack Trace:

CakephpFixtureFactories\Command\BakeFixtureFactoryCommand->templateData() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/vierge-noire/cakephp-fixture-factories/src/Command/BakeFixtureFactoryCommand.php, line 273
CakephpFixtureFactories\Command\BakeFixtureFactoryCommand->bakeFixtureFactory() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/vierge-noire/cakephp-fixture-factories/src/Command/BakeFixtureFactoryCommand.php, line 253
CakephpFixtureFactories\Command\BakeFixtureFactoryCommand->execute() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/BaseCommand.php, line 192
Cake\Console\BaseCommand->run() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 327
Cake\Console\CommandRunner->runCommand() /Users/kevinpfeifer/Documents/Sunlime/alfred/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 168
Cake\Console\CommandRunner->run() /Users/kevinpfeifer/Documents/Sunlime/alfred/bin/cake.php, line 12
[main]

@LordSimal LordSimal changed the title fix warning fix common options missing and warning Oct 10, 2023
@@ -420,6 +420,8 @@ public function getOptionParser(): ConsoleOptionParser
$name = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
$parser = new ConsoleOptionParser($name);

$parser = $this->_setCommonOptions($parser);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed the error since the common option's default values aren't set without this call.

@@ -324,7 +324,7 @@ public function templateData(Arguments $arg): array
$data['useStatements'] = array_unique(array_values(Hash::flatten($useStatements)));
}

if ($data['useStatements']) {
if (!empty($data['useStatements'])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed the warning

Copy link
Collaborator

@pabloelcolombiano pabloelcolombiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for adding a teest!

@pabloelcolombiano pabloelcolombiano changed the base branch from cake5 to next October 11, 2023 19:00
@pabloelcolombiano pabloelcolombiano dismissed their stale review October 11, 2023 19:00

The base branch was changed.

Copy link
Collaborator

@pabloelcolombiano pabloelcolombiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for adding a test!

@pabloelcolombiano pabloelcolombiano merged commit e9aee90 into vierge-noire:next Oct 11, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants