mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 11:01:04 +00:00
Merge pull request #5954 from yguedidi/rework-command-tests
Rework command tests
This commit is contained in:
commit
0883bda18d
12 changed files with 44 additions and 165 deletions
|
@ -26,21 +26,28 @@ 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',
|
||||
];
|
||||
|
||||
private bool $runOtherCommands = true;
|
||||
|
||||
public function disableRunOtherCommands(): void
|
||||
{
|
||||
$this->runOtherCommands = false;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
|
@ -74,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.');
|
||||
|
||||
|
@ -174,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.');
|
||||
|
||||
|
@ -242,7 +249,7 @@ class InstallCommand extends ContainerAwareCommand
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function setupAdmin()
|
||||
private function setupAdmin()
|
||||
{
|
||||
$this->io->section('Step 3 of 4: Administration setup.');
|
||||
|
||||
|
@ -277,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);
|
||||
|
@ -313,8 +320,12 @@ 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;
|
||||
}
|
||||
|
||||
$parameters = array_merge(
|
||||
['command' => $command],
|
||||
$parameters,
|
||||
|
|
|
@ -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,14 +14,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
|
|||
public function testRunCleanDuplicates()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new CleanDuplicatesCommand());
|
||||
|
||||
$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());
|
||||
|
@ -31,13 +27,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
|
|||
public function testRunCleanDuplicatesCommandWithBadUsername()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new CleanDuplicatesCommand());
|
||||
|
||||
$command = $application->find('wallabag:clean-duplicates');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'unknown',
|
||||
]);
|
||||
|
||||
|
@ -47,13 +41,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
|
|||
public function testRunCleanDuplicatesCommandForUser()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new CleanDuplicatesCommand());
|
||||
|
||||
$command = $application->find('wallabag:clean-duplicates');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
@ -88,13 +80,11 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
|
|||
$this->assertCount(2, $nbEntries);
|
||||
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new CleanDuplicatesCommand());
|
||||
|
||||
$command = $application->find('wallabag:clean-duplicates');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
|
|
@ -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,26 +15,21 @@ 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');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
$tester->execute([]);
|
||||
}
|
||||
|
||||
public function testExportCommandWithBadUsername()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ExportCommand());
|
||||
|
||||
$command = $application->find('wallabag:export');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'unknown',
|
||||
]);
|
||||
|
||||
|
@ -45,13 +39,11 @@ class ExportCommandTest extends WallabagCoreTestCase
|
|||
public function testExportCommand()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ExportCommand());
|
||||
|
||||
$command = $application->find('wallabag:export');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
@ -63,13 +55,11 @@ class ExportCommandTest extends WallabagCoreTestCase
|
|||
public function testExportCommandWithSpecialPath()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ExportCommand());
|
||||
|
||||
$command = $application->find('wallabag:export');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
'filepath' => 'specialexport.json',
|
||||
]);
|
||||
|
|
|
@ -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,14 +14,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
|
|||
public function testRunGenerateUrlHashesCommand()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new GenerateUrlHashesCommand());
|
||||
|
||||
$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());
|
||||
|
@ -31,13 +27,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
|
|||
public function testRunGenerateUrlHashesCommandWithBadUsername()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new GenerateUrlHashesCommand());
|
||||
|
||||
$command = $application->find('wallabag:generate-hashed-urls');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'unknown',
|
||||
]);
|
||||
|
||||
|
@ -47,13 +41,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
|
|||
public function testRunGenerateUrlHashesCommandForUser()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new GenerateUrlHashesCommand());
|
||||
|
||||
$command = $application->find('wallabag:generate-hashed-urls');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
@ -77,13 +69,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase
|
|||
$em->flush();
|
||||
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new GenerateUrlHashesCommand());
|
||||
|
||||
$command = $application->find('wallabag:generate-hashed-urls');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
|
|
@ -3,9 +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\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
||||
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\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 +85,10 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
public function testRunInstallCommand()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new InstallCommandMock());
|
||||
|
||||
/** @var InstallCommand $command */
|
||||
$command = $application->find('wallabag:install');
|
||||
$command->disableRunOtherCommands();
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->setInputs([
|
||||
|
@ -101,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());
|
||||
|
@ -114,9 +109,10 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
public function testRunInstallCommandWithReset()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new InstallCommandMock());
|
||||
|
||||
/** @var InstallCommand $command */
|
||||
$command = $application->find('wallabag:install');
|
||||
$command->disableRunOtherCommands();
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->setInputs([
|
||||
|
@ -126,7 +122,6 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
'email_' . uniqid('', true) . '@wallabag.it', // email
|
||||
]);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'--reset' => true,
|
||||
]);
|
||||
|
||||
|
@ -149,19 +144,16 @@ 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');
|
||||
$command->run(new ArrayInput([
|
||||
'command' => 'doctrine:database:drop',
|
||||
'--force' => true,
|
||||
]), new NullOutput());
|
||||
|
||||
// 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');
|
||||
|
||||
|
@ -172,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());
|
||||
|
@ -188,9 +178,10 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
public function testRunInstallCommandChooseResetSchema()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new InstallCommandMock());
|
||||
|
||||
/** @var InstallCommand $command */
|
||||
$command = $application->find('wallabag:install');
|
||||
$command->disableRunOtherCommands();
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->setInputs([
|
||||
|
@ -198,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());
|
||||
|
@ -213,27 +202,17 @@ 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();
|
||||
$command->setApplication($application);
|
||||
$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 = new CreateDatabaseDoctrineCommand();
|
||||
$command->setApplication($application);
|
||||
$command->run(new ArrayInput([
|
||||
'command' => 'doctrine:database:create',
|
||||
'--env' => 'test',
|
||||
]), new NullOutput());
|
||||
$command = $application->find('doctrine:database:create');
|
||||
$command->run(new ArrayInput([]), new NullOutput());
|
||||
|
||||
$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 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());
|
||||
|
@ -257,14 +234,13 @@ class InstallCommandTest extends WallabagCoreTestCase
|
|||
public function testRunInstallCommandNoInteraction()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new InstallCommandMock());
|
||||
|
||||
/** @var InstallCommand $command */
|
||||
$command = $application->find('wallabag:install');
|
||||
$command->disableRunOtherCommands();
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
], [
|
||||
$tester->execute([], [
|
||||
'interactive' => false,
|
||||
]);
|
||||
|
||||
|
|
|
@ -5,21 +5,17 @@ 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');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertStringContainsString('3/3 user(s) displayed.', $tester->getDisplay());
|
||||
}
|
||||
|
@ -27,13 +23,11 @@ class ListUserCommandTest extends WallabagCoreTestCase
|
|||
public function testRunListUserCommandWithLimit()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ListUserCommand());
|
||||
|
||||
$command = $application->find('wallabag:user:list');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'--limit' => 2,
|
||||
]);
|
||||
|
||||
|
@ -43,13 +37,11 @@ class ListUserCommandTest extends WallabagCoreTestCase
|
|||
public function testRunListUserCommandWithSearch()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ListUserCommand());
|
||||
|
||||
$command = $application->find('wallabag:user:list');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'search' => 'boss',
|
||||
]);
|
||||
|
||||
|
@ -59,13 +51,11 @@ class ListUserCommandTest extends WallabagCoreTestCase
|
|||
public function testRunListUserCommandWithSearchAndLimit()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ListUserCommand());
|
||||
|
||||
$command = $application->find('wallabag:user:list');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'search' => 'bo',
|
||||
'--limit' => 1,
|
||||
]);
|
||||
|
|
|
@ -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,13 +50,10 @@ 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);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
], [
|
||||
$tester->execute([], [
|
||||
'interactive' => false,
|
||||
]);
|
||||
|
||||
|
@ -79,12 +75,10 @@ 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);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
], [
|
||||
'interactive' => false,
|
||||
|
@ -104,12 +98,10 @@ 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);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'empty',
|
||||
], [
|
||||
'interactive' => false,
|
||||
|
|
|
@ -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,26 +17,21 @@ 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');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
$tester->execute([]);
|
||||
}
|
||||
|
||||
public function testRunShowUserCommandWithBadUsername()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ShowUserCommand());
|
||||
|
||||
$command = $application->find('wallabag:user:show');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'unknown',
|
||||
]);
|
||||
|
||||
|
@ -47,13 +41,11 @@ class ShowUserCommandTest extends WallabagCoreTestCase
|
|||
public function testRunShowUserCommandForUser()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ShowUserCommand());
|
||||
|
||||
$command = $application->find('wallabag:user:show');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
@ -80,13 +72,11 @@ class ShowUserCommandTest extends WallabagCoreTestCase
|
|||
$em->flush();
|
||||
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ShowUserCommand());
|
||||
|
||||
$command = $application->find('wallabag:user:show');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
|
|
@ -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,26 +15,21 @@ 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');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
$tester->execute([]);
|
||||
}
|
||||
|
||||
public function testRunTagAllCommandWithBadUsername()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new TagAllCommand());
|
||||
|
||||
$command = $application->find('wallabag:tag:all');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'unknown',
|
||||
]);
|
||||
|
||||
|
@ -45,13 +39,11 @@ class TagAllCommandTest extends WallabagCoreTestCase
|
|||
public function testRunTagAllCommand()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new TagAllCommand());
|
||||
|
||||
$command = $application->find('wallabag:tag:all');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
]);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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,14 +17,11 @@ class ImportCommandTest extends WallabagCoreTestCase
|
|||
$this->expectExceptionMessage('Not enough arguments');
|
||||
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ImportCommand());
|
||||
|
||||
$command = $application->find('wallabag:import');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
$tester->execute([]);
|
||||
}
|
||||
|
||||
public function testRunImportCommandWithoutFilepath()
|
||||
|
@ -34,13 +30,11 @@ class ImportCommandTest extends WallabagCoreTestCase
|
|||
$this->expectExceptionMessage('not found');
|
||||
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ImportCommand());
|
||||
|
||||
$command = $application->find('wallabag:import');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'admin',
|
||||
'filepath' => 1,
|
||||
]);
|
||||
|
@ -51,13 +45,11 @@ class ImportCommandTest extends WallabagCoreTestCase
|
|||
$this->expectException(NoResultException::class);
|
||||
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ImportCommand());
|
||||
|
||||
$command = $application->find('wallabag:import');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'username' => 'random',
|
||||
'filepath' => './',
|
||||
]);
|
||||
|
@ -66,13 +58,11 @@ class ImportCommandTest extends WallabagCoreTestCase
|
|||
public function testRunImportCommand()
|
||||
{
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ImportCommand());
|
||||
|
||||
$command = $application->find('wallabag:import');
|
||||
|
||||
$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,13 +77,11 @@ class ImportCommandTest extends WallabagCoreTestCase
|
|||
$this->logInAs('admin');
|
||||
|
||||
$application = new Application($this->getClient()->getKernel());
|
||||
$application->add(new ImportCommand());
|
||||
|
||||
$command = $application->find('wallabag:import');
|
||||
|
||||
$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,
|
||||
|
|
|
@ -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,14 +18,11 @@ 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');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
$tester->execute([]);
|
||||
}
|
||||
|
||||
public function testRunRedisWorkerCommandWithBadService()
|
||||
|
@ -35,13 +31,11 @@ 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');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'serviceName' => 'YOMONSERVICE',
|
||||
]);
|
||||
}
|
||||
|
@ -49,7 +43,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);
|
||||
|
@ -64,7 +57,6 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase
|
|||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute([
|
||||
'command' => $command->getName(),
|
||||
'serviceName' => 'readability',
|
||||
'--maxIterations' => 1,
|
||||
]);
|
||||
|
|
Loading…
Reference in a new issue