From f65502b7bc28de1309d86540e5719e3f874776fc Mon Sep 17 00:00:00 2001 From: Arnaud BAGNIS Date: Wed, 7 Feb 2024 21:29:15 +0100 Subject: [PATCH 1/3] add support to symfony console 5,6,7 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index eac0afc..493e7b5 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "require": { "php": "^8.0.0", "rareloop/lumberjack-core": "^5.0.1||^6.0.0", - "symfony/console": "^4.1", + "symfony/console": "^5.0 || ^6.0 || ^7.0", "icanboogie/inflector": "^2.0", "statamic/stringy": "^3.1.1" }, @@ -26,4 +26,4 @@ "Rareloop\\Hatchet\\Test\\": "tests" } } -} \ No newline at end of file +} From 385330c9af87444e067e18ed963470cfb1c39d71 Mon Sep 17 00:00:00 2001 From: Arnaud BAGNIS Date: Wed, 7 Feb 2024 21:55:27 +0100 Subject: [PATCH 2/3] Resolve test unit + Adapt Command --- src/Commands/Command.php | 4 ---- src/Commands/ControllerMake.php | 3 ++- src/Commands/ExceptionMake.php | 10 +++++----- src/Commands/PostTypeMake.php | 10 +++++----- src/Commands/RouteList.php | 10 ++++++---- src/Commands/ServiceProviderMake.php | 11 ++++++----- src/Commands/ViewModelMake.php | 11 ++++++----- tests/Unit/CommandTest.php | 9 +++++---- tests/Unit/HatchetTest.php | 4 +++- tests/Unit/RegisterCommandsTest.php | 2 +- 10 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 4360f3e..db58e92 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -23,10 +23,6 @@ public function __construct(Application $app) } else { parent::__construct($this->name); } - - if (isset($this->description)) { - $this->setDescription($this->description); - } } protected function configureFromSignature() diff --git a/src/Commands/ControllerMake.php b/src/Commands/ControllerMake.php index d58ec6e..0e5ca82 100644 --- a/src/Commands/ControllerMake.php +++ b/src/Commands/ControllerMake.php @@ -12,7 +12,7 @@ class ControllerMake extends MakeFromStubCommand protected $description = 'Create a Controller'; - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); @@ -20,5 +20,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $stub = str_replace('DummyController', $name, $stub); $this->createFile('app/Http/Controllers/'.$name.'.php', $stub); + return self::SUCCESS; } } diff --git a/src/Commands/ExceptionMake.php b/src/Commands/ExceptionMake.php index 0bc4e4e..fe1c333 100644 --- a/src/Commands/ExceptionMake.php +++ b/src/Commands/ExceptionMake.php @@ -6,13 +6,13 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'make:exception {name : The class name of the Exception}', + description: 'Create a Exception' +)] class ExceptionMake extends MakeFromStubCommand { - protected $signature = 'make:exception {name : The class name of the Exception}'; - - protected $description = 'Create a Exception'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); diff --git a/src/Commands/PostTypeMake.php b/src/Commands/PostTypeMake.php index 5db8ad2..7319c48 100644 --- a/src/Commands/PostTypeMake.php +++ b/src/Commands/PostTypeMake.php @@ -12,13 +12,13 @@ use Symfony\Component\Console\Question\Question; use function Stringy\create as s; +#[AsCommand( + name: 'make:posttype {name : The class name of the PostType (singular)}', + description: 'Create a PostType' +)] class PostTypeMake extends MakeFromStubCommand { - protected $signature = 'make:posttype {name : The class name of the PostType (singular)}'; - - protected $description = 'Create a PostType'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $singular = $input->getArgument('name'); $plural = Inflector::get('en')->pluralize($singular); diff --git a/src/Commands/RouteList.php b/src/Commands/RouteList.php index 4272d70..63d0948 100644 --- a/src/Commands/RouteList.php +++ b/src/Commands/RouteList.php @@ -4,17 +4,19 @@ use Rareloop\Hatchet\Commands\Command; use Rareloop\Router\Router; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'route:list', + description: 'List all registered routes' +)] class RouteList extends Command { - protected $signature = 'route:list'; - protected $description = 'List all registered routes'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $router = $this->app->get(Router::class); diff --git a/src/Commands/ServiceProviderMake.php b/src/Commands/ServiceProviderMake.php index 9076bee..3ddd1b2 100644 --- a/src/Commands/ServiceProviderMake.php +++ b/src/Commands/ServiceProviderMake.php @@ -3,16 +3,17 @@ namespace Rareloop\Hatchet\Commands; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'make:provider {name : The class name of the ServiceProvider}', + description: 'Create a ServiceProvider', +)] class ServiceProviderMake extends MakeFromStubCommand { - protected $signature = 'make:provider {name : The class name of the ServiceProvider}'; - - protected $description = 'Create a ServiceProvider'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); diff --git a/src/Commands/ViewModelMake.php b/src/Commands/ViewModelMake.php index 7e73a21..e0fde4a 100644 --- a/src/Commands/ViewModelMake.php +++ b/src/Commands/ViewModelMake.php @@ -3,16 +3,17 @@ namespace Rareloop\Hatchet\Commands; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'make:viewmodel {name : The class name of the View Model}', + description: 'Create a ViewModel', +)] class ViewModelMake extends MakeFromStubCommand { - protected $signature = 'make:viewmodel {name : The class name of the View Model}'; - - protected $description = 'Create a ViewModel'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); diff --git a/tests/Unit/CommandTest.php b/tests/Unit/CommandTest.php index c381248..127c36d 100644 --- a/tests/Unit/CommandTest.php +++ b/tests/Unit/CommandTest.php @@ -12,7 +12,7 @@ class CommandTest extends TestCase { - use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; + use MockeryPHPUnitIntegration; /** @test */ public function can_create_a_command_with_a_name() @@ -55,9 +55,10 @@ class CommandWithSignature extends Command protected $signature = 'test:command {name} {--option}'; } +#[AsCommand( + name: 'test:command', + description: 'testing123' +)] class CommandWithDescription extends Command { - protected $name = 'test:command'; - - protected $description = 'testing123'; } diff --git a/tests/Unit/HatchetTest.php b/tests/Unit/HatchetTest.php index 72794b9..809719d 100644 --- a/tests/Unit/HatchetTest.php +++ b/tests/Unit/HatchetTest.php @@ -83,5 +83,7 @@ protected function configure() $this->setName('test:command'); } - protected function execute(InputInterface $input, OutputInterface $output) {} + protected function execute(InputInterface $input, OutputInterface $output): int { + return false; + } } diff --git a/tests/Unit/RegisterCommandsTest.php b/tests/Unit/RegisterCommandsTest.php index 39cf774..1df3e15 100644 --- a/tests/Unit/RegisterCommandsTest.php +++ b/tests/Unit/RegisterCommandsTest.php @@ -44,5 +44,5 @@ protected function configure() $this->setName('test:command'); } - protected function execute(InputInterface $input, OutputInterface $output) {} + protected function execute(InputInterface $input, OutputInterface $output): int {} } From 6ba8a2d3a529e24101f229abbf0b97088ea6a5a2 Mon Sep 17 00:00:00 2001 From: Arnaud BAGNIS Date: Wed, 7 Feb 2024 23:04:39 +0100 Subject: [PATCH 3/3] add Missing AsCommand --- src/Commands/ExceptionMake.php | 1 + src/Commands/PostTypeMake.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Commands/ExceptionMake.php b/src/Commands/ExceptionMake.php index fe1c333..986c375 100644 --- a/src/Commands/ExceptionMake.php +++ b/src/Commands/ExceptionMake.php @@ -3,6 +3,7 @@ namespace Rareloop\Hatchet\Commands; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/Commands/PostTypeMake.php b/src/Commands/PostTypeMake.php index 7319c48..e2b95c0 100644 --- a/src/Commands/PostTypeMake.php +++ b/src/Commands/PostTypeMake.php @@ -4,6 +4,7 @@ use ICanBoogie\Inflector; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface;