From a5ddbfdb62149ce37986faf68a217326ad82ec29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Sun, 19 Nov 2017 19:28:49 +0100 Subject: [PATCH] Deprecated AbstractCommand (#9) --- .docs/README.md | 6 +++--- src/Command/AbstractCommand.php | 9 +++++++++ tests/cases/Command/Command.HelperSet.phpt | 2 +- tests/cases/DI/ConsoleExtension.phpt | 12 ++++++------ tests/fixtures/FooCommand.php | 4 ++-- tests/fixtures/HelperSetCommand.php | 4 ++-- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.docs/README.md b/.docs/README.md index eb9a420..706d2bb 100644 --- a/.docs/README.md +++ b/.docs/README.md @@ -15,7 +15,7 @@ extensions: ``` -The extension will look for all commands extending from [`Contributte\Console\Command\AbstractCommand`](https://github.com/contributte/console/blob/master/src/Command/AbstractCommand.php) and automatically add them to the console application. +The extension will look for all commands extending from [`Symfony\Component\Console\Command\Command`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Command/Command.php) and automatically add them to the console application. That's all. You don't have to be worried about anything else. ## Configuration @@ -87,11 +87,11 @@ From this point, all commands are instanced only if needed. Don't forget, that l namespace App\Console; -use Contributte\Console\Command\AbstractCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -final class FooCommand extends AbstractCommand +final class FooCommand extends Command { /** diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 0ab40f0..042df40 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -10,4 +10,13 @@ abstract class AbstractCommand extends Command { + /** + * @param string|null $name + */ + public function __construct($name = NULL) + { + parent::__construct($name); + trigger_error(sprintf('Extending %s is deprecated, extend %s directly.', self::class, Command::class), E_USER_DEPRECATED); + } + } diff --git a/tests/cases/Command/Command.HelperSet.phpt b/tests/cases/Command/Command.HelperSet.phpt index ddb3a1c..704bea2 100644 --- a/tests/cases/Command/Command.HelperSet.phpt +++ b/tests/cases/Command/Command.HelperSet.phpt @@ -1,7 +1,7 @@ findByType(AbstractCommand::class)); + Assert::count(0, $container->findByType(Command::class)); }); // 1 command of type FooCommand @@ -47,8 +47,8 @@ test(function () { Assert::type(Application::class, $container->getByType(Application::class)); Assert::true($container->isCreated('foo')); - Assert::count(1, $container->findByType(AbstractCommand::class)); - Assert::type(FooCommand::class, $container->getByType(AbstractCommand::class)); + Assert::count(1, $container->findByType(Command::class)); + Assert::type(FooCommand::class, $container->getByType(Command::class)); }); // 1 command of type FooCommand lazy-loading @@ -69,6 +69,6 @@ test(function () { Assert::type(Application::class, $container->getByType(Application::class)); Assert::false($container->isCreated('foo')); - Assert::count(1, $container->findByType(AbstractCommand::class)); - Assert::type(FooCommand::class, $container->getByType(AbstractCommand::class)); + Assert::count(1, $container->findByType(Command::class)); + Assert::type(FooCommand::class, $container->getByType(Command::class)); }); diff --git a/tests/fixtures/FooCommand.php b/tests/fixtures/FooCommand.php index 5c2ec46..cd2c651 100644 --- a/tests/fixtures/FooCommand.php +++ b/tests/fixtures/FooCommand.php @@ -2,14 +2,14 @@ namespace Tests\Fixtures; -use Contributte\Console\Command\AbstractCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @author Milan Felix Sulc */ -final class FooCommand extends AbstractCommand +final class FooCommand extends Command { /** @var string */ diff --git a/tests/fixtures/HelperSetCommand.php b/tests/fixtures/HelperSetCommand.php index 0a77726..86e60cd 100644 --- a/tests/fixtures/HelperSetCommand.php +++ b/tests/fixtures/HelperSetCommand.php @@ -2,14 +2,14 @@ namespace Tests\Fixtures; -use Contributte\Console\Command\AbstractCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @author Milan Felix Sulc */ -final class HelperSetCommand extends AbstractCommand +final class HelperSetCommand extends Command { /**