From 905f0a00543db05fef021cc2d1d2b91ef2403d0d Mon Sep 17 00:00:00 2001 From: David Maicher Date: Tue, 9 Jun 2020 13:58:50 +0200 Subject: [PATCH] remove deprecations for ConnectionHelper --- bin/doctrine-dbal.php | 18 ++----- .../Console/Command/ReservedWordsCommand.php | 21 +-------- src/Tools/Console/Command/RunSqlCommand.php | 21 +-------- src/Tools/Console/ConsoleRunner.php | 46 ++---------------- src/Tools/Console/Helper/ConnectionHelper.php | 47 ------------------- tests/Tools/Console/RunSqlCommandTest.php | 15 +++--- 6 files changed, 17 insertions(+), 151 deletions(-) delete mode 100644 src/Tools/Console/Helper/ConnectionHelper.php diff --git a/bin/doctrine-dbal.php b/bin/doctrine-dbal.php index 61a4098c9b0..2f83e0d144f 100644 --- a/bin/doctrine-dbal.php +++ b/bin/doctrine-dbal.php @@ -1,8 +1,6 @@ SQLServer2012Keywords::class, ]; - /** @var ConnectionProvider|null */ + /** @var ConnectionProvider */ private $connectionProvider; - public function __construct(?ConnectionProvider $connectionProvider = null) + public function __construct(ConnectionProvider $connectionProvider) { parent::__construct(); $this->connectionProvider = $connectionProvider; - if ($connectionProvider !== null) { - return; - } - - @trigger_error('Not passing a connection provider as the first constructor argument is deprecated', E_USER_DEPRECATED); } /** @@ -174,14 +165,6 @@ private function getConnection(InputInterface $input): Connection $connectionName = $input->getOption('connection'); assert(is_string($connectionName) || $connectionName === null); - if ($this->connectionProvider === null) { - if ($connectionName !== null) { - throw new Exception('Specifying a connection is only supported when a ConnectionProvider is used.'); - } - - return $this->getHelper('db')->getConnection(); - } - if ($connectionName !== null) { return $this->connectionProvider->getConnection($connectionName); } diff --git a/src/Tools/Console/Command/RunSqlCommand.php b/src/Tools/Console/Command/RunSqlCommand.php index f1302b14fe3..d32993a5a33 100644 --- a/src/Tools/Console/Command/RunSqlCommand.php +++ b/src/Tools/Console/Command/RunSqlCommand.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\DBAL\Tools\Dumper; -use Exception; use LogicException; use RuntimeException; use Symfony\Component\Console\Command\Command; @@ -19,9 +18,6 @@ use function is_numeric; use function is_string; use function stripos; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Task for executing arbitrary SQL that can come from a file or directly from @@ -29,18 +25,13 @@ */ class RunSqlCommand extends Command { - /** @var ConnectionProvider|null */ + /** @var ConnectionProvider */ private $connectionProvider; - public function __construct(?ConnectionProvider $connectionProvider = null) + public function __construct(ConnectionProvider $connectionProvider) { parent::__construct(); $this->connectionProvider = $connectionProvider; - if ($connectionProvider !== null) { - return; - } - - @trigger_error('Not passing a connection provider as the first constructor argument is deprecated', E_USER_DEPRECATED); } /** @return void */ @@ -104,14 +95,6 @@ private function getConnection(InputInterface $input): Connection $connectionName = $input->getOption('connection'); assert(is_string($connectionName) || $connectionName === null); - if ($this->connectionProvider === null) { - if ($connectionName !== null) { - throw new Exception('Specifying a connection is only supported when a ConnectionProvider is used.'); - } - - return $this->getHelper('db')->getConnection(); - } - if ($connectionName !== null) { return $this->connectionProvider->getConnection($connectionName); } diff --git a/src/Tools/Console/ConsoleRunner.php b/src/Tools/Console/ConsoleRunner.php index d1eb630d965..8637afdc6a6 100644 --- a/src/Tools/Console/ConsoleRunner.php +++ b/src/Tools/Console/ConsoleRunner.php @@ -2,67 +2,30 @@ namespace Doctrine\DBAL\Tools\Console; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; -use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use PackageVersions\Versions; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\HelperSet; -use TypeError; - -use function sprintf; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Handles running the Console Tools inside Symfony Console context. */ class ConsoleRunner { - /** - * Create a Symfony Console HelperSet - * - * @deprecated use a ConnectionProvider instead. - * - * @return HelperSet - */ - public static function createHelperSet(Connection $connection) - { - return new HelperSet([ - 'db' => new ConnectionHelper($connection), - ]); - } - /** * Runs console with the given connection provider or helperset (deprecated). * - * @param ConnectionProvider|HelperSet $helperSetOrConnectionProvider - * @param Command[] $commands + * @param Command[] $commands * * @return void */ - public static function run($helperSetOrConnectionProvider, $commands = []) + public static function run(ConnectionProvider $connectionProvider, $commands = []) { $cli = new Application('Doctrine Command Line Interface', Versions::getVersion('doctrine/dbal')); $cli->setCatchExceptions(true); - - $connectionProvider = null; - if ($helperSetOrConnectionProvider instanceof HelperSet) { - @trigger_error(sprintf('Passing an instance of "%s" as the first argument is deprecated. Pass an instance of "%s" instead.', HelperSet::class, ConnectionProvider::class), E_USER_DEPRECATED); - $connectionProvider = null; - $cli->setHelperSet($helperSetOrConnectionProvider); - } elseif ($helperSetOrConnectionProvider instanceof ConnectionProvider) { - $connectionProvider = $helperSetOrConnectionProvider; - } else { - throw new TypeError(sprintf('First argument must be an instance of "%s" or "%s"', HelperSet::class, ConnectionProvider::class)); - } - self::addCommands($cli, $connectionProvider); - $cli->addCommands($commands); $cli->run(); } @@ -70,11 +33,10 @@ public static function run($helperSetOrConnectionProvider, $commands = []) /** * @return void */ - public static function addCommands(Application $cli, ?ConnectionProvider $connectionProvider = null) + public static function addCommands(Application $cli, ConnectionProvider $connectionProvider) { $cli->addCommands([ - new RunSqlCommand(), - new ReservedWordsCommand(), + new RunSqlCommand($connectionProvider), new ReservedWordsCommand($connectionProvider), ]); } diff --git a/src/Tools/Console/Helper/ConnectionHelper.php b/src/Tools/Console/Helper/ConnectionHelper.php deleted file mode 100644 index 09855a74cd5..00000000000 --- a/src/Tools/Console/Helper/ConnectionHelper.php +++ /dev/null @@ -1,47 +0,0 @@ -_connection = $connection; - } - - /** - * Retrieves the Doctrine database Connection. - * - * @return Connection - */ - public function getConnection() - { - return $this->_connection; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'connection'; - } -} diff --git a/tests/Tools/Console/RunSqlCommandTest.php b/tests/Tools/Console/RunSqlCommandTest.php index 84b9436d98b..32157cc3416 100644 --- a/tests/Tools/Console/RunSqlCommandTest.php +++ b/tests/Tools/Console/RunSqlCommandTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; -use Doctrine\DBAL\Tools\Console\ConsoleRunner; +use Doctrine\DBAL\Tools\Console\ConnectionProvider\SingleConnectionProvider; use LogicException; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,20 +24,17 @@ class RunSqlCommandTest extends TestCase protected function setUp(): void { - $application = new Application(); - $application->add(new RunSqlCommand()); - - $this->command = $application->find('dbal:run-sql'); - $this->commandTester = new CommandTester($this->command); - $this->connectionMock = $this->createMock(Connection::class); $this->connectionMock->method('fetchAllAssociative') ->willReturn([[1]]); $this->connectionMock->method('executeUpdate') ->willReturn(42); - $helperSet = ConsoleRunner::createHelperSet($this->connectionMock); - $this->command->setHelperSet($helperSet); + $application = new Application(); + $application->add(new RunSqlCommand(new SingleConnectionProvider($this->connectionMock))); + + $this->command = $application->find('dbal:run-sql'); + $this->commandTester = new CommandTester($this->command); } public function testMissingSqlArgument(): void