Skip to content

Commit

Permalink
Disable transaction events in DatabaseTransactions
Browse files Browse the repository at this point in the history
This follows commit deafaa7
which already added this for RefreshDatabase.

It's for the exact same reason as outlined in laravel#23832 :
> This is motivated by the fact that in tests, when using the RefreshDatabase trait, transactions events are dispatched and may interfer with the application testing itself when it relies on events like these ( for further info, see laravel/ideas#1094 ).

As to not have custom handling of transaction events interfere with the
test suite itself, this simply disables this.

Again, the same change was added to `RefreshDatabase` and is still
present; this PR merely keeps the behaviour of them in sync in regards
to the handling of events in transactions.
  • Loading branch information
mfn committed Apr 12, 2020
1 parent 70c0772 commit 95381c6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Illuminate/Foundation/Testing/DatabaseTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ public function beginDatabaseTransaction()
$database = $this->app->make('db');

foreach ($this->connectionsToTransact() as $name) {
$database->connection($name)->beginTransaction();
$connection = $database->connection($name);
$dispatcher = $connection->getEventDispatcher();

$connection->unsetEventDispatcher();
$connection->beginTransaction();
$connection->setEventDispatcher($dispatcher);
}

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

$connection->rollBack();
$connection->unsetEventDispatcher();
$connection->rollback();
$connection->setEventDispatcher($dispatcher);
$connection->disconnect();
}
});
Expand Down

0 comments on commit 95381c6

Please sign in to comment.