From 0bf99bb144561525a34a50315b95efd6f543fe35 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 22 Feb 2015 14:35:36 +0100 Subject: Improve install command & add test Also add fixtures for Config InstallCommand now check if database, schema are here and ask the user what to do (keep or trash & re-create) --- .../Tests/Command/InstallCommandTest.php | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php (limited to 'src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php new file mode 100644 index 00000000..6bcc9707 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -0,0 +1,61 @@ +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 InstallCommand()); + + $command = $application->find('wallabag:install'); + + // We mock the DialogHelper + $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + ->disableOriginalConstructor() + ->getMock(); + $dialog->expects($this->any()) + ->method('ask') + ->will($this->returnValue('test')); + $dialog->expects($this->any()) + ->method('askConfirmation') + ->will($this->returnValue(true)); + + // We override the standard helper with our mock + $command->getHelperSet()->set($dialog, 'dialog'); + + $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()); + } +} -- cgit v1.2.3 From 732c2ad8971f427ec196acfac53dad034cefdef4 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 22 Feb 2015 17:18:54 +0100 Subject: sqlite doesn't support getListDatabasesSQL --- src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index 6bcc9707..a091d66f 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -50,7 +50,7 @@ class InstallCommandTest extends WallabagTestCase $tester = new CommandTester($command); $tester->execute(array( - 'command' => $command->getName() + 'command' => $command->getName(), )); $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay()); -- cgit v1.2.3 From c641baad0ec52198d77f2018c7bf8acdfe5957ce Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 22 Feb 2015 23:29:48 +0100 Subject: More tests on the install command --- .../Tests/Command/InstallCommandTest.php | 219 ++++++++++++++++++++- 1 file changed, 216 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index a091d66f..64f6c329 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -8,13 +8,13 @@ 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; class InstallCommandTest extends WallabagTestCase { - public function tearDown() + public static function tearDownAfterClass() { - parent::tearDown(); - $application = new Application(static::$kernel); $application->setAutoExit(false); @@ -58,4 +58,217 @@ class InstallCommandTest extends WallabagTestCase $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); } + + public function testRunInstallCommandWithReset() + { + $this->container = static::$kernel->getContainer(); + + $application = new Application(static::$kernel); + $application->add(new InstallCommand()); + + $command = $application->find('wallabag:install'); + + // We mock the DialogHelper + $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + ->disableOriginalConstructor() + ->getMock(); + $dialog->expects($this->any()) + ->method('ask') + ->will($this->returnValue('test')); + $dialog->expects($this->any()) + ->method('askConfirmation') + ->will($this->returnValue(true)); + + // We override the standard helper with our mock + $command->getHelperSet()->set($dialog, 'dialog'); + + $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()); + } + + 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'); + + // We mock the DialogHelper + $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + ->disableOriginalConstructor() + ->getMock(); + $dialog->expects($this->any()) + ->method('ask') + ->will($this->returnValue('test')); + $dialog->expects($this->any()) + ->method('askConfirmation') + ->will($this->returnValue(true)); + + // We override the standard helper with our mock + $command->getHelperSet()->set($dialog, 'dialog'); + + $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 InstallCommand()); + + $command = $application->find('wallabag:install'); + + // We mock the DialogHelper + $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + ->disableOriginalConstructor() + ->getMock(); + + $dialog->expects($this->exactly(3)) + ->method('askConfirmation') + ->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 + $command->getHelperSet()->set($dialog, 'dialog'); + + $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()); + } + + 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'); + + // We mock the DialogHelper + $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + ->disableOriginalConstructor() + ->getMock(); + + $dialog->expects($this->exactly(2)) + ->method('askConfirmation') + ->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'); + + $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 InstallCommand()); + + $command = $application->find('wallabag:install'); + + // We mock the DialogHelper + $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + ->disableOriginalConstructor() + ->getMock(); + $dialog->expects($this->any()) + ->method('ask') + ->will($this->returnValue('test')); + $dialog->expects($this->any()) + ->method('askConfirmation') + ->will($this->returnValue(true)); + + // We override the standard helper with our mock + $command->getHelperSet()->set($dialog, 'dialog'); + + $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()); + } } -- cgit v1.2.3