Passed
Push — master ( 6e6daa...cfe756 )
by Caen
03:17
created

TestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 10
Bugs 0 Features 0
Metric Value
eloc 20
c 10
b 0
f 0
dl 0
loc 42
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 2
A tearDown() 0 14 2
A assertFileEqualsString() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Testing;
6
7
use Hyde\Facades\Features;
8
use Hyde\Hyde;
9
use Illuminate\View\Component;
10
use LaravelZero\Framework\Testing\TestCase as BaseTestCase;
11
12
use function file_get_contents;
13
use function Hyde\normalize_newlines;
14
15
abstract class TestCase extends BaseTestCase
16
{
17
    use CreatesApplication;
18
    use ResetsApplication;
19
    use CreatesTemporaryFiles;
20
    use InteractsWithPages;
21
22
    protected static bool $booted = false;
23
24
    protected function setUp(): void
25
    {
26
        parent::setUp();
27
28
        if (! static::$booted) {
29
            $this->resetApplication();
30
31
            static::$booted = true;
32
        }
33
    }
34
35
    protected function tearDown(): void
36
    {
37
        $this->cleanUpFilesystem();
38
39
        if (method_exists(\Illuminate\View\Component::class, 'flushCache')) {
40
            /** Until https://github.com/laravel/framework/pull/44648 makes its way into Laravel Zero, we need to clear the cache ourselves */
41
            Component::flushCache();
42
            Component::forgetComponentsResolver();
43
            Component::forgetFactory();
44
        }
45
46
        Features::clearMockedInstances();
47
48
        parent::tearDown();
49
    }
50
51
    protected function assertFileEqualsString(string $string, string $path, bool $strict = false): void
52
    {
53
        if ($strict) {
54
            $this->assertSame($string, file_get_contents(Hyde::path($path)));
55
        } else {
56
            $this->assertEquals(normalize_newlines($string), normalize_newlines(file_get_contents(Hyde::path($path))));
57
        }
58
    }
59
}
60