diff --git a/src/Neves/Testing/DatabaseTransactions.php b/src/Neves/Testing/DatabaseTransactions.php new file mode 100644 index 0000000000..b1f6003569 --- /dev/null +++ b/src/Neves/Testing/DatabaseTransactions.php @@ -0,0 +1,38 @@ +app->make('db'); + + foreach ($this->connectionsToTransact() as $name) { + $connection = $database->connection($name); + + $currentDispatcher = $connection->getEventDispatcher(); + $connection->setEventDispatcher($emptyDispatcher); + $connection->beginTransaction(); + $connection->setEventDispatcher($currentDispatcher); + } + + $this->beforeApplicationDestroyed(function () use ($database, $emptyDispatcher) { + foreach ($this->connectionsToTransact() as $name) { + $connection = $database->connection($name); + + $currentDispatcher = $connection->getEventDispatcher(); + $connection->setEventDispatcher($emptyDispatcher); + $connection->rollBack(); + $connection->setEventDispatcher($currentDispatcher); + + $connection->disconnect(); + } + }); + } +}