-
Notifications
You must be signed in to change notification settings - Fork 33
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
PHPUnit setup methods should be treated equally to constructors #107
Comments
An easy, albeit not 100% correct approach could be to suppress |
This is what I'm about to do at the project level but you're right, it will suppress other issues than this. E.g. sebastianbergmann/phpunit#4307 which still exists for some other properties like |
Would it be possible to introduce something like an annotation to tell psalm |
Also having this issue. Has there been any progress on this? |
As you can see, the issue is still opened. Feel free to work on it if you look for progress ;) |
PHPUnit executes
setUp()
and other@before
methods on each test run, so with regards to the test (test*()
and@test
) methods they behave more or less like a constructor.When analyzing test classes, Psalm and the PHPUnit plugin report the properties initialized in setup methods as not initialized in constructor.
While it's technically true, it's irrelevant for the test cases. By the time when the test method is invoked, the property will be initialized.
It is possible to rework such tests to initialize the object explicitly for each test method but this is less convenient, more verbose and in fact invalidates the PHPUnit setup approach.
The text was updated successfully, but these errors were encountered: