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

TestCase::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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