Skip to content

Instantly share code, notes, and snippets.

@chanakasan
Created November 6, 2013 02:31
Show Gist options
  • Save chanakasan/7329971 to your computer and use it in GitHub Desktop.
Save chanakasan/7329971 to your computer and use it in GitHub Desktop.
Symfony2 FunctionalTestCase for extending integration test classes
<?php
namespace Panda86\AppBundle\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\StringInput;
class FunctionalTestCase extends WebTestCase
{
/**
* @var \Doctrine\ORM\EntityManager
*/
protected $em;
protected static $application;
/**
* {@inheritDoc}
*/
public function setUp()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
$this->em = static::$kernel->getContainer()
->get('doctrine')
->getManager()
;
self::runCommand('doctrine:database:create');
self::runCommand('doctrine:schema:update --force');
self::runCommand('doctrine:fixtures:load --append');
}
protected static function runCommand($command)
{
$command = sprintf('%s --quiet', $command);
return self::getApplication()->run(new StringInput($command));
}
protected static function getApplication()
{
if (null === self::$application) {
$client = static::createClient();
self::$application = new Application($client->getKernel());
self::$application->setAutoExit(false);
}
return self::$application;
}
/**
* {@inheritDoc}
*/
protected function tearDown()
{
parent::tearDown();
$this->em->close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment