-
Notifications
You must be signed in to change notification settings - Fork 46
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
markTestIncomplete and markTestSkipped as earlyTerminatingMethodCalls #52
Comments
It's currently hard to have the one advantage (to correctly find undefined variables) and not the other (finding unreachable code). When I first ran this analysis on codebase at my dayjob, it found some useful cases - like having a redundant I usually use markTestSkipped conditionally in tests, so this problem does not apply to my usage. But I'm gonna leave this open - it's theoretically possible to solve this by introducing some kind of option to NodeScopeResolver in PHPStan core. |
Until then, it's easy for users to ignore this with |
Hello 👋 We found this problem annoying too. Unreachable code analysis should not inspect code below public function testService(): void
{
$this->markTestSkipped('Skipped due temporary unavailable service');
// ..... unreachable test code here ....
} Our dirty temporary solution is to rename the test method: // Skipped due temporary unavailable service
public function skipTestService(): void
{
// ..... unreachable test code here ....
} It is not the same of course. Phpunit cannot recognize and report skipped test in this way. |
If i write static::markTestSkipped then i expected that code below will be unreachable. |
@ondrejmirtes 2 cents from my experience: today one of our tests was skipped because of some problems and when I've rebased my changes on newest develop branch I got CI failure because of that even though my changes weren't related to that test (actually there weren't any changes in code, just technical stuff).. I don't see it useful to add it to baseline files every time something like this happens 🤔 Would be great to be able to turn this rule off and consider |
Please default to meaningful behavior. I put It's the point of that statement! Skipping but not deleting a test for it to be fixed at a later state. An I don't want to ignore these kind of errors. It should never be an error to begin with. |
Anyone have sensible workarounds? This is what I will do for now
|
You can wrap the method call in an if (time() > 1000) {
$this->markTestIncomplete('This test is still incomplete.');
} This could be a slightly ugly but easy way to make the error by phpstan to disappear. |
Should we add something like |
@VincentLanglet I'd rather invent a PHPDoc tag for this. |
Since only the next line is reported, this works fine: $this->markTestSkipped('Not implemented yet');
// @phpstan-ignore-next-line With this apporach you are able to ignore only the skips you want to be and not ignoring them globally |
Main reason is that Phpstan does not respect phpunit methods like: `markTestSkipped()` and `markTestIncomplete()`. Since tests is pseudo code/tooling I choose to take the approach to skip Phpstan scanning in out unit tests. Read more here: phpstan/phpstan-phpunit#52 (comment)
Main reason is that Phpstan does not respect phpunit methods like: `markTestSkipped()` and `markTestIncomplete()`. Since tests is pseudo code/tooling I choose to take the approach to skip Phpstan scanning in out unit tests. Read more here: phpstan/phpstan-phpunit#52 (comment)
Main reason is that Phpstan does not respect phpunit methods like: `markTestSkipped()` and `markTestIncomplete()`. Since tests is pseudo code/tooling I choose to take the approach to skip Phpstan scanning in out unit tests. Read more here: phpstan/phpstan-phpunit#52 (comment)
Main reason is that Phpstan does not respect phpunit methods like: `markTestSkipped()` and `markTestIncomplete()`. Since tests is pseudo code/tooling I choose to take the approach to skip Phpstan scanning in out unit tests. Read more here: phpstan/phpstan-phpunit#52 (comment)
Note on the last workaround: the comment must precede the next non-whitespace line with actual code. If the next line is empty, the error will still be reported. |
The extension marks
markTestIncomplete
andmarkTestSkipped
asearlyTerminatingMethodCalls
. The effect is that PHPStan will emit aUnreachable statement - code above always terminates.
error for any code after them.I found that this is not necessary useful. I mean, this error is useful for detecting unexpectedly unreachable statements, but the goal of
markTestIncomplete
ormarkTestSkipped
, is to make some code unreachable/unexecuted without actually removing it.The text was updated successfully, but these errors were encountered: