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

Undo bindings when they're unused? #54693

Open
janopae opened this issue Apr 22, 2024 · 1 comment
Open

Undo bindings when they're unused? #54693

janopae opened this issue Apr 22, 2024 · 1 comment

Comments

@janopae
Copy link

janopae commented Apr 22, 2024

Symfony version(s) affected

>=3.4.0-BETA1

Description

In config_test.yaml, I replaced service definitions with mocks. Now, a parameter binding defined in the general config.yaml is not needed anymore. Because of this, the Kernel doesn't compile and throws InvalidArgumentException: A binding is configured for an argument of type "string" named … under "_defaults" in file…, but no corresponding argument has been found. It may be unused and should be removed, or it may have a typo

It seems like I'm supposed to undo the bind in the testing config, but I can't undo yaml keys.

How to reproduce

Bind a parameter by name and/or type and use it in a service:

# services.yaml
services:
    _defaults:
        bind:
            string $mystring: 'Hello'
public class MyClass {
    public function __construct(
        public readonly string $mystring;
    ){};
}

Overwrite the using service in your test config:

# config_test.yaml
services:
    PHPUnit\Framework\MockObject\Generator\Generator: ~

    MyClass:
        factory: ['@PHPUnit\Framework\MockObject\Generator\Generator', 'testDouble']
        arguments:
            $type: '\MyClass'
            $mockObject: true
            $callOriginalConstructor: false
            $callOriginalClone: false
            $cloneArguments: false
            $allowMockingUnknownTypes: false
        public: true

See the mentioned error every time you use the container in a KernelTestCase.

Possible Solution

Don't throw an exception when there are unused bindings – raise warning or info instead

Additional Context

No response

@OskarStark
Copy link
Contributor

So this bug exists in 5.4? Because 3.4 and 4.4 are not maintained anymore, if yes please update the description. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants