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

Set mock instance of interface into typed properties #1804

Open
dkarlovi opened this issue Jan 18, 2023 · 3 comments
Open

Set mock instance of interface into typed properties #1804

dkarlovi opened this issue Jan 18, 2023 · 3 comments

Comments

@dkarlovi
Copy link

dkarlovi commented Jan 18, 2023

Is your feature request related to a problem? Please describe.

A user has a class like so

interface Interface {}

class InterfaceInstance implements Interface
{
    public int $foo;
}

class C
{
    private Interface $prop;
    
    function foo(): int
    {
        return $this->prop->foo;
    }
}

Describe the solution you'd like

The user is typing an interface, but actually expecting the specific implementation to be available. Static analysis notices this when used.

A new mutator might set this property to a mocked interface which does the absolute minimum to match the interface, it would mean any reliance on the specific implementation would fail.

Describe alternatives you've considered

Incorporate static analysis output in some way instead?

Additional context

User claims "code works, tests work" and is wondering what is static analysis on about here.

@theofidry
Copy link
Member

I think this is related to #650

@dkarlovi
Copy link
Author

@theofidry in what way? I imagine this as a new mutator.

@maks-rafalko
Copy link
Member

It will be caught by https://github.com/Roave/infection-static-analysis-plugin, and actually related to #1323

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

3 participants