コード例 #1
0
 /**
  * @param PHPUnit_Framework_TestSuite $suite
  *
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     $kernel = new AppKernel('test', true);
     // create a "test" kernel
     $kernel->boot();
     $application = new Application($kernel);
     // add the database:drop command to the application and run it
     $command = new DropDatabaseDoctrineCommand();
     $command->setContainer($kernel->getContainer());
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:database:drop', '--force' => true]);
     $command->run($input, new ConsoleOutput());
     // This stops a bug where Drop Database does not close the handle properly & causes subsequent
     // "database not found" errors.
     $connection = $kernel->getContainer()->get('doctrine')->getConnection();
     if ($connection->isConnected()) {
         $connection->close();
     }
     // add the database:create command to the application and run it
     $command = new CreateDatabaseDoctrineCommand();
     $command->setContainer($kernel->getContainer());
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:database:create']);
     $command->run($input, new ConsoleOutput());
     // Run the database migrations, with --quiet because they are quite
     // chatty on the console.
     $command = new MigrationsMigrateDoctrineCommand();
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:migrations:migrate', '--quiet' => false, '--no-interaction' => true]);
     $input->setInteractive(false);
     $command->run($input, new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET));
     // and load the fixtures
     $command = new LoadDataFixturesDoctrineCommand();
     $command->setContainer($kernel->getContainer());
     $application->add($command);
     $input = new ArrayInput(['command' => 'doctrine:fixtures:load', '--quiet']);
     $input->setInteractive(false);
     $command->run($input, new ConsoleOutput());
 }
コード例 #2
0
 public function testRunInstallCommandChooseNothing()
 {
     $application = new Application($this->getClient()->getKernel());
     $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(['command' => 'doctrine:database:drop', '--force' => true]), new NullOutput());
     $this->getClient()->getContainer()->get('doctrine')->getConnection()->close();
     $command = new CreateDatabaseDoctrineCommand();
     $command->setApplication($application);
     $command->run(new ArrayInput(['command' => 'doctrine:database:create', '--env' => 'test']), new NullOutput());
     $command = $application->find('wallabag:install');
     // We mock the QuestionHelper
     $question = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')->disableOriginalConstructor()->getMock();
     $question->expects($this->exactly(2))->method('ask')->will($this->onConsecutiveCalls(false, false));
     // We override the standard helper with our mock
     $command->getHelperSet()->set($question, 'question');
     $tester = new CommandTester($command);
     $tester->execute(['command' => $command->getName()]);
     $this->assertContains('Checking system requirements.', $tester->getDisplay());
     $this->assertContains('Setting up database.', $tester->getDisplay());
     $this->assertContains('Administration setup.', $tester->getDisplay());
     $this->assertContains('Config setup.', $tester->getDisplay());
     $this->assertContains('Creating schema', $tester->getDisplay());
 }