ResolveParameterPlaceHoldersPass example



    public function testProcessConsiderEnvVariablesAsUsedEvenInPrivateServices()
    {
        $container = new ContainerBuilder();
        $container->setParameter('env(FOOBAR)', 'test');
        $container
            ->register('foo')
            ->setArguments(['%env(FOOBAR)%'])
        ;

        $resolvePass = new ResolveParameterPlaceHoldersPass();
        $resolvePass->process($container);

        $this->process($container);

        $this->assertFalse($container->hasDefinition('foo'));

        $envCounters = $container->getEnvCounters();
        $this->assertArrayHasKey('FOOBAR', $envCounters);
        $this->assertSame(1, $envCounters['FOOBAR']);
    }

    
new RegisterEnvVarProcessorsPass(),
            ],
            -1000 => [new ExtensionCompilerPass()],
        ];

        $this->optimizationPasses = [[
            new AutoAliasServicePass(),
            new ValidateEnvPlaceholdersPass(),
            new ResolveDecoratorStackPass(),
            new ResolveChildDefinitionsPass(),
            new RegisterServiceSubscribersPass(),
            new ResolveParameterPlaceHoldersPass(false, false),
            new ResolveFactoryClassPass(),
            new ResolveNamedArgumentsPass(),
            new AutowireRequiredMethodsPass(),
            new AutowireRequiredPropertiesPass(),
            new ResolveBindingsPass(),
            new ServiceLocatorTagPass(),
            new DecoratorServicePass(),
            new CheckDefinitionValidityPass(),
            new AutowirePass(false),
            new ServiceLocatorTagPass(),
            new ResolveTaggedIteratorArgumentPass(),
            
new RegisterEnvVarProcessorsPass(),
            ],
            -1000 => [new ExtensionCompilerPass()],
        ];

        $this->optimizationPasses = [[
            new AutoAliasServicePass(),
            new ValidateEnvPlaceholdersPass(),
            new ResolveDecoratorStackPass(),
            new ResolveChildDefinitionsPass(),
            new RegisterServiceSubscribersPass(),
            new ResolveParameterPlaceHoldersPass(false, false),
            new ResolveFactoryClassPass(),
            new ResolveNamedArgumentsPass(),
            new AutowireRequiredMethodsPass(),
            new AutowireRequiredPropertiesPass(),
            new ResolveBindingsPass(),
            new ServiceLocatorTagPass(),
            new DecoratorServicePass(),
            new CheckDefinitionValidityPass(),
            new AutowirePass(false),
            new ServiceLocatorTagPass(),
            new ResolveTaggedIteratorArgumentPass(),
            
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;

class ResolveParameterPlaceHoldersPassTest extends TestCase
{
    private ResolveParameterPlaceHoldersPass $compilerPass;
    private ContainerBuilder $container;
    private Definition $fooDefinition;

    protected function setUp(): void
    {
        $this->compilerPass = new ResolveParameterPlaceHoldersPass();
        $this->container = $this->createContainerBuilder();
        $this->compilerPass->process($this->container);
        $this->fooDefinition = $this->container->getDefinition('foo');
    }

    public function testClassParametersShouldBeResolved()
    {
        $this->assertSame('Foo', $this->fooDefinition->getClass());
    }

    public function testFactoryParametersShouldBeResolved()
    {

        putenv('ARRAY={"foo":"bar"}');

        $container = new ContainerBuilder(new EnvPlaceholderParameterBag([
            'ccc' => '%env(json:ARRAY)%',
        ]));

        $container
            ->register('foobar', BarMethodCall::class)
            ->addMethodCall('setArray', ['%ccc%']);

        (new ResolveParameterPlaceHoldersPass())->process($container);
        (new CheckTypeDeclarationsPass(true))->process($container);

        $this->addToAssertionCount(1);

        putenv('ARRAY=');
    }

    public function testProcessHandleNotFoundEnvPlaceholder()
    {
        $container = new ContainerBuilder(new EnvPlaceholderParameterBag([
            'ccc' => '%env(json:ARRAY)%',
        ]));
Home | Imprint | This part of the site doesn't use cookies.