Skip to content

Conflict with Phpstorm resolution. #56

@VincentLanglet

Description

@VincentLanglet

I'm using

"phpstan/phpstan": "0.12.*",
"phpstan/phpstan-phpunit": "0.12.*",
"phpunit/phpunit": "8.2.5",

I have warning from Phpstorm 'void' method 'getMockBuilder' result used with the following code :

$pdfGenerator = $this->getMockBuilder(PdfGenerator::class)->getMock();

When I Cmd + Click, I see Phpstorm are locating the getMockBuilder in phpstan/phpstan-phpunit/stubs (instead of inside Phpunit package, maybe he take the first one in lexical order) with the following annotation:

	/**
	 * @template T
	 * @phpstan-param class-string<T> $originalClassName
	 * @phpstan-return MockObject&T
	 */
	public function createConfiguredMock($originalClassName) {}

And theses annotations are not understood by Phpstorm.

Changing to

	/**
	 * @template T
	 * @phpstan-param class-string<T> $originalClassName
	 * @phpstan-return MockObject&T
         * @return MockBuilder
	 */
	public function createConfiguredMock($originalClassName) {}

Fix the issue.

By the way, in Phpunit code, the annotations are

/**
     * Returns a builder object to create mock objects using a fluent interface.
     *
     * @param string|string[] $className
     *
     * @psalm-template RealInstanceType of object
     * @psalm-param class-string<RealInstanceType>|string[] $className
     * @psalm-return MockBuilder<RealInstanceType>
     */
    public function getMockBuilder($className): MockBuilder
    {
        $this->recordDoubledType($className);

        return new MockBuilder($this, $className);
    }

So the returnType/paramsType are added both with the psalm syntax and the regular syntax.

Shouldn't the regular syntax be used too in the stubs provided by phpstan ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions