Passed
Pull Request — next (#61)
by Bas
05:52 queued 02:43
created

initializeTestDatabaseTransactions()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
ccs 16
cts 16
cp 1
rs 9.7666
cc 3
nc 2
nop 0
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Testing;
6
7
trait HandlesTestingTransactions
8
{
9 152
    protected function initializeTestDatabaseTransactions(): void
10
    {
11 152
        $database = $this->app->make('db');
12
13 152
        foreach ($this->connectionsToTransact() as $name) {
0 ignored issues
show
Bug introduced by
It seems like connectionsToTransact() 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

13
        foreach ($this->/** @scrutinizer ignore-call */ connectionsToTransact() as $name) {
Loading history...
14 152
            $connection = $database->connection($name);
15 152
            $dispatcher = $connection->getEventDispatcher();
16
17 152
            $connection->unsetEventDispatcher();
18 152
            $connection->beginTransaction($this->transactionCollections);
19 152
            $connection->setEventDispatcher($dispatcher);
20
        }
21
22 152
        $this->beforeApplicationDestroyed(function () use ($database) {
0 ignored issues
show
Bug introduced by
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

22
        $this->/** @scrutinizer ignore-call */ 
23
               beforeApplicationDestroyed(function () use ($database) {
Loading history...
23 152
            foreach ($this->connectionsToTransact() as $name) {
24 152
                $connection = $database->connection($name);
25 152
                $dispatcher = $connection->getEventDispatcher();
26
27 152
                $connection->unsetEventDispatcher();
28 152
                $connection->rollback();
29 152
                $connection->setEventDispatcher($dispatcher);
30 152
                $connection->disconnect();
31
            }
32 152
        });
33 152
    }
34
}
35