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

HandlesTestingTransactions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 1
b 0
f 0
dl 0
loc 24
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A initializeTestDatabaseTransactions() 0 22 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