Passed
Push — master ( 4956b8...9ed26a )
by Jean Paul
01:50
created

ParentTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEnvironmentVariable() 0 8 4
A testCanGetDefaultValueForEnvVar() 0 8 1
1
<?php declare( strict_types=1 );
2
3
namespace Coco\SourceWatcher\Tests\Common;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Class ParentTest
9
 *
10
 * @package Coco\SourceWatcher\Tests\Common
11
 */
12
class ParentTest extends TestCase
13
{
14
    protected function getEnvironmentVariable ( string $variableName, $default, $castingFunctionName = null )
15
    {
16
        if ( !empty( $castingFunctionName ) ) {
17
            return array_key_exists( $variableName, $_ENV ) ? call_user_func( $castingFunctionName,
18
                $_ENV[$variableName] ) : $default;
19
        }
20
21
        return array_key_exists( $variableName, $_ENV ) ? $_ENV[$variableName] : $default;
22
    }
23
24
    public function testCanGetDefaultValueForEnvVar () : void
25
    {
26
        $variableName = "SOMETHING_NOT_SETUP_IN_ENV";
27
        $default = "a default value";
28
        $result = $this->getEnvironmentVariable( $variableName, $default );
29
        $expected = "a default value";
30
31
        $this->assertEquals( $expected, $result );
32
    }
33
}
34