idea-php-phpunit-plugin icon indicating copy to clipboard operation
idea-php-phpunit-plugin copied to clipboard

Autocomplete does not work for indirectly created MockObjects - how to aid class detection in plugin?

Open tlamy opened this issue 4 years ago • 1 comments

We use a custom DIC in our projects, and also provide an abstract PHPUnit TestCase that automatically mocks constructor dependencies for units under test. To access these auto mocks we provide something like

    /**
     * @param class-string $className
     * @return MockObject
     */
    protected function getMockFromContainer(string $className): MockObject
    {}

but method autocomplete does not work, obviously because the plugin does not know which class is mocked.

For the plugin's business, getMockFromContainer($className) should behave like createMock($className). Is there a way to configure such aliases?

tlamy avatar Dec 13 '21 07:12 tlamy

Try this (with a recent version of PhpStorm):

    /**
     * @template T
     * @param class-string<T> $className
     * @return MockObject&T
     */
    protected function getMockFromContainer(string $className): MockObject
    {}

InvisibleSmiley avatar Jan 20 '22 07:01 InvisibleSmiley