Skip to content

MissingConstructor issues detected when explicitly specifying a test code analysis path #92

@Ocramius

Description

@Ocramius

While working on a project that uses very strict psalm settings and this plugin, we discovered that running vendor/bin/psalm with following configuration and no arguments, no issues are reported:

<?xml version="1.0"?>
<psalm
    totallyTyped="true"
    resolveFromConfigFile="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <projectFiles>
        <directory name="src"/>
        <directory name="tests/src"/>
        <ignoreFiles>
            <directory name="vendor"/>
        </ignoreFiles>
    </projectFiles>

    <issueHandlers>
        <InternalMethod>
            <errorLevel type="suppress">
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturnCallback"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::method"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::with"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::withConsecutive"/>
            </errorLevel>
        </InternalMethod>
    </issueHandlers>

    <plugins>
        <pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
    </plugins>
</psalm>

If I run vendor/bin/psalm tests (new argument added!), the output changes, and starts reporting stuff that is generally silenced by this plugin (the following, but for every test):

ERROR: MissingConstructor - tests/src/Unit/Presentation/UserViewTest.php:27:35 - SomeProject\Core\Tests\Unit\Presentation\UserViewTest has an uninitialized property $this->user, but no constructor (see https://psalm.dev/073)
    private UserSettingRepository $userSettingRepository;

Interestingly, no other errors around assertions nor anything: it seems like the translation from setUp to __construct isn't really working as expected 🤔

Tried it on updated dependencies BTW:

psalm/plugin-phpunit 0.12.2 Psalm plugin for PHPUnit
vimeo/psalm          3.17.2 A static analysis tool for finding errors in PHP applications

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions