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

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

Open
Ocramius opened this issue Oct 15, 2020 · 4 comments

Comments

@Ocramius
Copy link

Ocramius commented Oct 15, 2020

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
@weirdan
Copy link
Member

weirdan commented Oct 17, 2020

it seems like the translation from setUp to __construct isn't really working as expected thinking

It seems it's much easier than that - Psalm just doesn't trigger afterCodebasePopulated in this use case.
@muglug, should it do that?

@Ocramius
Copy link
Author

@weirdan is there a code reference? Perhaps somebody can send a patch, after having this knowledge...

@MauricioFauth

This comment was marked as off-topic.

@orklah

This comment was marked as off-topic.

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

No branches or pull requests

4 participants