Skip to content

Instantly share code, notes, and snippets.

@wowo
Created June 14, 2011 21:26
Show Gist options
  • Save wowo/1025932 to your computer and use it in GitHub Desktop.
Save wowo/1025932 to your computer and use it in GitHub Desktop.
Model Test Case, which loads fixtures and builds database before each test
<?php
require_once(__DIR__ . "/../../../../app/AppKernel.php");
class ModelTestCase extends \PHPUnit_Framework_TestCase
{
protected $_application;
public function getContainer()
{
return $this->_application->getKernel()->getContainer();
}
public function setUp()
{
$kernel = new \AppKernel("test", true);
$kernel->boot();
$this->_application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$this->_application->setAutoExit(false);
$this->runConsole("doctrine:schema:drop", array("--force" => true));
$this->runConsole("doctrine:schema:create");
$this->runConsole("doctrine:fixtures:load", array("--fixtures" => __DIR__ . "/../DataFixtures"));
}
protected function runConsole($command, Array $options = array())
{
$options["-e"] = "test";
$options["-q"] = null;
$options = array_merge($options, array('command' => $command));
return $this->_application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment