Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add ShouldCallParentMethodsRule #79

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

Merged
ondrejmirtes merged 3 commits into phpstan:master from canvural:patch-1
Jul 28, 2020
Merged

Conversation

@canvural
Copy link
Contributor

@canvural canvural commented Jul 18, 2020

Closes #78

rules.neon Outdated
- PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule
- PHPStan\Rules\PHPUnit\AssertSameWithCountRule
- PHPStan\Rules\PHPUnit\MockMethodCallRule
- PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule
Copy link
Member

@ondrejmirtes ondrejmirtes Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this as a new rule which would block another 0.12.x release, could you:

  1. Require PHPStan 0.12.33 as it contains the bleedingEdge parameter
  2. Add this as a conditional rule like this:
conditionalTags:
 PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule:
 phpstan.rules.rule: %featureToggles.bleedingEdge%
services:
 -
 class: PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule

Copy link
Member

@ondrejmirtes ondrejmirtes Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have it in conditionalTags, it should no longer be in the rules section.

public function processNode(Node $node, Scope $scope): array
{
/** @var InClassMethodNode $node */
$node = $node;
Copy link
Member

@ondrejmirtes ondrejmirtes Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary, PHPStan already knows the type.

continue;
}

if (in_array(strtolower($stmt->expr->name->name), ['setup', 'teardown'], true)) {
Copy link
Member

@ondrejmirtes ondrejmirtes Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would accept parent::setUp() in tearDown method, and vice-versa. We need to be more strict.

{
$this->analyse([__DIR__ . '/data/missing-parent-method-calls.php'], [
[
'Missing call to parent::setUp method.',
Copy link
Member

@ondrejmirtes ondrejmirtes Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like 'Missing call to parent::setUp() method.'. more

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done :)

rules.neon Outdated
- PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule
- PHPStan\Rules\PHPUnit\AssertSameWithCountRule
- PHPStan\Rules\PHPUnit\MockMethodCallRule
- PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule
Copy link
Member

@ondrejmirtes ondrejmirtes Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have it in conditionalTags, it should no longer be in the rules section.

[
'Missing call to parent::setUp() method.',
32,
],[
Copy link
Member

@ondrejmirtes ondrejmirtes Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be formatted the same way as the next item (open square bracket on the next line)

@ondrejmirtes ondrejmirtes merged commit 20f23c9 into phpstan:master Jul 28, 2020
Copy link
Member

Thank you, I'll tag it once I have a computer again :)

canvural reacted with thumbs up emoji

Copy link
Member

Tagged as 0.12.14 :)

canvural reacted with rocket emoji

Copy link
Contributor Author

Great! Thanks.

Copy link
Member

FYI found out very quickly the logic wasn't quite right, just fixed it :) 264abf4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Feature Request] New rule for making sure parent setUp or tearDown methods are called if extending custom base test case

AltStyle によって変換されたページ (->オリジナル) /