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

UseThemeTest::currentTheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Maestriam\Samurai\Tests\Unit\Entities\Theme;
4
5
use Maestriam\Samurai\Entities\Theme;
6
use Maestriam\Samurai\Exceptions\ThemeNotFoundException;
7
use Maestriam\Samurai\Foundation\ConfigKeeper;
8
use Maestriam\Samurai\Foundation\EnvHandler;
9
10
class UseThemeTest extends ThemeTestCase
11
{
12
    public function testUseExistingTheme()
13
    {
14
        $name  = 'bands/accept';
15
        $theme = new Theme($name);
16
17
        $ret = $theme->make()->use();
18
19
        $current = $this->currentTheme();
20
21
        $this->assertValidTheme($ret);
22
        $this->assertEquals($current, $name);
23
    }
24
25
    public function testUseInexistingTheme()
26
    {
27
        $name = 'bands/accept';
28
        
29
        $theme = new Theme($name);
30
31
        $this->expectException(ThemeNotFoundException::class);
32
33
        $theme->use();
34
    }
35
    
36
    private function currentTheme() : string
37
    {
38
        $key = $this->getEnvKey();
39
40
        $env = new EnvHandler();
41
42
        return $env->get($key);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $env->get($key) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
43
    }
44
        
45
    private function getEnvKey() : string
46
    {
47
        $config = new ConfigKeeper();
48
        
49
        return $config->env();
50
    }
51
}