Skip to content

Instantly share code, notes, and snippets.

@meddulla
Forked from wowo/ModelTestCase.php
Created February 3, 2012 12:15
Show Gist options
  • Save meddulla/1729897 to your computer and use it in GitHub Desktop.
Save meddulla/1729897 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 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("cache:warmup");
$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