Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertContainerBuilderServiceDecoration expect ContainerBuilderInterface #163

Open
choks87 opened this issue Mar 14, 2024 · 0 comments
Open

Comments

@choks87
Copy link

choks87 commented Mar 14, 2024

How to reproduce:

Within some test that extends AbstractExtensionTestCase:

Usage

$this->assertContainerBuilderServiceDecoration('foo', 'bar');

Will throw:

InvalidArgumentException: Expected an instance of Symfony\Component\DependencyInjection\ContainerBuilder

/var/www/html/vendor/matthiasnoback/symfony-dependency-injection-test/PhpUnit/DefinitionDecoratesConstraint.php:49
/var/www/html/vendor/matthiasnoback/symfony-dependency-injection-test/PhpUnit/AbstractContainerBuilderTestCase.php:245

Cause:

In assert Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractContainerBuilderTestCase:245 there is part:

$definition = $this->container->findDefinition($serviceId);

        self::assertThat($definition, new DefinitionDecoratesConstraint($serviceId, $decoratedServiceId, $renamedId, $priority, $invalidBehavior));

But in \Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionDecoratesConstraint::evaluate It expects ContainerBuilder:

    public function evaluate($other, string $description = '', bool $returnResult = false): bool
    {
        if (!($other instanceof ContainerBuilder)) {
            throw new \InvalidArgumentException(
                'Expected an instance of Symfony\Component\DependencyInjection\ContainerBuilder'
            );
        }

        return $this->evaluateServiceDefinition($other, $returnResult);
    }

Suggested Fix

    final protected function assertContainerBuilderServiceDecoration(
        string $serviceId,
        string $decoratedServiceId,
        ?string $renamedId = null,
        int $priority = 0,
        ?int $invalidBehavior = null
    ): void {
        self::assertThat($this->container, new DefinitionDecoratesConstraint($serviceId, $decoratedServiceId, $renamedId, $priority, $invalidBehavior));
    }
    ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant