Skip to content

Commit a8a3b17

Browse files
committed
Disable transaction events in DatabaseTransactions
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.
1 parent 17f55cc commit a8a3b17

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Illuminate/Foundation/Testing/DatabaseTransactions.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ public function beginDatabaseTransaction()
1414
$database = $this->app->make('db');
1515

1616
foreach ($this->connectionsToTransact() as $name) {
17-
$database->connection($name)->beginTransaction();
17+
$connection = $database->connection($name);
18+
$dispatcher = $connection->getEventDispatcher();
19+
20+
$connection->unsetEventDispatcher();
21+
$connection->beginTransaction();
22+
$connection->setEventDispatcher($dispatcher);
1823
}
1924

2025
$this->beforeApplicationDestroyed(function () use ($database) {
2126
foreach ($this->connectionsToTransact() as $name) {
2227
$connection = $database->connection($name);
28+
$dispatcher = $connection->getEventDispatcher();
2329

24-
$connection->rollBack();
30+
$connection->unsetEventDispatcher();
31+
$connection->rollback();
32+
$connection->setEventDispatcher($dispatcher);
2533
$connection->disconnect();
2634
}
2735
});

0 commit comments

Comments
 (0)