*/ class TestCase extends BaseTestCase { /** * @var \PropelPDO */ protected $con; /** * The list of created temp files to be removed. * * @var array */ protected $tmpFiles = array(); protected function setUp() { parent::setUp(); if (!class_exists('Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBook')) { $schema = <<
XML; QuickBuilder::buildSchema($schema); } $this->con = Propel::getServiceContainer()->getConnection('default'); $this->con->beginTransaction(); } protected function tearDown() { foreach ($this->tmpFiles as $eachFile) { @unlink($eachFile); } $this->tmpFiles = array(); // Only commit if the transaction hasn't failed. // This is because tearDown() is also executed on a failed tests, // and we don't want to call ConnectionInterface::commit() in that case // since it will trigger an exception on its own // ('Cannot commit because a nested transaction was rolled back') if (null !== $this->con) { if ($this->con->isCommitable()) { $this->con->commit(); } $this->con = null; } } /** * Return the name of a created temporary file containing the given content. * * @param string $content * * @return string */ protected function getTempFile($content = '') { $filename = tempnam(sys_get_temp_dir(), 'propelbundle-datafixtures-test'); @unlink($filename); file_put_contents($filename, $content); $this->tmpFiles[] = $filename; return $filename; } }