RefreshDatabase   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A swapTestingDatabase() 0 11 1
1
<?php
2
3
namespace MuhmdRaouf\LaravelParatest\Testing;
4
5
use Illuminate\Foundation\Testing\RefreshDatabase as BaseRefreshDatabase;
6
7
trait RefreshDatabase
8
{
9
    use BaseRefreshDatabase{
10
        refreshTestDatabase as protected parentRefreshTestDatabase;
11
    }
12
13
    protected function refreshTestDatabase()
14
    {
15
        $this->swapTestingDatabase();
16
        $this->parentRefreshTestDatabase();
0 ignored issues
show
Bug introduced by
The method parentRefreshTestDatabase() does not exist on MuhmdRaouf\LaravelParatest\Testing\RefreshDatabase. Did you maybe mean refreshTestDatabase()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
17
    }
18
19
    protected function swapTestingDatabase(): void
20
    {
21
        $driver = config('database.default');
22
        $dbName = config("database.connections.$driver.database");
23
24
        // Paratest gives each process a unique TEST_TOKEN env variable.
25
        // When that's not set, we can default to 1 because it's
26
        // probably running on PHPUnit instead.
27
        $TEST_TOKEN = env('TEST_TOKEN', 1);
28
        config()->set("database.connections.$driver.database", "$dbName-$TEST_TOKEN");
29
    }
30
}
31