From b3d6676b6e7d6615e990ee586b7dd18aa7a25d56 Mon Sep 17 00:00:00 2001 From: RM Date: Wed, 25 Nov 2026 21:36:15 +0100 Subject: [PATCH] Declare the constructor of TestCase in the stub 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 --- AGENTS.md | 2 +- stubs/TestCase.phpstub | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4ff333d..1085846 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -33,7 +33,7 @@ Layout: metadata is ignored by PHPUnit, so the plugin reports it and stops honouring it in `TestCaseHandler`. - `src/Hooks/MissingParentCallHandler.php` and `src/Issue/MissingParentCall.php`: the `AfterClassLikeAnalysis` hook and plugin issue for `setUp()`-style overrides without a `parent::` call. -- `stubs/TestCase.phpstub`: hides the constructor of `TestCase` (see the stub) and makes `assertNotEmpty()` +- `stubs/TestCase.phpstub`: declares the constructor of `TestCase` (see the stub) and makes `assertNotEmpty()` narrow its argument. - `tests/acceptance/*.feature`: the Behat scenarios, the only test suite that CI runs. One file per area (`DataProviders`, `NamedDatasets`, `Narrowing`, `MockMethod`, ...): add a scenario to the file of the area diff --git a/stubs/TestCase.phpstub b/stubs/TestCase.phpstub index 77508e7..df2495a 100644 --- a/stubs/TestCase.phpstub +++ b/stubs/TestCase.phpstub @@ -2,11 +2,12 @@ namespace PHPUnit\Framework; /** - * Without a constructor here, Psalm reports a property that setUp() initializes as MissingConstructor, which - * TestCaseHandler suppresses, rather than as PropertyNotSetInConstructor of TestCase's final constructor. + * Psalm doesn't analyse a stubbed constructor, so it reports a property that a test case leaves uninitialized as + * MissingConstructor, which TestCaseHandler suppresses when setUp() or another initializer sets it. */ abstract class TestCase extends Assert implements Test, SelfDescribing { + final public function __construct(string $name) {} } abstract class Assert