Created
June 14, 2011 21:26
-
-
Save wowo/1025932 to your computer and use it in GitHub Desktop.
Model Test Case, which loads fixtures and builds database before each test
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 | |
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