Created
January 10, 2012 17:37
-
-
Save marcw/1590166 to your computer and use it in GitHub Desktop.
SF2 functional test good practices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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