Skip to content

Declare the constructor of TestCase in the stub - #293

Merged
orklah merged 1 commit into
psalm:masterfrom
orklah:stub-declares-testcase-constructor
Nov 25, 2026
Merged

orklah merged 1 commit into
psalm:masterfrom
orklah:stub-declares-testcase-constructor

Conversation

@orklah

@orklah orklah commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

With vimeo/psalm#15001, a test case that leaves a property uninitialized and has no setUp() or other initializer no longer gets MissingConstructor: that PR skips the check when the inherited constructor is the real one of a class a stub leaves it out of, as this stub does for TestCase. Declaring the constructor in the stub keeps the current behaviour on every Psalm version.

Before (Psalm with vimeo/psalm#15001, scenario Stateful test case without @before or setUp produces MissingConstructor)

final class MyTestCase extends TestCase
{
    /** @var I&\PHPUnit\Framework\MockObject\Stub */
    private $i; // no issue
}

After

    private $i; // MissingConstructor

vimeo/psalm#15001 stops reporting MissingConstructor when the inherited
constructor is the real one of a class a stub leaves it out of. Declaring
it keeps the MissingConstructor of test cases without an initializer, on
every Psalm version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@orklah
orklah merged commit d84de7b into psalm:master Nov 25, 2026
8 checks passed
@orklah
orklah deleted the stub-declares-testcase-constructor branch November 25, 2026 20:45
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

Successfully merging this pull request may close these issues.

1 participant