Skip to content

Commit

Permalink
Add support of not running in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
1josefnevoral committed Aug 12, 2016
1 parent 83a0db1 commit 178ef88
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/AbstractDbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class AbstractDbTestCase extends AbstractTestCase

protected $initialized;
protected static $started;
protected $isInTransactionMode = true;

/**
* @var FixtureLoader
Expand Down Expand Up @@ -89,7 +90,7 @@ protected function init()
$this->initContainer();
$this->initialized = true;

// do it only once, for db setup
// do it only once, for db setup or repeat if not in transaction mode
if (!self::$started) {
$this->initDatabases();
self::$started = true;
Expand Down Expand Up @@ -127,7 +128,9 @@ protected function beginTransactions()
{
$fixtureLoader = $this->getFixtureLoader();
foreach($this->getInitializedConnections() as $connection) {
$connection->beginTransaction();
if ($this->isInTransactionMode) {
$connection->beginTransaction();
}

$this->loadFixtures($fixtureLoader, $connection);
}
Expand All @@ -136,6 +139,9 @@ protected function beginTransactions()
protected function closeTransactions()
{
foreach ($this->getInitializedConnections() as $connection) {
if (!$this->isInTransactionMode) {
continue;
}
$connection->rollBack();
}
}
Expand Down Expand Up @@ -234,4 +240,14 @@ protected function executeQueryWithForeignKeySetting(\Closure $closure, Abstract
$connection->enableForeignKeyChecks();
}
}


protected function cleanTables(array $tableNames)
{
foreach ($this->getInitializedConnections() as $connection) {
foreach ($tableNames as $table) {
$connection->execute('DELETE FROM ' . $table . ' WHERE id > 0');
}
}
}
}

0 comments on commit 178ef88

Please sign in to comment.