Passed
Push — master ( ed297f...604ea4 )
by Giuliano
04:39
created

ThemeURLTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPublishable() 0 5 1
A registerDomain() 0 9 1
A testThemeUrl() 0 9 1
A testUrlFileFromTheme() 0 10 1
A getUrl() 0 8 1
1
<?php
2
3
namespace Maestriam\Samurai\Tests\Unit\Entities\Theme;
4
5
use Maestriam\Samurai\Foundation\ConfigKeeper;
6
use Maestriam\Samurai\Foundation\EnvHandler;
7
8
/**
9
 * Testes de funcionalidades básicas apresentadas no README.md
10
 */
11
class ThemeURLTest extends ThemeTestCase
12
{
13
    public function testThemeUrl()
14
    {
15
        $name  = 'bands/edguy';
16
        $theme = $this->theme($name)->findOrCreate();
17
        
18
        $expected = $this->getUrl($name);
19
        $actual   = $theme->url();
20
21
        $this->assertEquals($expected, $actual);
22
    }
23
24
    public function testUrlFileFromTheme()
25
    {
26
        $name  = 'bands/edguy';
27
        $file  = 'js/index.js';
28
        $theme = $this->theme($name)->findOrCreate();
29
30
        $expected = $this->getUrl($name, $file);
31
        $actual   = $theme->url($file);
32
33
        $this->assertEquals($expected, $actual);
34
    }
35
36
    public function getUrl($theme, $file = null)
37
    {
38
        $public = $this->getPublishable();
39
        $domain = $this->registerDomain();
40
41
        $file =  '/' . $file ?? '';
42
43
        return sprintf("%s/%s/%s%s", $domain, $public, $theme, $file);
44
    }
45
46
    private function registerDomain() : string
47
    {
48
        $env = new EnvHandler();
49
50
        $domain = 'http://localhost:8000';
51
52
        $env->set('APP_URL', $domain);
53
54
        return $domain;
55
    }
56
57
    private function getPublishable() : string
58
    {
59
        $config = new ConfigKeeper();
60
61
        return $config->publishable();
62
    }
63
}