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

UnitTestCase::mockConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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