Passed
Push — master ( a1af26...d56533 )
by Caen
03:20 queued 12s
created

UnitTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 8
c 6
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setupKernel() 0 4 1
A mockConfig() 0 5 1
A needsKernel() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Testing;
6
7
use Hyde\Foundation\HydeKernel;
8
use Illuminate\Config\Repository;
9
use Illuminate\Support\Facades\Config;
10
use PHPUnit\Framework\TestCase as BaseTestCase;
11
12
abstract class UnitTestCase extends BaseTestCase
13
{
14
    protected static bool $hasSetUpKernel = false;
15
16
    protected static function needsKernel(): void
17
    {
18
        if (! self::$hasSetUpKernel) {
19
            self::setupKernel();
20
        }
21
    }
22
23
    protected static function setupKernel(): void
24
    {
25
        HydeKernel::setInstance(new HydeKernel());
26
        self::$hasSetUpKernel = true;
27
    }
28
29
    protected static function mockConfig(array $items = []): void
30
    {
31
        app()->bind('config', fn (): Repository => new Repository($items));
32
33
        Config::swap(app('config'));
34
    }
35
}
36