Skip to content

Instantly share code, notes, and snippets.

@fesor
Created May 1, 2013 13:42
Show Gist options
  • Save fesor/5495341 to your computer and use it in GitHub Desktop.
Save fesor/5495341 to your computer and use it in GitHub Desktop.
Symfony application bootstrap file for functional testing
<?php
require_once __DIR__.'/bootstrap.php.cache';
require_once __DIR__.'/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
$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();
$application->add($command);
$input = new ArrayInput(array(
'command' => 'doctrine:database:drop',
'--force' => true,
));
$command->run($input, new ConsoleOutput());
// add the database:create command to the application and run it
$command = new CreateDatabaseDoctrineCommand();
$application->add($command);
$input = new ArrayInput(array(
'command' => 'doctrine:database:create',
));
$command->run($input, new ConsoleOutput());
$connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection();
if ($connection->isConnected()) {
$connection->close();
}
// let Doctrine create the database schema (i.e. the tables)
$command = new \Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand();
$application->add($command);
$input = new ArrayInput(array(
'command' => 'doctrine:schema:create',
));
$command->run($input, new ConsoleOutput());
// load fixtures
$command = new \Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand();
$application->add($command);
$input = new ArrayInput(array(
'command' => 'doctrine:fixtures:load',
'--no-interaction' => true,
));
$command->run($input, new ConsoleOutput());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment