Skip to content

Instantly share code, notes, and snippets.

@marcw
Created January 10, 2012 17:37
Show Gist options
  • Save marcw/1590166 to your computer and use it in GitHub Desktop.
Save marcw/1590166 to your computer and use it in GitHub Desktop.
SF2 functional test good practices
<?php
class AppKernel extends Kernel
{
static protected $connection;
public function boot()
{
parent::boot();
if ('test' === $this->getEnvironment()) {
if (null === static::$connection) {
static::$connection = $this->getContainer()->get('doctrine.dbal.default_connection');
} else {
$this->getContainer()->set('doctrine.dbal.default_connection', static::$connection);
}
}
}
}
<?php
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
class WebTestCase extends BaseWebTestCase
{
protected $client;
protected $container;
protected $em;
public function setUp()
{
if (null !== $this->client) {
$this->client->shutdown();
}
$this->client = static::createClient();
// Load fixtures (thx @FrancisBesset)
$fixtures = new LoadDataFixturesDoctrineCommand();
$fixtures->setApplication(new Application(static::$kernel));
$fixtures->run(
new ArrayInput(array(
'doctrine:data:load',
)),
new NullOutput()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment