GetEnvVariableTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeWithtNullableKey() 0 9 1
A setUp() 0 3 1
A testGetWithInvalidTypeKey() 0 7 1
A testGetEnvVariableInvalid() 0 7 1
1
<?php
2
3
namespace Maestriam\Samurai\Tests\Unit\Foundation\EnvHandler;
4
5
use Maestriam\Samurai\Foundation\EnvHandler;
6
use stdClass;
7
8
/**
9
 * Testes de funcionalidades básicas apresentadas no README.md
10
 */
11
class GetEnvVariableTest extends EnvHandlerTestCase
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 é possível recuperar um valor de uma variavel de ambiente inexistente
25
     * no arquivo     
26
     *
27
     * @return void
28
     */
29
    public function testGetEnvVariableInvalid()
30
    {
31
        $key = 'THEME_CURRENT_' . time();
32
        
33
        $handler = new EnvHandler();
34
35
        $this->assertNull($handler->get($key));
36
    }
37
38
    /**
39
     * Verifica se é possível tentar recuperar uma chave, sem passar o nome
40
     * dela na função get.
41
     * Por padrão, deve emitir um erro de argumento
42
     *
43
     * @return void
44
     */
45
    public function testGeWithtNullableKey()
46
    {   
47
        $handler = new EnvHandler();
48
49
        $this->expectException(\ArgumentCountError::class);
50
        $handler->get();
0 ignored issues
show
Bug introduced by
The call to Maestriam\Samurai\Foundation\EnvHandler::get() has too few arguments starting with key. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        $handler->/** @scrutinizer ignore-call */ 
51
                  get();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
51
        
52
        $this->expectException(\ArgumentCountError::class);
53
        $handler->get(null);       
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type string expected by parameter $key of Maestriam\Samurai\Foundation\EnvHandler::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        $handler->get(/** @scrutinizer ignore-type */ null);       
Loading history...
54
    }
55
56
    /**
57
      * Verifica se é possível tentar recuperar uma chave, passando 
58
     * tipos diferentes de string
59
     * Por padrão, deve emitir um ErrorException
60
     *
61
     * @return void
62
     */
63
    public function testGetWithInvalidTypeKey()
64
    {
65
        $this->expectException(\ErrorException::class);
66
        $handler->get([]);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $handler seems to be never defined.
Loading history...
67
68
        $this->expectException(\ErrorException::class);
69
        $handler->get(new stdClass());
70
    }
71
}