RoutesTest::testGetMediaUrlPreset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Config;
6
7
use AbterPhp\Framework\Constant\Env;
8
use AbterPhp\Framework\Environments\Environment;
9
use PHPUnit\Framework\TestCase;
10
11
class RoutesTest extends TestCase
12
{
13
    private const MEDIA_BASE_URL = "/media";
14
15
    /** @var Routes - System Under Test */
16
    protected Routes $sut;
17
18
    public function setUp(): void
19
    {
20
        $this->sut = new Routes();
21
22
        Environment::setVar(Env::MEDIA_BASE_URL, self::MEDIA_BASE_URL);
23
        Environment::unsetVar(Env::CACHE_BASE_PATH);
24
25
        parent::setUp();
26
    }
27
28
    public function testGetMediaUrlPreset(): void
29
    {
30
        $mediaBaseUrl = 'foo';
31
32
        $this->sut->setMediaUrl($mediaBaseUrl);
33
34
        $actualResult = $this->sut->getMediaUrl();
35
36
        $this->assertEquals($mediaBaseUrl, $actualResult);
37
    }
38
39
    public function testGetMediaUrlFromEnvVar(): void
40
    {
41
        $mediaBaseUrl = 'foo';
42
43
        Environment::setVar(Env::MEDIA_BASE_URL, $mediaBaseUrl);
44
45
        $actualResult = $this->sut->getMediaUrl();
46
47
        $this->assertEquals($mediaBaseUrl, $actualResult);
48
    }
49
50
    public function testGetCacheUrlPreset(): void
51
    {
52
        $cacheUrl = 'foo';
53
54
        $this->sut->setCacheUrl($cacheUrl);
55
56
        $actualResult = $this->sut->getCacheUrl();
57
58
        $this->assertEquals($cacheUrl, $actualResult);
59
    }
60
61
    public function testGetCacheUrlFromEmptyEnvVar(): void
62
    {
63
        $cacheBasePath = '';
64
65
        Environment::setVar(Env::CACHE_BASE_PATH, $cacheBasePath);
66
67
        $actualResult = $this->sut->getCacheUrl();
68
69
        $this->assertEquals($cacheBasePath, $actualResult);
70
    }
71
72
    public function testGetCacheUrlFromEnvVar(): void
73
    {
74
        $cacheBasePath = 'foo';
75
        $expectedBasePath = self::MEDIA_BASE_URL . '/foo';
76
77
        Environment::setVar(Env::CACHE_BASE_PATH, $cacheBasePath);
78
79
        $actualResult = $this->sut->getCacheUrl();
80
81
        $this->assertEquals($expectedBasePath, $actualResult);
82
    }
83
84
    public function testGetAssetsPathPreset(): void
85
    {
86
        $cacheUrl = 'foo';
87
88
        $this->sut->setAssetsPath($cacheUrl);
89
90
        $actualResult = $this->sut->getAssetsPath();
91
92
        $this->assertEquals($cacheUrl, $actualResult);
93
    }
94
95
    public function testGetAssetsPathFromEmptyEnvVar(): void
96
    {
97
        $cacheBasePath = '';
98
99
        Environment::setVar(Env::CACHE_BASE_PATH, $cacheBasePath);
100
101
        $actualResult = $this->sut->getAssetsPath();
102
103
        $this->assertEquals($cacheBasePath, $actualResult);
104
    }
105
106
    public function testGetAssetsPathFromEnvVar(): void
107
    {
108
        $cacheBasePath = 'foo';
109
        $expectedBasePath = 'foo/:path';
110
111
        Environment::setVar(Env::CACHE_BASE_PATH, $cacheBasePath);
112
113
        $actualResult = $this->sut->getAssetsPath();
114
115
        $this->assertEquals($expectedBasePath, $actualResult);
116
    }
117
}
118