|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\DependencyInjection\Container;
|
16 | 16 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
| 17 | +use Symfony\Component\DependencyInjection\EnvVarProcessor; |
17 | 18 | use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
18 | 19 | use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
19 | 20 | use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
20 | 21 | use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
21 | 22 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
| 23 | +use Symfony\Component\DependencyInjection\ServiceLocator; |
22 | 24 | use Symfony\Contracts\Service\ResetInterface;
|
23 | 25 |
|
24 | 26 | class ContainerTest extends TestCase
|
@@ -405,6 +407,33 @@ public function testRequestAnInternalSharedPrivateService()
|
405 | 407 | $c->get('internal_dependency');
|
406 | 408 | $c->get('internal');
|
407 | 409 | }
|
| 410 | + |
| 411 | + public function testGetEnvDoesNotAutoCastNullWithDefaultEnvVarProcessor() |
| 412 | + { |
| 413 | + $container = new Container(); |
| 414 | + $container->setParameter('env(FOO)', null); |
| 415 | + $container->compile(); |
| 416 | + |
| 417 | + $r = new \ReflectionMethod($container, 'getEnv'); |
| 418 | + $r->setAccessible(true); |
| 419 | + $this->assertNull($r->invoke($container, 'FOO')); |
| 420 | + } |
| 421 | + |
| 422 | + public function testGetEnvDoesNotAutoCastNullWithEnvVarProcessorsLocatorReturningDefaultEnvVarProcessor() |
| 423 | + { |
| 424 | + $container = new Container(); |
| 425 | + $container->setParameter('env(FOO)', null); |
| 426 | + $container->set('container.env_var_processors_locator', new ServiceLocator([ |
| 427 | + 'string' => static function () use ($container): EnvVarProcessor { |
| 428 | + return new EnvVarProcessor($container); |
| 429 | + }, |
| 430 | + ])); |
| 431 | + $container->compile(); |
| 432 | + |
| 433 | + $r = new \ReflectionMethod($container, 'getEnv'); |
| 434 | + $r->setAccessible(true); |
| 435 | + $this->assertNull($r->invoke($container, 'FOO')); |
| 436 | + } |
408 | 437 | }
|
409 | 438 |
|
410 | 439 | class ProjectServiceContainer extends Container
|
|
0 commit comments