From 8f20df6559bbd696ac035c87b3db63218cd089ce Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 3 Sep 2022 02:17:36 +0200 Subject: [PATCH 1/5] Remove InstallCommandMock --- .../CoreBundle/Command/InstallCommand.php | 11 ++++++++++ .../CoreBundle/Command/InstallCommandTest.php | 17 +++++++++----- .../CoreBundle/Mock/InstallCommandMock.php | 22 ------------------- 3 files changed, 23 insertions(+), 27 deletions(-) delete mode 100644 tests/Wallabag/CoreBundle/Mock/InstallCommandMock.php diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index fa40beac9..17f97b9b7 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -41,6 +41,13 @@ class InstallCommand extends ContainerAwareCommand 'curl_multi_init', ]; + private bool $runOtherCommands = true; + + public function disableRunOtherCommands(): void + { + $this->runOtherCommands = false; + } + protected function configure() { $this @@ -315,6 +322,10 @@ class InstallCommand extends ContainerAwareCommand */ protected function runCommand($command, $parameters = []) { + if (!$this->runOtherCommands) { + return $this; + } + $parameters = array_merge( ['command' => $command], $parameters, diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 96fa775b6..e81e50fec 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -14,7 +14,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Tester\CommandTester; -use Tests\Wallabag\CoreBundle\Mock\InstallCommandMock; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Wallabag\CoreBundle\Command\InstallCommand; @@ -89,9 +88,11 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommandMock()); + $application->add(new InstallCommand()); + /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); + $command->disableRunOtherCommands(); $tester = new CommandTester($command); $tester->setInputs([ @@ -114,9 +115,11 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandWithReset() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommandMock()); + $application->add(new InstallCommand()); + /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); + $command->disableRunOtherCommands(); $tester = new CommandTester($command); $tester->setInputs([ @@ -188,9 +191,11 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandChooseResetSchema() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommandMock()); + $application->add(new InstallCommand()); + /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); + $command->disableRunOtherCommands(); $tester = new CommandTester($command); $tester->setInputs([ @@ -257,9 +262,11 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandNoInteraction() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommandMock()); + $application->add(new InstallCommand()); + /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); + $command->disableRunOtherCommands(); $tester = new CommandTester($command); $tester->execute([ diff --git a/tests/Wallabag/CoreBundle/Mock/InstallCommandMock.php b/tests/Wallabag/CoreBundle/Mock/InstallCommandMock.php deleted file mode 100644 index 5806bd4d5..000000000 --- a/tests/Wallabag/CoreBundle/Mock/InstallCommandMock.php +++ /dev/null @@ -1,22 +0,0 @@ - Date: Sat, 3 Sep 2022 02:54:30 +0200 Subject: [PATCH 2/5] Make InstallCommand properties and methods private --- .../CoreBundle/Command/InstallCommand.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 17f97b9b7..1dafde40d 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -26,17 +26,17 @@ class InstallCommand extends ContainerAwareCommand /** * @var InputInterface */ - protected $defaultInput; + private $defaultInput; /** * @var SymfonyStyle */ - protected $io; + private $io; /** * @var array */ - protected $functionExists = [ + private $functionExists = [ 'curl_exec', 'curl_multi_init', ]; @@ -81,7 +81,7 @@ class InstallCommand extends ContainerAwareCommand $this->io->success('You can now configure your web server, see https://doc.wallabag.org'); } - protected function checkRequirements() + private function checkRequirements() { $this->io->section('Step 1 of 4: Checking system requirements.'); @@ -181,7 +181,7 @@ class InstallCommand extends ContainerAwareCommand return $this; } - protected function setupDatabase() + private function setupDatabase() { $this->io->section('Step 2 of 4: Setting up database.'); @@ -249,7 +249,7 @@ class InstallCommand extends ContainerAwareCommand return $this; } - protected function setupAdmin() + private function setupAdmin() { $this->io->section('Step 3 of 4: Administration setup.'); @@ -284,7 +284,7 @@ class InstallCommand extends ContainerAwareCommand return $this; } - protected function setupConfig() + private function setupConfig() { $this->io->section('Step 4 of 4: Config setup.'); $em = $this->getContainer()->get(EntityManagerInterface::class); @@ -320,7 +320,7 @@ class InstallCommand extends ContainerAwareCommand * @param string $command * @param array $parameters Parameters to this command (usually 'force' => true) */ - protected function runCommand($command, $parameters = []) + private function runCommand($command, $parameters = []) { if (!$this->runOtherCommands) { return $this; From 6915a92047ff0de6419610dbdb3559937ac59c97 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 3 Sep 2022 02:20:24 +0200 Subject: [PATCH 3/5] Remove useless command addition --- .../CoreBundle/Command/CleanDuplicatesCommandTest.php | 5 ----- .../Wallabag/CoreBundle/Command/ExportCommandTest.php | 5 ----- .../Command/GenerateUrlHashesCommandTest.php | 5 ----- .../CoreBundle/Command/InstallCommandTest.php | 11 ----------- .../CoreBundle/Command/ListUserCommandTest.php | 5 ----- .../CoreBundle/Command/ReloadEntryCommandTest.php | 4 ---- .../CoreBundle/Command/ShowUserCommandTest.php | 5 ----- .../Wallabag/CoreBundle/Command/TagAllCommandTest.php | 4 ---- .../ImportBundle/Command/ImportCommandTest.php | 6 ------ .../ImportBundle/Command/RedisWorkerCommandTest.php | 4 ---- 10 files changed, 54 deletions(-) diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php index 72d7dd513..29f8cd294 100644 --- a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php @@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; @@ -15,7 +14,6 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase public function testRunCleanDuplicates() { $application = new Application($this->getClient()->getKernel()); - $application->add(new CleanDuplicatesCommand()); $command = $application->find('wallabag:clean-duplicates'); @@ -31,7 +29,6 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase public function testRunCleanDuplicatesCommandWithBadUsername() { $application = new Application($this->getClient()->getKernel()); - $application->add(new CleanDuplicatesCommand()); $command = $application->find('wallabag:clean-duplicates'); @@ -47,7 +44,6 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase public function testRunCleanDuplicatesCommandForUser() { $application = new Application($this->getClient()->getKernel()); - $application->add(new CleanDuplicatesCommand()); $command = $application->find('wallabag:clean-duplicates'); @@ -88,7 +84,6 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $this->assertCount(2, $nbEntries); $application = new Application($this->getClient()->getKernel()); - $application->add(new CleanDuplicatesCommand()); $command = $application->find('wallabag:clean-duplicates'); diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index ac7c0792b..4e8d4c0d0 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\ExportCommand; class ExportCommandTest extends WallabagCoreTestCase { @@ -16,7 +15,6 @@ class ExportCommandTest extends WallabagCoreTestCase $this->expectExceptionMessage('Not enough arguments (missing: "username")'); $application = new Application($this->getClient()->getKernel()); - $application->add(new ExportCommand()); $command = $application->find('wallabag:export'); @@ -29,7 +27,6 @@ class ExportCommandTest extends WallabagCoreTestCase public function testExportCommandWithBadUsername() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ExportCommand()); $command = $application->find('wallabag:export'); @@ -45,7 +42,6 @@ class ExportCommandTest extends WallabagCoreTestCase public function testExportCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ExportCommand()); $command = $application->find('wallabag:export'); @@ -63,7 +59,6 @@ class ExportCommandTest extends WallabagCoreTestCase public function testExportCommandWithSpecialPath() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ExportCommand()); $command = $application->find('wallabag:export'); diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php index f235619b6..d09515804 100644 --- a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php @@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\GenerateUrlHashesCommand; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; @@ -15,7 +14,6 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase public function testRunGenerateUrlHashesCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new GenerateUrlHashesCommand()); $command = $application->find('wallabag:generate-hashed-urls'); @@ -31,7 +29,6 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase public function testRunGenerateUrlHashesCommandWithBadUsername() { $application = new Application($this->getClient()->getKernel()); - $application->add(new GenerateUrlHashesCommand()); $command = $application->find('wallabag:generate-hashed-urls'); @@ -47,7 +44,6 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase public function testRunGenerateUrlHashesCommandForUser() { $application = new Application($this->getClient()->getKernel()); - $application->add(new GenerateUrlHashesCommand()); $command = $application->find('wallabag:generate-hashed-urls'); @@ -77,7 +73,6 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase $em->flush(); $application = new Application($this->getClient()->getKernel()); - $application->add(new GenerateUrlHashesCommand()); $command = $application->find('wallabag:generate-hashed-urls'); diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index e81e50fec..a20a2fd3b 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -5,7 +5,6 @@ namespace Tests\Wallabag\CoreBundle\Command; use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; -use Doctrine\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -88,7 +87,6 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommand()); /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); @@ -115,7 +113,6 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandWithReset() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommand()); /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); @@ -152,7 +149,6 @@ class InstallCommandTest extends WallabagCoreTestCase } $application = new Application($this->getClient()->getKernel()); - $application->add(new DropDatabaseDoctrineCommand()); // drop database first, so the install command won't ask to reset things $command = $application->find('doctrine:database:drop'); @@ -164,7 +160,6 @@ class InstallCommandTest extends WallabagCoreTestCase // start a new application to avoid lagging connexion to pgsql $client = static::createClient(); $application = new Application($client->getKernel()); - $application->add(new InstallCommand()); $command = $application->find('wallabag:install'); @@ -191,7 +186,6 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandChooseResetSchema() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommand()); /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); @@ -218,10 +212,6 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandChooseNothing() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommand()); - $application->add(new DropDatabaseDoctrineCommand()); - $application->add(new CreateDatabaseDoctrineCommand()); - $application->add(new MigrationsMigrateDoctrineCommand()); // drop database first, so the install command won't ask to reset things $command = new DropDatabaseDoctrineCommand(); @@ -262,7 +252,6 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandNoInteraction() { $application = new Application($this->getClient()->getKernel()); - $application->add(new InstallCommand()); /** @var InstallCommand $command */ $command = $application->find('wallabag:install'); diff --git a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php index 8a4f8a58f..69696bdc3 100644 --- a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php @@ -5,14 +5,12 @@ namespace Tests\Wallabag\CoreBundle\Command; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\ListUserCommand; class ListUserCommandTest extends WallabagCoreTestCase { public function testRunListUserCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ListUserCommand()); $command = $application->find('wallabag:user:list'); @@ -27,7 +25,6 @@ class ListUserCommandTest extends WallabagCoreTestCase public function testRunListUserCommandWithLimit() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ListUserCommand()); $command = $application->find('wallabag:user:list'); @@ -43,7 +40,6 @@ class ListUserCommandTest extends WallabagCoreTestCase public function testRunListUserCommandWithSearch() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ListUserCommand()); $command = $application->find('wallabag:user:list'); @@ -59,7 +55,6 @@ class ListUserCommandTest extends WallabagCoreTestCase public function testRunListUserCommandWithSearchAndLimit() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ListUserCommand()); $command = $application->find('wallabag:user:list'); diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php index 0bd4a5780..45cacf117 100644 --- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php @@ -5,7 +5,6 @@ namespace Tests\Wallabag\CoreBundle\Command; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\ReloadEntryCommand; use Wallabag\CoreBundle\Entity\Entry; class ReloadEntryCommandTest extends WallabagCoreTestCase @@ -51,7 +50,6 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase public function testRunReloadEntryCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ReloadEntryCommand()); $command = $application->find('wallabag:entry:reload'); $tester = new CommandTester($command); @@ -79,7 +77,6 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase public function testRunReloadEntryWithUsernameCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ReloadEntryCommand()); $command = $application->find('wallabag:entry:reload'); $tester = new CommandTester($command); @@ -104,7 +101,6 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase public function testRunReloadEntryWithoutEntryCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ReloadEntryCommand()); $command = $application->find('wallabag:entry:reload'); $tester = new CommandTester($command); diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index 32cef11b1..51f8b2eb7 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php @@ -7,7 +7,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\ShowUserCommand; use Wallabag\UserBundle\Entity\User; class ShowUserCommandTest extends WallabagCoreTestCase @@ -18,7 +17,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase $this->expectExceptionMessage('Not enough arguments'); $application = new Application($this->getClient()->getKernel()); - $application->add(new ShowUserCommand()); $command = $application->find('wallabag:user:show'); @@ -31,7 +29,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase public function testRunShowUserCommandWithBadUsername() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ShowUserCommand()); $command = $application->find('wallabag:user:show'); @@ -47,7 +44,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase public function testRunShowUserCommandForUser() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ShowUserCommand()); $command = $application->find('wallabag:user:show'); @@ -80,7 +76,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase $em->flush(); $application = new Application($this->getClient()->getKernel()); - $application->add(new ShowUserCommand()); $command = $application->find('wallabag:user:show'); diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php index 04526311c..4fea25aae 100644 --- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php @@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\TagAllCommand; class TagAllCommandTest extends WallabagCoreTestCase { @@ -16,7 +15,6 @@ class TagAllCommandTest extends WallabagCoreTestCase $this->expectExceptionMessage('Not enough arguments (missing: "username")'); $application = new Application($this->getClient()->getKernel()); - $application->add(new TagAllCommand()); $command = $application->find('wallabag:tag:all'); @@ -29,7 +27,6 @@ class TagAllCommandTest extends WallabagCoreTestCase public function testRunTagAllCommandWithBadUsername() { $application = new Application($this->getClient()->getKernel()); - $application->add(new TagAllCommand()); $command = $application->find('wallabag:tag:all'); @@ -45,7 +42,6 @@ class TagAllCommandTest extends WallabagCoreTestCase public function testRunTagAllCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new TagAllCommand()); $command = $application->find('wallabag:tag:all'); diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index 750e748db..36ee76dbf 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -8,7 +8,6 @@ use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\ImportBundle\Command\ImportCommand; class ImportCommandTest extends WallabagCoreTestCase { @@ -18,7 +17,6 @@ class ImportCommandTest extends WallabagCoreTestCase $this->expectExceptionMessage('Not enough arguments'); $application = new Application($this->getClient()->getKernel()); - $application->add(new ImportCommand()); $command = $application->find('wallabag:import'); @@ -34,7 +32,6 @@ class ImportCommandTest extends WallabagCoreTestCase $this->expectExceptionMessage('not found'); $application = new Application($this->getClient()->getKernel()); - $application->add(new ImportCommand()); $command = $application->find('wallabag:import'); @@ -51,7 +48,6 @@ class ImportCommandTest extends WallabagCoreTestCase $this->expectException(NoResultException::class); $application = new Application($this->getClient()->getKernel()); - $application->add(new ImportCommand()); $command = $application->find('wallabag:import'); @@ -66,7 +62,6 @@ class ImportCommandTest extends WallabagCoreTestCase public function testRunImportCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new ImportCommand()); $command = $application->find('wallabag:import'); @@ -87,7 +82,6 @@ class ImportCommandTest extends WallabagCoreTestCase $this->logInAs('admin'); $application = new Application($this->getClient()->getKernel()); - $application->add(new ImportCommand()); $command = $application->find('wallabag:import'); diff --git a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php index f27439af3..a8c79dc0e 100644 --- a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php @@ -9,7 +9,6 @@ use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use Wallabag\ImportBundle\Command\RedisWorkerCommand; class RedisWorkerCommandTest extends WallabagCoreTestCase { @@ -19,7 +18,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase $this->expectExceptionMessage('Not enough arguments (missing: "serviceName")'); $application = new Application($this->getClient()->getKernel()); - $application->add(new RedisWorkerCommand()); $command = $application->find('wallabag:import:redis-worker'); @@ -35,7 +33,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase $this->expectExceptionMessage('No queue or consumer found for service name'); $application = new Application($this->getClient()->getKernel()); - $application->add(new RedisWorkerCommand()); $command = $application->find('wallabag:import:redis-worker'); @@ -49,7 +46,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase public function testRunRedisWorkerCommand() { $application = new Application($this->getClient()->getKernel()); - $application->add(new RedisWorkerCommand()); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter(Client::class, true); From 17497275b2d956b692b173f2783e1b45bed80751 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 3 Sep 2022 02:21:43 +0200 Subject: [PATCH 4/5] Use find for remaining useless addition --- tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index a20a2fd3b..5ac86e05e 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -3,8 +3,6 @@ namespace Tests\Wallabag\CoreBundle\Command; use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; -use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; -use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -214,8 +212,7 @@ class InstallCommandTest extends WallabagCoreTestCase $application = new Application($this->getClient()->getKernel()); // drop database first, so the install command won't ask to reset things - $command = new DropDatabaseDoctrineCommand(); - $command->setApplication($application); + $command = $application->find('doctrine:database:drop'); $command->run(new ArrayInput([ 'command' => 'doctrine:database:drop', '--force' => true, @@ -223,8 +220,7 @@ class InstallCommandTest extends WallabagCoreTestCase $this->getClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->close(); - $command = new CreateDatabaseDoctrineCommand(); - $command->setApplication($application); + $command = $application->find('doctrine:database:create'); $command->run(new ArrayInput([ 'command' => 'doctrine:database:create', '--env' => 'test', From e32794e9d68ef2b212937651fcaa2bba00992667 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 3 Sep 2022 02:28:07 +0200 Subject: [PATCH 5/5] Remove useless command input parameter --- .../Command/CleanDuplicatesCommandTest.php | 7 +---- .../CoreBundle/Command/ExportCommandTest.php | 7 +---- .../Command/GenerateUrlHashesCommandTest.php | 7 +---- .../CoreBundle/Command/InstallCommandTest.php | 28 ++++--------------- .../Command/ListUserCommandTest.php | 7 +---- .../Command/ReloadEntryCommandTest.php | 6 +--- .../Command/ShowUserCommandTest.php | 7 +---- .../CoreBundle/Command/TagAllCommandTest.php | 6 +--- .../Command/ImportCommandTest.php | 8 +----- .../Command/RedisWorkerCommandTest.php | 6 +--- 10 files changed, 15 insertions(+), 74 deletions(-) diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php index 29f8cd294..354950030 100644 --- a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php @@ -18,9 +18,7 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:clean-duplicates'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); $this->assertStringContainsString('Cleaning through 3 user accounts', $tester->getDisplay()); $this->assertStringContainsString('Finished cleaning. 0 duplicates found in total', $tester->getDisplay()); @@ -34,7 +32,6 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'unknown', ]); @@ -49,7 +46,6 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); @@ -89,7 +85,6 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 4e8d4c0d0..ef2c8cd66 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -19,9 +19,7 @@ class ExportCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:export'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); } public function testExportCommandWithBadUsername() @@ -32,7 +30,6 @@ class ExportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'unknown', ]); @@ -47,7 +44,6 @@ class ExportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); @@ -64,7 +60,6 @@ class ExportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', 'filepath' => 'specialexport.json', ]); diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php index d09515804..d76cc4b39 100644 --- a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php @@ -18,9 +18,7 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:generate-hashed-urls'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); $this->assertStringContainsString('Generating hashed urls for "3" users', $tester->getDisplay()); $this->assertStringContainsString('Finished generated hashed urls', $tester->getDisplay()); @@ -34,7 +32,6 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'unknown', ]); @@ -49,7 +46,6 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); @@ -78,7 +74,6 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 5ac86e05e..40f01f1e3 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -98,9 +98,7 @@ class InstallCommandTest extends WallabagCoreTestCase 'password_' . uniqid('', true), // password 'email_' . uniqid('', true) . '@wallabag.it', // email ]); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay()); @@ -124,7 +122,6 @@ class InstallCommandTest extends WallabagCoreTestCase 'email_' . uniqid('', true) . '@wallabag.it', // email ]); $tester->execute([ - 'command' => $command->getName(), '--reset' => true, ]); @@ -151,7 +148,6 @@ class InstallCommandTest extends WallabagCoreTestCase // drop database first, so the install command won't ask to reset things $command = $application->find('doctrine:database:drop'); $command->run(new ArrayInput([ - 'command' => 'doctrine:database:drop', '--force' => true, ]), new NullOutput()); @@ -168,9 +164,7 @@ class InstallCommandTest extends WallabagCoreTestCase 'password_' . uniqid('', true), // password 'email_' . uniqid('', true) . '@wallabag.it', // email ]); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay()); @@ -195,9 +189,7 @@ class InstallCommandTest extends WallabagCoreTestCase 'y', // do want to reset the schema 'n', // don't want to create a new user ]); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay()); @@ -214,17 +206,13 @@ class InstallCommandTest extends WallabagCoreTestCase // drop database first, so the install command won't ask to reset things $command = $application->find('doctrine:database:drop'); $command->run(new ArrayInput([ - 'command' => 'doctrine:database:drop', '--force' => true, ]), new NullOutput()); $this->getClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->close(); $command = $application->find('doctrine:database:create'); - $command->run(new ArrayInput([ - 'command' => 'doctrine:database:create', - '--env' => 'test', - ]), new NullOutput()); + $command->run(new ArrayInput([]), new NullOutput()); $command = $application->find('wallabag:install'); @@ -233,9 +221,7 @@ class InstallCommandTest extends WallabagCoreTestCase 'n', // don't want to reset the entire database 'n', // don't want to create a new user ]); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay()); @@ -254,9 +240,7 @@ class InstallCommandTest extends WallabagCoreTestCase $command->disableRunOtherCommands(); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ], [ + $tester->execute([], [ 'interactive' => false, ]); diff --git a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php index 69696bdc3..05d73aa4b 100644 --- a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php @@ -15,9 +15,7 @@ class ListUserCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:user:list'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); $this->assertStringContainsString('3/3 user(s) displayed.', $tester->getDisplay()); } @@ -30,7 +28,6 @@ class ListUserCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), '--limit' => 2, ]); @@ -45,7 +42,6 @@ class ListUserCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'search' => 'boss', ]); @@ -60,7 +56,6 @@ class ListUserCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'search' => 'bo', '--limit' => 1, ]); diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php index 45cacf117..a91a7e561 100644 --- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php @@ -53,9 +53,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:entry:reload'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ], [ + $tester->execute([], [ 'interactive' => false, ]); @@ -81,7 +79,6 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:entry:reload'); $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ], [ 'interactive' => false, @@ -105,7 +102,6 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:entry:reload'); $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'empty', ], [ 'interactive' => false, diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index 51f8b2eb7..d2bb583a3 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php @@ -21,9 +21,7 @@ class ShowUserCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:user:show'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); } public function testRunShowUserCommandWithBadUsername() @@ -34,7 +32,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'unknown', ]); @@ -49,7 +46,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); @@ -81,7 +77,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php index 4fea25aae..d7b3553ac 100644 --- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php @@ -19,9 +19,7 @@ class TagAllCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:tag:all'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); } public function testRunTagAllCommandWithBadUsername() @@ -32,7 +30,6 @@ class TagAllCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'unknown', ]); @@ -47,7 +44,6 @@ class TagAllCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', ]); diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index 36ee76dbf..ec3df0f7a 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -21,9 +21,7 @@ class ImportCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:import'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); } public function testRunImportCommandWithoutFilepath() @@ -37,7 +35,6 @@ class ImportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', 'filepath' => 1, ]); @@ -53,7 +50,6 @@ class ImportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'random', 'filepath' => './', ]); @@ -67,7 +63,6 @@ class ImportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => 'admin', 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', '--importer' => 'v2', @@ -87,7 +82,6 @@ class ImportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'username' => $this->getLoggedInUserId(), 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', '--useUserId' => true, diff --git a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php index a8c79dc0e..aebeaab5d 100644 --- a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php @@ -22,9 +22,7 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:import:redis-worker'); $tester = new CommandTester($command); - $tester->execute([ - 'command' => $command->getName(), - ]); + $tester->execute([]); } public function testRunRedisWorkerCommandWithBadService() @@ -38,7 +36,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'serviceName' => 'YOMONSERVICE', ]); } @@ -60,7 +57,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ - 'command' => $command->getName(), 'serviceName' => 'readability', '--maxIterations' => 1, ]);