Merge pull request #5954 from yguedidi/rework-command-tests

Rework command tests
This commit is contained in:
Jérémy Benoist 2022-11-03 09:01:21 +01:00 committed by GitHub
commit 0883bda18d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 44 additions and 165 deletions

View file

@ -26,21 +26,28 @@ class InstallCommand extends ContainerAwareCommand
/** /**
* @var InputInterface * @var InputInterface
*/ */
protected $defaultInput; private $defaultInput;
/** /**
* @var SymfonyStyle * @var SymfonyStyle
*/ */
protected $io; private $io;
/** /**
* @var array * @var array
*/ */
protected $functionExists = [ private $functionExists = [
'curl_exec', 'curl_exec',
'curl_multi_init', 'curl_multi_init',
]; ];
private bool $runOtherCommands = true;
public function disableRunOtherCommands(): void
{
$this->runOtherCommands = false;
}
protected function configure() protected function configure()
{ {
$this $this
@ -74,7 +81,7 @@ class InstallCommand extends ContainerAwareCommand
$this->io->success('You can now configure your web server, see https://doc.wallabag.org'); $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.'); $this->io->section('Step 1 of 4: Checking system requirements.');
@ -174,7 +181,7 @@ class InstallCommand extends ContainerAwareCommand
return $this; return $this;
} }
protected function setupDatabase() private function setupDatabase()
{ {
$this->io->section('Step 2 of 4: Setting up database.'); $this->io->section('Step 2 of 4: Setting up database.');
@ -242,7 +249,7 @@ class InstallCommand extends ContainerAwareCommand
return $this; return $this;
} }
protected function setupAdmin() private function setupAdmin()
{ {
$this->io->section('Step 3 of 4: Administration setup.'); $this->io->section('Step 3 of 4: Administration setup.');
@ -277,7 +284,7 @@ class InstallCommand extends ContainerAwareCommand
return $this; return $this;
} }
protected function setupConfig() private function setupConfig()
{ {
$this->io->section('Step 4 of 4: Config setup.'); $this->io->section('Step 4 of 4: Config setup.');
$em = $this->getContainer()->get(EntityManagerInterface::class); $em = $this->getContainer()->get(EntityManagerInterface::class);
@ -313,8 +320,12 @@ class InstallCommand extends ContainerAwareCommand
* @param string $command * @param string $command
* @param array $parameters Parameters to this command (usually 'force' => true) * @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;
}
$parameters = array_merge( $parameters = array_merge(
['command' => $command], ['command' => $command],
$parameters, $parameters,

View file

@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\CleanDuplicatesCommand;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Entity\User;
@ -15,14 +14,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
public function testRunCleanDuplicates() public function testRunCleanDuplicates()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new CleanDuplicatesCommand());
$command = $application->find('wallabag:clean-duplicates'); $command = $application->find('wallabag:clean-duplicates');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
$this->assertStringContainsString('Cleaning through 3 user accounts', $tester->getDisplay()); $this->assertStringContainsString('Cleaning through 3 user accounts', $tester->getDisplay());
$this->assertStringContainsString('Finished cleaning. 0 duplicates found in total', $tester->getDisplay()); $this->assertStringContainsString('Finished cleaning. 0 duplicates found in total', $tester->getDisplay());
@ -31,13 +27,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
public function testRunCleanDuplicatesCommandWithBadUsername() public function testRunCleanDuplicatesCommandWithBadUsername()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new CleanDuplicatesCommand());
$command = $application->find('wallabag:clean-duplicates'); $command = $application->find('wallabag:clean-duplicates');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'unknown', 'username' => 'unknown',
]); ]);
@ -47,13 +41,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
public function testRunCleanDuplicatesCommandForUser() public function testRunCleanDuplicatesCommandForUser()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new CleanDuplicatesCommand());
$command = $application->find('wallabag:clean-duplicates'); $command = $application->find('wallabag:clean-duplicates');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);
@ -88,13 +80,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
$this->assertCount(2, $nbEntries); $this->assertCount(2, $nbEntries);
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new CleanDuplicatesCommand());
$command = $application->find('wallabag:clean-duplicates'); $command = $application->find('wallabag:clean-duplicates');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);

View file

@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\ExportCommand;
class ExportCommandTest extends WallabagCoreTestCase class ExportCommandTest extends WallabagCoreTestCase
{ {
@ -16,26 +15,21 @@ class ExportCommandTest extends WallabagCoreTestCase
$this->expectExceptionMessage('Not enough arguments (missing: "username")'); $this->expectExceptionMessage('Not enough arguments (missing: "username")');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ExportCommand());
$command = $application->find('wallabag:export'); $command = $application->find('wallabag:export');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
} }
public function testExportCommandWithBadUsername() public function testExportCommandWithBadUsername()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ExportCommand());
$command = $application->find('wallabag:export'); $command = $application->find('wallabag:export');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'unknown', 'username' => 'unknown',
]); ]);
@ -45,13 +39,11 @@ class ExportCommandTest extends WallabagCoreTestCase
public function testExportCommand() public function testExportCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ExportCommand());
$command = $application->find('wallabag:export'); $command = $application->find('wallabag:export');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);
@ -63,13 +55,11 @@ class ExportCommandTest extends WallabagCoreTestCase
public function testExportCommandWithSpecialPath() public function testExportCommandWithSpecialPath()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ExportCommand());
$command = $application->find('wallabag:export'); $command = $application->find('wallabag:export');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
'filepath' => 'specialexport.json', 'filepath' => 'specialexport.json',
]); ]);

View file

@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\GenerateUrlHashesCommand;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Entity\User;
@ -15,14 +14,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
public function testRunGenerateUrlHashesCommand() public function testRunGenerateUrlHashesCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new GenerateUrlHashesCommand());
$command = $application->find('wallabag:generate-hashed-urls'); $command = $application->find('wallabag:generate-hashed-urls');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
$this->assertStringContainsString('Generating hashed urls for "3" users', $tester->getDisplay()); $this->assertStringContainsString('Generating hashed urls for "3" users', $tester->getDisplay());
$this->assertStringContainsString('Finished generated hashed urls', $tester->getDisplay()); $this->assertStringContainsString('Finished generated hashed urls', $tester->getDisplay());
@ -31,13 +27,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
public function testRunGenerateUrlHashesCommandWithBadUsername() public function testRunGenerateUrlHashesCommandWithBadUsername()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new GenerateUrlHashesCommand());
$command = $application->find('wallabag:generate-hashed-urls'); $command = $application->find('wallabag:generate-hashed-urls');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'unknown', 'username' => 'unknown',
]); ]);
@ -47,13 +41,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
public function testRunGenerateUrlHashesCommandForUser() public function testRunGenerateUrlHashesCommandForUser()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new GenerateUrlHashesCommand());
$command = $application->find('wallabag:generate-hashed-urls'); $command = $application->find('wallabag:generate-hashed-urls');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);
@ -77,13 +69,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
$em->flush(); $em->flush();
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new GenerateUrlHashesCommand());
$command = $application->find('wallabag:generate-hashed-urls'); $command = $application->find('wallabag:generate-hashed-urls');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);

View file

@ -3,9 +3,6 @@
namespace Tests\Wallabag\CoreBundle\Command; namespace Tests\Wallabag\CoreBundle\Command;
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; 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\Connection;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SqlitePlatform;
@ -14,7 +11,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\Mock\InstallCommandMock;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\InstallCommand; use Wallabag\CoreBundle\Command\InstallCommand;
@ -89,9 +85,10 @@ class InstallCommandTest extends WallabagCoreTestCase
public function testRunInstallCommand() public function testRunInstallCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new InstallCommandMock());
/** @var InstallCommand $command */
$command = $application->find('wallabag:install'); $command = $application->find('wallabag:install');
$command->disableRunOtherCommands();
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->setInputs([ $tester->setInputs([
@ -101,9 +98,7 @@ class InstallCommandTest extends WallabagCoreTestCase
'password_' . uniqid('', true), // password 'password_' . uniqid('', true), // password
'email_' . uniqid('', true) . '@wallabag.it', // email 'email_' . uniqid('', true) . '@wallabag.it', // email
]); ]);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
$this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay());
$this->assertStringContainsString('Setting up database.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay());
@ -114,9 +109,10 @@ class InstallCommandTest extends WallabagCoreTestCase
public function testRunInstallCommandWithReset() public function testRunInstallCommandWithReset()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new InstallCommandMock());
/** @var InstallCommand $command */
$command = $application->find('wallabag:install'); $command = $application->find('wallabag:install');
$command->disableRunOtherCommands();
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->setInputs([ $tester->setInputs([
@ -126,7 +122,6 @@ class InstallCommandTest extends WallabagCoreTestCase
'email_' . uniqid('', true) . '@wallabag.it', // email 'email_' . uniqid('', true) . '@wallabag.it', // email
]); ]);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'--reset' => true, '--reset' => true,
]); ]);
@ -149,19 +144,16 @@ class InstallCommandTest extends WallabagCoreTestCase
} }
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new DropDatabaseDoctrineCommand());
// drop database first, so the install command won't ask to reset things // drop database first, so the install command won't ask to reset things
$command = $application->find('doctrine:database:drop'); $command = $application->find('doctrine:database:drop');
$command->run(new ArrayInput([ $command->run(new ArrayInput([
'command' => 'doctrine:database:drop',
'--force' => true, '--force' => true,
]), new NullOutput()); ]), new NullOutput());
// start a new application to avoid lagging connexion to pgsql // start a new application to avoid lagging connexion to pgsql
$client = static::createClient(); $client = static::createClient();
$application = new Application($client->getKernel()); $application = new Application($client->getKernel());
$application->add(new InstallCommand());
$command = $application->find('wallabag:install'); $command = $application->find('wallabag:install');
@ -172,9 +164,7 @@ class InstallCommandTest extends WallabagCoreTestCase
'password_' . uniqid('', true), // password 'password_' . uniqid('', true), // password
'email_' . uniqid('', true) . '@wallabag.it', // email 'email_' . uniqid('', true) . '@wallabag.it', // email
]); ]);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
$this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay());
$this->assertStringContainsString('Setting up database.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay());
@ -188,9 +178,10 @@ class InstallCommandTest extends WallabagCoreTestCase
public function testRunInstallCommandChooseResetSchema() public function testRunInstallCommandChooseResetSchema()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new InstallCommandMock());
/** @var InstallCommand $command */
$command = $application->find('wallabag:install'); $command = $application->find('wallabag:install');
$command->disableRunOtherCommands();
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->setInputs([ $tester->setInputs([
@ -198,9 +189,7 @@ class InstallCommandTest extends WallabagCoreTestCase
'y', // do want to reset the schema 'y', // do want to reset the schema
'n', // don't want to create a new user 'n', // don't want to create a new user
]); ]);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
$this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay());
$this->assertStringContainsString('Setting up database.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay());
@ -213,27 +202,17 @@ class InstallCommandTest extends WallabagCoreTestCase
public function testRunInstallCommandChooseNothing() public function testRunInstallCommandChooseNothing()
{ {
$application = new Application($this->getClient()->getKernel()); $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 // drop database first, so the install command won't ask to reset things
$command = new DropDatabaseDoctrineCommand(); $command = $application->find('doctrine:database:drop');
$command->setApplication($application);
$command->run(new ArrayInput([ $command->run(new ArrayInput([
'command' => 'doctrine:database:drop',
'--force' => true, '--force' => true,
]), new NullOutput()); ]), new NullOutput());
$this->getClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->close(); $this->getClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->close();
$command = new CreateDatabaseDoctrineCommand(); $command = $application->find('doctrine:database:create');
$command->setApplication($application); $command->run(new ArrayInput([]), new NullOutput());
$command->run(new ArrayInput([
'command' => 'doctrine:database:create',
'--env' => 'test',
]), new NullOutput());
$command = $application->find('wallabag:install'); $command = $application->find('wallabag:install');
@ -242,9 +221,7 @@ class InstallCommandTest extends WallabagCoreTestCase
'n', // don't want to reset the entire database 'n', // don't want to reset the entire database
'n', // don't want to create a new user 'n', // don't want to create a new user
]); ]);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
$this->assertStringContainsString('Checking system requirements.', $tester->getDisplay()); $this->assertStringContainsString('Checking system requirements.', $tester->getDisplay());
$this->assertStringContainsString('Setting up database.', $tester->getDisplay()); $this->assertStringContainsString('Setting up database.', $tester->getDisplay());
@ -257,14 +234,13 @@ class InstallCommandTest extends WallabagCoreTestCase
public function testRunInstallCommandNoInteraction() public function testRunInstallCommandNoInteraction()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new InstallCommandMock());
/** @var InstallCommand $command */
$command = $application->find('wallabag:install'); $command = $application->find('wallabag:install');
$command->disableRunOtherCommands();
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([], [
'command' => $command->getName(),
], [
'interactive' => false, 'interactive' => false,
]); ]);

View file

@ -5,21 +5,17 @@ namespace Tests\Wallabag\CoreBundle\Command;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\ListUserCommand;
class ListUserCommandTest extends WallabagCoreTestCase class ListUserCommandTest extends WallabagCoreTestCase
{ {
public function testRunListUserCommand() public function testRunListUserCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ListUserCommand());
$command = $application->find('wallabag:user:list'); $command = $application->find('wallabag:user:list');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
$this->assertStringContainsString('3/3 user(s) displayed.', $tester->getDisplay()); $this->assertStringContainsString('3/3 user(s) displayed.', $tester->getDisplay());
} }
@ -27,13 +23,11 @@ class ListUserCommandTest extends WallabagCoreTestCase
public function testRunListUserCommandWithLimit() public function testRunListUserCommandWithLimit()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ListUserCommand());
$command = $application->find('wallabag:user:list'); $command = $application->find('wallabag:user:list');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'--limit' => 2, '--limit' => 2,
]); ]);
@ -43,13 +37,11 @@ class ListUserCommandTest extends WallabagCoreTestCase
public function testRunListUserCommandWithSearch() public function testRunListUserCommandWithSearch()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ListUserCommand());
$command = $application->find('wallabag:user:list'); $command = $application->find('wallabag:user:list');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'search' => 'boss', 'search' => 'boss',
]); ]);
@ -59,13 +51,11 @@ class ListUserCommandTest extends WallabagCoreTestCase
public function testRunListUserCommandWithSearchAndLimit() public function testRunListUserCommandWithSearchAndLimit()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ListUserCommand());
$command = $application->find('wallabag:user:list'); $command = $application->find('wallabag:user:list');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'search' => 'bo', 'search' => 'bo',
'--limit' => 1, '--limit' => 1,
]); ]);

View file

@ -5,7 +5,6 @@ namespace Tests\Wallabag\CoreBundle\Command;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\ReloadEntryCommand;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
class ReloadEntryCommandTest extends WallabagCoreTestCase class ReloadEntryCommandTest extends WallabagCoreTestCase
@ -51,13 +50,10 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
public function testRunReloadEntryCommand() public function testRunReloadEntryCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ReloadEntryCommand());
$command = $application->find('wallabag:entry:reload'); $command = $application->find('wallabag:entry:reload');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([], [
'command' => $command->getName(),
], [
'interactive' => false, 'interactive' => false,
]); ]);
@ -79,12 +75,10 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
public function testRunReloadEntryWithUsernameCommand() public function testRunReloadEntryWithUsernameCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ReloadEntryCommand());
$command = $application->find('wallabag:entry:reload'); $command = $application->find('wallabag:entry:reload');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
], [ ], [
'interactive' => false, 'interactive' => false,
@ -104,12 +98,10 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
public function testRunReloadEntryWithoutEntryCommand() public function testRunReloadEntryWithoutEntryCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ReloadEntryCommand());
$command = $application->find('wallabag:entry:reload'); $command = $application->find('wallabag:entry:reload');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'empty', 'username' => 'empty',
], [ ], [
'interactive' => false, 'interactive' => false,

View file

@ -7,7 +7,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\ShowUserCommand;
use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Entity\User;
class ShowUserCommandTest extends WallabagCoreTestCase class ShowUserCommandTest extends WallabagCoreTestCase
@ -18,26 +17,21 @@ class ShowUserCommandTest extends WallabagCoreTestCase
$this->expectExceptionMessage('Not enough arguments'); $this->expectExceptionMessage('Not enough arguments');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ShowUserCommand());
$command = $application->find('wallabag:user:show'); $command = $application->find('wallabag:user:show');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
} }
public function testRunShowUserCommandWithBadUsername() public function testRunShowUserCommandWithBadUsername()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ShowUserCommand());
$command = $application->find('wallabag:user:show'); $command = $application->find('wallabag:user:show');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'unknown', 'username' => 'unknown',
]); ]);
@ -47,13 +41,11 @@ class ShowUserCommandTest extends WallabagCoreTestCase
public function testRunShowUserCommandForUser() public function testRunShowUserCommandForUser()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ShowUserCommand());
$command = $application->find('wallabag:user:show'); $command = $application->find('wallabag:user:show');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);
@ -80,13 +72,11 @@ class ShowUserCommandTest extends WallabagCoreTestCase
$em->flush(); $em->flush();
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ShowUserCommand());
$command = $application->find('wallabag:user:show'); $command = $application->find('wallabag:user:show');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);

View file

@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\TagAllCommand;
class TagAllCommandTest extends WallabagCoreTestCase class TagAllCommandTest extends WallabagCoreTestCase
{ {
@ -16,26 +15,21 @@ class TagAllCommandTest extends WallabagCoreTestCase
$this->expectExceptionMessage('Not enough arguments (missing: "username")'); $this->expectExceptionMessage('Not enough arguments (missing: "username")');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new TagAllCommand());
$command = $application->find('wallabag:tag:all'); $command = $application->find('wallabag:tag:all');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
} }
public function testRunTagAllCommandWithBadUsername() public function testRunTagAllCommandWithBadUsername()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new TagAllCommand());
$command = $application->find('wallabag:tag:all'); $command = $application->find('wallabag:tag:all');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'unknown', 'username' => 'unknown',
]); ]);
@ -45,13 +39,11 @@ class TagAllCommandTest extends WallabagCoreTestCase
public function testRunTagAllCommand() public function testRunTagAllCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new TagAllCommand());
$command = $application->find('wallabag:tag:all'); $command = $application->find('wallabag:tag:all');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
]); ]);

View file

@ -1,22 +0,0 @@
<?php
namespace Tests\Wallabag\CoreBundle\Mock;
use Wallabag\CoreBundle\Command\InstallCommand;
/**
* This mock aims to speed the test of InstallCommand by avoid calling external command
* like all doctrine commands.
*
* This speed the test but as a downside, it doesn't allow to fully test the InstallCommand
*
* Launching tests to avoid doctrine command:
* phpunit --exclude-group command-doctrine
*/
class InstallCommandMock extends InstallCommand
{
protected function runCommand($command, $parameters = [])
{
return $this;
}
}

View file

@ -8,7 +8,6 @@ use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\ImportBundle\Command\ImportCommand;
class ImportCommandTest extends WallabagCoreTestCase class ImportCommandTest extends WallabagCoreTestCase
{ {
@ -18,14 +17,11 @@ class ImportCommandTest extends WallabagCoreTestCase
$this->expectExceptionMessage('Not enough arguments'); $this->expectExceptionMessage('Not enough arguments');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
$command = $application->find('wallabag:import'); $command = $application->find('wallabag:import');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
} }
public function testRunImportCommandWithoutFilepath() public function testRunImportCommandWithoutFilepath()
@ -34,13 +30,11 @@ class ImportCommandTest extends WallabagCoreTestCase
$this->expectExceptionMessage('not found'); $this->expectExceptionMessage('not found');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
$command = $application->find('wallabag:import'); $command = $application->find('wallabag:import');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
'filepath' => 1, 'filepath' => 1,
]); ]);
@ -51,13 +45,11 @@ class ImportCommandTest extends WallabagCoreTestCase
$this->expectException(NoResultException::class); $this->expectException(NoResultException::class);
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
$command = $application->find('wallabag:import'); $command = $application->find('wallabag:import');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'random', 'username' => 'random',
'filepath' => './', 'filepath' => './',
]); ]);
@ -66,13 +58,11 @@ class ImportCommandTest extends WallabagCoreTestCase
public function testRunImportCommand() public function testRunImportCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
$command = $application->find('wallabag:import'); $command = $application->find('wallabag:import');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => 'admin', 'username' => 'admin',
'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
'--importer' => 'v2', '--importer' => 'v2',
@ -87,13 +77,11 @@ class ImportCommandTest extends WallabagCoreTestCase
$this->logInAs('admin'); $this->logInAs('admin');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
$command = $application->find('wallabag:import'); $command = $application->find('wallabag:import');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'username' => $this->getLoggedInUserId(), 'username' => $this->getLoggedInUserId(),
'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
'--useUserId' => true, '--useUserId' => true,

View file

@ -9,7 +9,6 @@ use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\ImportBundle\Command\RedisWorkerCommand;
class RedisWorkerCommandTest extends WallabagCoreTestCase class RedisWorkerCommandTest extends WallabagCoreTestCase
{ {
@ -19,14 +18,11 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase
$this->expectExceptionMessage('Not enough arguments (missing: "serviceName")'); $this->expectExceptionMessage('Not enough arguments (missing: "serviceName")');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new RedisWorkerCommand());
$command = $application->find('wallabag:import:redis-worker'); $command = $application->find('wallabag:import:redis-worker');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([]);
'command' => $command->getName(),
]);
} }
public function testRunRedisWorkerCommandWithBadService() public function testRunRedisWorkerCommandWithBadService()
@ -35,13 +31,11 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase
$this->expectExceptionMessage('No queue or consumer found for service name'); $this->expectExceptionMessage('No queue or consumer found for service name');
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new RedisWorkerCommand());
$command = $application->find('wallabag:import:redis-worker'); $command = $application->find('wallabag:import:redis-worker');
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'serviceName' => 'YOMONSERVICE', 'serviceName' => 'YOMONSERVICE',
]); ]);
} }
@ -49,7 +43,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase
public function testRunRedisWorkerCommand() public function testRunRedisWorkerCommand()
{ {
$application = new Application($this->getClient()->getKernel()); $application = new Application($this->getClient()->getKernel());
$application->add(new RedisWorkerCommand());
$factory = new RedisMockFactory(); $factory = new RedisMockFactory();
$redisMock = $factory->getAdapter(Client::class, true); $redisMock = $factory->getAdapter(Client::class, true);
@ -64,7 +57,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute([ $tester->execute([
'command' => $command->getName(),
'serviceName' => 'readability', 'serviceName' => 'readability',
'--maxIterations' => 1, '--maxIterations' => 1,
]); ]);