1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
<?php
declare(strict_types=1);
namespace DI\Test\UnitTest\Definition;
use DI\Definition\EnvironmentVariableDefinition;
use PHPUnit\Framework\TestCase;
/**
* @covers \DI\Definition\EnvironmentVariableDefinition
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\DI\Definition\EnvironmentVariableDefinition::class)]
class EnvironmentVariableDefinitionTest extends TestCase
{
public function test_getters()
{
$definition = new EnvironmentVariableDefinition('bar', false, 'default');
$definition->setName('foo');
$this->assertEquals('foo', $definition->getName());
$this->assertEquals('bar', $definition->getVariableName());
$this->assertFalse($definition->isOptional());
$this->assertEquals('default', $definition->getDefaultValue());
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_cast_to_string()
{
$str = 'Environment variable (
variable = bar
optional = no
)';
$this->assertEquals($str, (string) new EnvironmentVariableDefinition('bar'));
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_cast_to_string_with_default_value()
{
$str = 'Environment variable (
variable = bar
optional = yes
default = \'<default>\'
)';
$this->assertEquals($str, (string) new EnvironmentVariableDefinition('bar', true, '<default>'));
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_cast_to_string_with_reference_as_default_value()
{
$str = 'Environment variable (
variable = bar
optional = yes
default = get(foo)
)';
$this->assertEquals($str, (string) new EnvironmentVariableDefinition('bar', true, \DI\get('foo')));
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_cast_to_string_with_nested_definition_as_default_value()
{
$str = 'Environment variable (
variable = bar
optional = yes
default = Environment variable (
variable = foo
optional = no
)
)';
$this->assertEquals($str, (string) new EnvironmentVariableDefinition('bar', true, new EnvironmentVariableDefinition('foo')));
}
}
|