RefreshDatabase::swapTestingDatabase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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