Skip to content

Commit

Permalink
Reuse code from DatabaseTransactions in RefreshDatabase (#22596)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek authored and taylorotwell committed Jan 2, 2018
1 parent 68d3a1b commit efc36db
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions src/Illuminate/Foundation/Testing/RefreshDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait RefreshDatabase
{
use DatabaseTransactions;

/**
* Define hooks to migrate the database before and after each test.
*
Expand Down Expand Up @@ -59,38 +61,4 @@ protected function refreshTestDatabase()

$this->beginDatabaseTransaction();
}

/**
* Begin a database transaction on the testing database.
*
* @return void
*/
public function beginDatabaseTransaction()
{
$database = $this->app->make('db');

foreach ($this->connectionsToTransact() as $name) {
$database->connection($name)->beginTransaction();
}

$this->beforeApplicationDestroyed(function () use ($database) {
foreach ($this->connectionsToTransact() as $name) {
$connection = $database->connection($name);

$connection->rollBack();
$connection->disconnect();
}
});
}

/**
* The database connections that should have transactions.
*
* @return array
*/
protected function connectionsToTransact()
{
return property_exists($this, 'connectionsToTransact')
? $this->connectionsToTransact : [null];
}
}

0 comments on commit efc36db

Please sign in to comment.