You've already forked Php-Template
initial
This commit is contained in:
46
tests/Helpers/EnvTest.php
Normal file
46
tests/Helpers/EnvTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Helpers;
|
||||
|
||||
use Siteworxpro\App\Helpers\Env;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
class EnvTest extends Unit
|
||||
{
|
||||
public function testGetReturnsStringByDefault(): void
|
||||
{
|
||||
putenv('TEST_KEY=example');
|
||||
$result = Env::get('TEST_KEY');
|
||||
$this->assertSame('example', $result);
|
||||
}
|
||||
|
||||
public function testGetReturnsDefaultIfKeyNotSet(): void
|
||||
{
|
||||
putenv('TEST_KEY'); // Unset the environment variable
|
||||
$result = Env::get('TEST_KEY', 'default_value');
|
||||
$this->assertSame('default_value', $result);
|
||||
}
|
||||
|
||||
public function testGetCastsToBoolean(): void
|
||||
{
|
||||
putenv('TEST_KEY=true');
|
||||
$result = Env::get('TEST_KEY', null, 'bool');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testGetCastsToInteger(): void
|
||||
{
|
||||
putenv('TEST_KEY=123');
|
||||
$result = Env::get('TEST_KEY', null, 'int');
|
||||
$this->assertSame(123, $result);
|
||||
}
|
||||
|
||||
public function testGetCastsToFloat(): void
|
||||
{
|
||||
putenv('TEST_KEY=123.45');
|
||||
$result = Env::get('TEST_KEY', null, 'float');
|
||||
$this->assertSame(123.45, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user