From cf14306c2b3f82a81f8d56669a71633b4d4b5fce Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Mon, 16 Apr 2018 21:09:05 +0200 Subject: Main merge to user management system - files are now at /main/public/ --- main/app/tests/DatabaseTransactions.php | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 main/app/tests/DatabaseTransactions.php (limited to 'main/app/tests/DatabaseTransactions.php') diff --git a/main/app/tests/DatabaseTransactions.php b/main/app/tests/DatabaseTransactions.php new file mode 100755 index 0000000..ed2225b --- /dev/null +++ b/main/app/tests/DatabaseTransactions.php @@ -0,0 +1,48 @@ +ci['db']; + + foreach ($this->connectionsToTransact() as $name) { + $database->connection($name)->beginTransaction(); + } + + $this->beforeApplicationDestroyed(function () use ($database) { + foreach ($this->connectionsToTransact() as $name) { + $database->connection($name)->rollBack(); + } + }); + } + + /** + * The database connections that should have transactions. + * + * @return array + */ + protected function connectionsToTransact() + { + return property_exists($this, 'connectionsToTransact') + ? $this->connectionsToTransact : [null]; + } +} \ No newline at end of file -- cgit v1.2.3