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

ParentTest::testCanGetDefaultValueForEnvVar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
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