From 9affff7e7b30abdbedc5db43b03b98c251ee7a66 Mon Sep 17 00:00:00 2001 From: Simon Kollross Date: Mon, 12 Feb 2018 15:26:37 +0100 Subject: [PATCH 1/2] Fixes starting of two database transactions in tests --- .../Foundation/Testing/RefreshDatabase.php | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/RefreshDatabase.php b/src/Illuminate/Foundation/Testing/RefreshDatabase.php index bffec98e5254..421fb4734361 100644 --- a/src/Illuminate/Foundation/Testing/RefreshDatabase.php +++ b/src/Illuminate/Foundation/Testing/RefreshDatabase.php @@ -6,8 +6,6 @@ trait RefreshDatabase { - use DatabaseTransactions; - /** * Define hooks to migrate the database before and after each test. * @@ -61,4 +59,38 @@ 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]; + } } From 45610d87e03f88a1aef3c1e67e4c15cb3c1c97ca Mon Sep 17 00:00:00 2001 From: Simon Kollross Date: Mon, 12 Feb 2018 15:34:25 +0100 Subject: [PATCH 2/2] indentation fixed --- src/Illuminate/Foundation/Testing/RefreshDatabase.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/RefreshDatabase.php b/src/Illuminate/Foundation/Testing/RefreshDatabase.php index 421fb4734361..5bac0a86d4d2 100644 --- a/src/Illuminate/Foundation/Testing/RefreshDatabase.php +++ b/src/Illuminate/Foundation/Testing/RefreshDatabase.php @@ -68,21 +68,21 @@ protected function refreshTestDatabase() 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. *