X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FTests%2FCommand%2FInstallCommandTest.php;h=7d75e2b7b2755ee5878a51644aeb37ef4bc53e87;hb=86719c63bf47686ca55020e6b0443344de36d45a;hp=7a819953e07d08bc24caa3f2a39d3761100a2723;hpb=2878416f8b4d94fb5e64c2fa61861526a7654d3d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index 7a819953..7d75e2b7 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -2,15 +2,15 @@ namespace Wallabag\CoreBundle\Tests\Command; -use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -use Wallabag\CoreBundle\Command\InstallCommand; -use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock; +use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; +use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; -use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; +use Symfony\Component\Console\Tester\CommandTester; +use Wallabag\CoreBundle\Command\InstallCommand; +use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; class InstallCommandTest extends WallabagCoreTestCase { @@ -28,26 +28,21 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommand() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test')); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -62,26 +57,21 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandWithReset() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test')); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -95,43 +85,51 @@ class InstallCommandTest extends WallabagCoreTestCase $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()); + $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); } - /** - * @group command-doctrine - */ public function testRunInstallCommandWithDatabaseRemoved() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); - $application->add(new InstallCommand()); + if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { + /* + * LOG: statement: CREATE DATABASE "wallabag" + * ERROR: source database "template1" is being accessed by other users + * DETAIL: There is 1 other session using the database. + * STATEMENT: CREATE DATABASE "wallabag" + * FATAL: database "wallabag" does not exist + * + * http://stackoverflow.com/a/14374832/569101 + */ + $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); + } + + $application = new Application($this->getClient()->getKernel()); $application->add(new DropDatabaseDoctrineCommand()); // 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(array( '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'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test')); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -149,20 +147,18 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandChooseResetSchema() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->exactly(3)) - ->method('askConfirmation') + $question->expects($this->exactly(3)) + ->method('ask') ->will($this->onConsecutiveCalls( false, // don't want to reset the entire database true, // do want to reset the schema @@ -170,7 +166,7 @@ class InstallCommandTest extends WallabagCoreTestCase )); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -185,14 +181,16 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); } - /** - * @group command-doctrine - */ public function testRunInstallCommandChooseNothing() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { + /* + * @see testRunInstallCommandWithDatabaseRemoved + */ + $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); + } + + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommand()); $application->add(new DropDatabaseDoctrineCommand()); $application->add(new CreateDatabaseDoctrineCommand()); @@ -205,7 +203,7 @@ class InstallCommandTest extends WallabagCoreTestCase '--force' => true, )), new NullOutput()); - $this->container->get('doctrine')->getManager()->getConnection()->close(); + $this->getClient()->getContainer()->get('doctrine')->getConnection()->close(); $command = new CreateDatabaseDoctrineCommand(); $command->setApplication($application); @@ -216,20 +214,20 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->exactly(2)) - ->method('askConfirmation') + $question->expects($this->exactly(2)) + ->method('ask') ->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 - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -246,26 +244,21 @@ class InstallCommandTest extends WallabagCoreTestCase public function testRunInstallCommandNoInteraction() { - $this->container = static::$kernel->getContainer(); - - $application = new Application(static::$kernel); + $application = new Application($this->getClient()->getKernel()); $application->add(new InstallCommandMock()); $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test')); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array(