-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
DatabaseTransactionsManager.php
47 lines (42 loc) · 1.37 KB
/
DatabaseTransactionsManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Illuminate\Foundation\Testing;
class DatabaseTransactionsManager extends \Illuminate\Database\DatabaseTransactionsManager
{
/**
* Register a transaction callback.
*
* @param callable $callback
* @return void
*/
public function addCallback($callback)
{
// If there are no transactions, we'll run the callbacks right away. Also, we'll run it
// right away when we're in test mode and we only have the wrapping transaction. For
// every other case, we'll queue up the callback to run after the commit happens.
if ($this->callbackApplicableTransactions()->count() === 0) {
return $callback();
}
$this->transactions->last()->addCallback($callback);
}
/**
* Get the transactions that are applicable to callbacks.
*
* @return \Illuminate\Support\Collection<int, \Illuminate\Database\DatabaseTransactionRecord>
*/
public function callbackApplicableTransactions()
{
return $this->transactions->reject(
fn ($transaction) => $transaction === $this->transactions->first()
)->values();
}
/**
* Determine if after commit callbacks should be executed.
*
* @param int $level
* @return bool
*/
public function afterCommitCallbacksShouldBeExecuted($level)
{
return $level === 2;
}
}