Failed Conditions
Branch feature/refactoring-samurai (8cc7c1)
by Giuliano
03:49
created

EnvHandlerTestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAndSetEnvVariable() 0 9 1
A setUp() 0 3 1
A testIfCanCreateEnvFile() 0 12 2
A tearDown() 0 5 1
A testIfCanCreateEnvFileWithDefaultName() 0 7 1
1
<?php
2
3
namespace Maestriam\Samurai\Tests\Unit\Foundation\EnvHandler;
4
5
use Maestriam\Samurai\Tests\TestCase;
6
use Maestriam\Samurai\Foundation\EnvHandler;
7
8
/**
9
 * Testes de funcionalidades básicas apresentadas no README.md
10
 */
11
class EnvHandlerTestCase extends TestCase
12
{
13
    /**
14
     * Instancia a classe de validação para ser testada
15
     *
16
     * @return void
17
     */
18
    public function setUp() : void
19
    {
20
        parent::setUp();
21
    }    
22
23
    /**
24
     * Verifica se consegue definir um valor no arquivo de configurações
25
     * de ambiente do projeto Laravel
26
     *
27
     * @return void
28
     */
29
    public function testGetAndSetEnvVariable()
30
    {        
31
        $key = 'THEME_CURRENT';
32
        $val = 'bands/kix';
33
        
34
        $handler = new EnvHandler();        
35
        $handler->set($key, $val);
36
37
        $this->assertIsString($handler->get($key));
38
    }
39
40
    /**
41
     * Verifica se consegue criar um novo arquivo de configurações
42
     * se caso não exista no projeto.
43
     * Por padrão, sempre deve ser criado na raíz do projeto (base_path())
44
     * 
45
     * @return void
46
     */
47
    public function testIfCanCreateEnvFile()
48
    {
49
        $filename = config('samurai.env_file');
50
        $filepath = base_path($filename);
51
52
        if (file_exists($filepath)) {
53
            unlink($filepath);
54
        }
55
56
        $handler = new EnvHandler();
0 ignored issues
show
Unused Code introduced by
The assignment to $handler is dead and can be removed.
Loading history...
57
58
        $this->assertFileExists($filepath);
59
    }
60
61
    /**
62
     * Verifica se consegue criar um novo arquivo de configuração,
63
     * caso não tenha um nome definido na configuração do pacote.
64
     * Por padrão, o nome sempre será .env e ficará na raíz do projeto
65
     *
66
     * @return void
67
     */
68
    public function testIfCanCreateEnvFileWithDefaultName()
69
    {
70
        config(['samurai.env_file' => null]);
71
        
72
        $handler = new EnvHandler();
73
74
        $this->assertFileExists($handler->file());
75
    }    
76
77
    public function tearDown(): void
78
    {
79
        $handler = new EnvHandler();
80
81
        $handler->set('THEME_CURRENT', '');
82
    }
83
}
84