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

markTestIncomplete and markTestSkipped as earlyTerminatingMethodCalls #52

Open
arnaud-lb opened this issue Oct 3, 2019 · 4 comments
Open

Comments

@arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Oct 3, 2019

The extension marks markTestIncomplete and markTestSkipped as earlyTerminatingMethodCalls. The effect is that PHPStan will emit a Unreachable 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 or markTestSkipped, is to make some code unreachable/unexecuted without actually removing it.

@ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Oct 3, 2019

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 return; below calling these methods, and even a test that wasn't supposed to be always skipped. So I think it's even useful in this current form.

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.

@ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Oct 3, 2019

Until then, it's easy for users to ignore this with ignoreErrors key in phpstan.neon.

@daniele-xp
Copy link

@daniele-xp daniele-xp commented Mar 3, 2020

Hello 👋

We found this problem annoying too. Unreachable code analysis should not inspect code below markTestSkipped or other related phpunit early return methods.

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.

@grachevko
Copy link

@grachevko grachevko commented Mar 27, 2020

If i write static::markTestSkipped then i expected that code below will be unreachable.
Adding every time this to baseline maybe force me to make tests not skipped, but it is not exactly)

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.