Issues (364)

src/Testing/DatabaseTransactions.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Testing;
6
7
use Illuminate\Foundation\Testing\DatabaseTransactions as IlluminateDatabaseTransactions;
8
use Illuminate\Foundation\Testing\DatabaseTransactionsManager;
9
use LaravelFreelancerNL\Aranguent\Testing\Concerns\PreparesTestingTransactions;
10
11
trait DatabaseTransactions
12
{
13
    use PreparesTestingTransactions;
14
    use IlluminateDatabaseTransactions;
15
16
    /**
17
     * Handle database transactions on the specified connections.
18
     *
19
     * @return void
20
     */
21 133
    public function beginDatabaseTransaction()
22
    {
23 133
        $database = $this->app->make('db');
24
25 133
        $connections = $this->connectionsToTransact();
26
27 133
        $this->app->instance('db.transactions', $transactionsManager = new DatabaseTransactionsManager($connections));
28
29 133
        foreach ($this->connectionsToTransact() as $name) {
30 133
            $connection = $database->connection($name);
31 133
            $connection->setTransactionManager($transactionsManager);
32 133
            $dispatcher = $connection->getEventDispatcher();
33
34 133
            $connection->unsetEventDispatcher();
35 133
            $connection->beginTransaction($this->transactionCollections);
36 133
            $connection->setEventDispatcher($dispatcher);
37
        }
38
39 133
        $this->beforeApplicationDestroyed(function () use ($database) {
0 ignored issues
show
It seems like beforeApplicationDestroyed() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $this->/** @scrutinizer ignore-call */ 
40
               beforeApplicationDestroyed(function () use ($database) {
Loading history...
40 133
            foreach ($this->connectionsToTransact() as $name) {
41 133
                $connection = $database->connection($name);
42 133
                $dispatcher = $connection->getEventDispatcher();
43
44 133
                $connection->unsetEventDispatcher();
45 133
                $connection->rollBack();
46 133
                $connection->setEventDispatcher($dispatcher);
47 133
                $connection->disconnect();
48
            }
49 133
        });
50
    }
51
}
52