Remove InstallCommandMock

This commit is contained in:
Yassine Guedidi 2022-09-03 02:17:36 +02:00 committed by Jérémy Benoist
parent c372d68cc1
commit 8f20df6559
3 changed files with 23 additions and 27 deletions

View File

@ -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,

View File

@ -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([

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;
}
}