forked from shlinkio/shlink-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request shlinkio#16 from acelaya-forks/feature/env-function
Feature/env function
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Config\Functions; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
use function putenv; | ||
use function Shlinkio\Shlink\Config\env; | ||
|
||
class FunctionsTest extends TestCase | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
putenv('TRUE_VALUE=true'); | ||
putenv('TRUE_VALUE_PARENTHESES=(true)'); | ||
putenv('FALSE_VALUE=false'); | ||
putenv('FALSE_VALUE_PARENTHESES=(false)'); | ||
putenv('EMPTY_VALUE=empty'); | ||
putenv('EMPTY_VALUE_PARENTHESES=(empty)'); | ||
putenv('NULL_VALUE=null'); | ||
putenv('NULL_VALUE_PARENTHESES=(null)'); | ||
putenv('REGULAR_VALUE= foo '); | ||
} | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
putenv('TRUE_VALUE='); | ||
putenv('TRUE_VALUE_PARENTHESES='); | ||
putenv('FALSE_VALUE='); | ||
putenv('FALSE_VALUE_PARENTHESES='); | ||
putenv('EMPTY_VALUE='); | ||
putenv('EMPTY_VALUE_PARENTHESES='); | ||
putenv('NULL_VALUE='); | ||
putenv('NULL_VALUE_PARENTHESES='); | ||
putenv('REGULAR_VALUE='); | ||
} | ||
|
||
/** @test */ | ||
public function envReturnsDefaultValueForUndefinedEnvVars(): void | ||
{ | ||
self::assertEquals(null, env('THIS_DOES_NOT_EXIST')); | ||
self::assertEquals('default', env('THIS_DOES_NOT_EXIST', 'default')); | ||
} | ||
|
||
/** @test */ | ||
public function specificValueKeywordsAreParsed(): void | ||
{ | ||
self::assertTrue(env('TRUE_VALUE')); | ||
self::assertTrue(env('TRUE_VALUE_PARENTHESES')); | ||
self::assertFalse(env('FALSE_VALUE')); | ||
self::assertFalse(env('FALSE_VALUE_PARENTHESES')); | ||
self::assertEmpty(env('EMPTY_VALUE')); | ||
self::assertEmpty(env('EMPTY_VALUE_PARENTHESES')); | ||
self::assertNull(env('NULL_VALUE')); | ||
self::assertNull(env('NULL_VALUE_PARENTHESES')); | ||
} | ||
|
||
/** @test */ | ||
public function regularValuesAreTrimmed(): void | ||
{ | ||
self::assertEquals('foo', env('REGULAR_VALUE')); | ||
} | ||
} |