diff options
author | marvin-borner@live.com | 2018-04-16 21:09:05 +0200 |
---|---|---|
committer | marvin-borner@live.com | 2018-04-16 21:09:05 +0200 |
commit | cf14306c2b3f82a81f8d56669a71633b4d4b5fce (patch) | |
tree | 86700651aa180026e89a66064b0364b1e4346f3f /main/app/tests/DatabaseTransactions.php | |
parent | 619b01b3615458c4ed78bfaeabb6b1a47cc8ad8b (diff) |
Main merge to user management system - files are now at /main/public/
Diffstat (limited to 'main/app/tests/DatabaseTransactions.php')
-rwxr-xr-x | main/app/tests/DatabaseTransactions.php | 48 |
1 files changed, 48 insertions, 0 deletions
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 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Tests; + +/** + * Trait enabling wrapping of each test case in a database transaction + * Based on Laravel `DatabaseTransactions` Traits + * + * @author Louis Charette + */ +trait DatabaseTransactions +{ + /** + * Handle database transactions on the specified connections. + * + * @return void + */ + public function beginDatabaseTransaction() + { + $database = $this->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 |