Skip to content

Instantly share code, notes, and snippets.

Forked from wowo/ModelTestCase.php
Created June 11, 2012 17:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save buxx/2911431 to your computer and use it in GitHub Desktop.
Model Test Case, which loads fixtures and builds database before each test
* Adapt to your AppKernel.php path
require_once(__DIR__ . "../../../../../../app/AppKernel.php");
* @see
class ModelTestCase extends \PHPUnit_Framework_TestCase
protected $_kernel;
protected $_application;
protected $_container;
public function __construct()
$this->_kernel = new \AppKernel("test", true);
$this->_container = $this->_kernel->getContainer();
protected function get($service)
return $this->_container->get($service);
public function setUp()
$this->_application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->_kernel);
$this->runConsole("doctrine:schema:drop", array("--force" => true));
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