Passed
Push — master ( 21719d...7c0196 )
by Caen
03:52 queued 12s
created

TestCase::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Hyde\Testing;
4
5
use Hyde\Framework\Contracts\PageContract;
6
use Hyde\Framework\Hyde;
7
use Hyde\Framework\Models\Pages\MarkdownPage;
8
use Hyde\Framework\Models\Route;
9
use LaravelZero\Framework\Testing\TestCase as BaseTestCase;
10
use Tests\CreatesApplication;
11
12
require_once __DIR__.'/helpers.php';
13
14
abstract class TestCase extends BaseTestCase
15
{
16
    use CreatesApplication;
17
    use ResetsApplication;
18
19
    protected static bool $booted = false;
20
21
    /**
22
     * Setup the test environment.
23
     *
24
     * @return void
25
     */
26
    protected function setUp(): void
27
    {
28
        parent::setUp();
29
30
        if (! static::$booted) {
31
            $this->resetApplication();
32
33
            Hyde::macro('touch', function (string|array $path) {
34
                if (is_array($path)) {
0 ignored issues
show
introduced by
The condition is_array($path) is always true.
Loading history...
35
                    foreach ($path as $p) {
36
                        touch(Hyde::path($p));
37
                    }
38
                } else {
39
                    return touch(Hyde::path($path));
40
                }
41
            });
42
43
            Hyde::macro('unlink', function (string|array $path) {
44
                if (is_array($path)) {
0 ignored issues
show
introduced by
The condition is_array($path) is always true.
Loading history...
45
                    foreach ($path as $p) {
46
                        unlink(Hyde::path($p));
47
                    }
48
                } else {
49
                    return unlink(Hyde::path($path));
50
                }
51
            });
52
53
            static::$booted = true;
54
        }
55
    }
56
57
    /**
58
     * Clean up the testing environment before the next test.
59
     *
60
     * @return void
61
     */
62
    protected function tearDown(): void
63
    {
64
        parent::tearDown();
65
    }
66
67
    /** @internal */
68
    protected function mockRoute(?Route $route = null)
69
    {
70
        view()->share('currentRoute', $route ?? (new Route(new MarkdownPage())));
71
    }
72
73
    /** @internal */
74
    protected function mockPage(?PageContract $page = null, ?string $currentPage = null)
75
    {
76
        view()->share('page', $page ?? new MarkdownPage());
77
        view()->share('currentPage', $currentPage ?? 'PHPUnit');
78
    }
79
}
80