wallabag/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php

270 lines
10 KiB
PHP
Raw Normal View History

<?php
namespace Wallabag\CoreBundle\Tests\Command;
2015-03-29 08:53:10 +00:00
use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
use Wallabag\CoreBundle\Command\InstallCommand;
use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
2015-02-22 22:29:48 +00:00
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
2015-03-29 08:53:10 +00:00
class InstallCommandTest extends WallabagCoreTestCase
{
2015-02-22 22:29:48 +00:00
public static function tearDownAfterClass()
{
$application = new Application(static::$kernel);
$application->setAutoExit(false);
$code = $application->run(new ArrayInput(array(
'command' => 'doctrine:fixtures:load',
'--no-interaction' => true,
'--env' => 'test',
)), new NullOutput());
}
public function testRunInstallCommand()
{
$this->container = static::$kernel->getContainer();
$application = new Application(static::$kernel);
$application->add(new InstallCommandMock());
$command = $application->find('wallabag:install');
2015-11-06 22:39:19 +00:00
// We mock the QuestionHelper
$question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
->disableOriginalConstructor()
->getMock();
2015-11-06 22:39:19 +00:00
$question->expects($this->any())
->method('ask')
2015-11-06 22:39:19 +00:00
->will($this->returnValue('yes_'.uniqid('', true)));
// We override the standard helper with our mock
2015-11-06 22:39:19 +00:00
$command->getHelperSet()->set($question, 'question');
$tester = new CommandTester($command);
$tester->execute(array(
'command' => $command->getName(),
));
$this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
$this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
$this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
$this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
}
2015-02-22 22:29:48 +00:00
public function testRunInstallCommandWithReset()
{
$this->container = static::$kernel->getContainer();
$application = new Application(static::$kernel);
$application->add(new InstallCommandMock());
2015-02-22 22:29:48 +00:00
$command = $application->find('wallabag:install');
2015-11-06 22:39:19 +00:00
// We mock the QuestionHelper
$question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
2015-02-22 22:29:48 +00:00
->disableOriginalConstructor()
->getMock();
2015-11-06 22:39:19 +00:00
$question->expects($this->any())
2015-02-22 22:29:48 +00:00
->method('ask')
2015-11-06 22:39:19 +00:00
->will($this->returnValue('yes_'.uniqid('', true)));
2015-02-22 22:29:48 +00:00
// We override the standard helper with our mock
2015-11-06 22:39:19 +00:00
$command->getHelperSet()->set($question, 'question');
2015-02-22 22:29:48 +00:00
$tester = new CommandTester($command);
$tester->execute(array(
'command' => $command->getName(),
'--reset' => true,
));
$this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
$this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
$this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
$this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
// we force to reset everything
$this->assertContains('Droping database, creating database and schema', $tester->getDisplay());
}
/**
* @group command-doctrine
*/
2015-02-22 22:29:48 +00:00
public function testRunInstallCommandWithDatabaseRemoved()
{
$this->container = static::$kernel->getContainer();
$application = new Application(static::$kernel);
$application->add(new InstallCommand());
$application->add(new DropDatabaseDoctrineCommand());
// drop database first, so the install command won't ask to reset things
$command = new DropDatabaseDoctrineCommand();
$command->setApplication($application);
$command->run(new ArrayInput(array(
'command' => 'doctrine:database:drop',
'--force' => true,
)), new NullOutput());
$command = $application->find('wallabag:install');
2015-11-06 22:39:19 +00:00
// We mock the QuestionHelper
$question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
2015-02-22 22:29:48 +00:00
->disableOriginalConstructor()
->getMock();
2015-11-06 22:39:19 +00:00
$question->expects($this->any())
2015-02-22 22:29:48 +00:00
->method('ask')
2015-11-06 22:39:19 +00:00
->will($this->returnValue('yes_'.uniqid('', true)));
2015-02-22 22:29:48 +00:00
// We override the standard helper with our mock
2015-11-06 22:39:19 +00:00
$command->getHelperSet()->set($question, 'question');
2015-02-22 22:29:48 +00:00
$tester = new CommandTester($command);
$tester->execute(array(
'command' => $command->getName(),
));
$this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
$this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
$this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
$this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
// the current database doesn't already exist
$this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
}
public function testRunInstallCommandChooseResetSchema()
{
$this->container = static::$kernel->getContainer();
$application = new Application(static::$kernel);
$application->add(new InstallCommandMock());
2015-02-22 22:29:48 +00:00
$command = $application->find('wallabag:install');
2015-11-06 22:39:19 +00:00
// We mock the QuestionHelper
$question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
2015-02-22 22:29:48 +00:00
->disableOriginalConstructor()
->getMock();
2015-11-06 22:39:19 +00:00
$question->expects($this->exactly(3))
->method('ask')
2015-02-22 22:29:48 +00:00
->will($this->onConsecutiveCalls(
false, // don't want to reset the entire database
true, // do want to reset the schema
false // don't want to create a new user
));
// We override the standard helper with our mock
2015-11-06 22:39:19 +00:00
$command->getHelperSet()->set($question, 'question');
2015-02-22 22:29:48 +00:00
$tester = new CommandTester($command);
$tester->execute(array(
'command' => $command->getName(),
));
$this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
$this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
$this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
$this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
$this->assertContains('Droping schema and creating schema', $tester->getDisplay());
}
/**
* @group command-doctrine
*/
2015-02-22 22:29:48 +00:00
public function testRunInstallCommandChooseNothing()
{
$this->container = static::$kernel->getContainer();
$application = new Application(static::$kernel);
$application->add(new InstallCommand());
$application->add(new DropDatabaseDoctrineCommand());
$application->add(new CreateDatabaseDoctrineCommand());
// drop database first, so the install command won't ask to reset things
$command = new DropDatabaseDoctrineCommand();
$command->setApplication($application);
$command->run(new ArrayInput(array(
'command' => 'doctrine:database:drop',
'--force' => true,
)), new NullOutput());
$this->container->get('doctrine')->getManager()->getConnection()->close();
$command = new CreateDatabaseDoctrineCommand();
$command->setApplication($application);
$command->run(new ArrayInput(array(
'command' => 'doctrine:database:create',
'--env' => 'test',
)), new NullOutput());
$command = $application->find('wallabag:install');
2015-11-06 22:39:19 +00:00
// We mock the QuestionHelper
$question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
2015-02-22 22:29:48 +00:00
->disableOriginalConstructor()
->getMock();
2015-11-06 22:39:19 +00:00
$question->expects($this->exactly(2))
->method('ask')
2015-02-22 22:29:48 +00:00
->will($this->onConsecutiveCalls(
false, // don't want to reset the entire database
false // don't want to create a new user
));
// We override the standard helper with our mock
2015-11-06 22:39:19 +00:00
$command->getHelperSet()->set($question, 'question');
2015-02-22 22:29:48 +00:00
$tester = new CommandTester($command);
$tester->execute(array(
'command' => $command->getName(),
));
$this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
$this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
$this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
$this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
$this->assertContains('Creating schema', $tester->getDisplay());
}
public function testRunInstallCommandNoInteraction()
{
$this->container = static::$kernel->getContainer();
$application = new Application(static::$kernel);
$application->add(new InstallCommandMock());
2015-02-22 22:29:48 +00:00
$command = $application->find('wallabag:install');
2015-11-06 22:39:19 +00:00
// We mock the QuestionHelper
$question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
2015-02-22 22:29:48 +00:00
->disableOriginalConstructor()
->getMock();
2015-11-06 22:39:19 +00:00
$question->expects($this->any())
2015-02-22 22:29:48 +00:00
->method('ask')
2015-11-06 22:39:19 +00:00
->will($this->returnValue('yes_'.uniqid('', true)));
2015-02-22 22:29:48 +00:00
// We override the standard helper with our mock
2015-11-06 22:39:19 +00:00
$command->getHelperSet()->set($question, 'question');
2015-02-22 22:29:48 +00:00
$tester = new CommandTester($command);
$tester->execute(array(
'command' => $command->getName(),
'--no-interaction' => true,
));
$this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
$this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
$this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
$this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
}
}