-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
Analyze tests directory with psalm #2311
Conversation
@@ -22,8 +22,9 @@ class UnitOfWorkPerformanceTest extends BaseTest | |||
*/ | |||
public function testComputeChanges() | |||
{ | |||
$n = 10000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -17,11 +17,6 @@ public function __construct($name = null) | |||
$this->name = $name; | |||
} | |||
|
|||
public function getId() | |||
{ | |||
return $this->id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id
property is not in the class.
I got caught up making changes 😬 , I've tried to split it in commits and just change simple things that should be easy to review, otherwise let me know and I can split it in PRs. After this there are just 130 remaining issues in phpstan in tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. You mentioned there being a number of errors left. How would one go about fixing those?
@@ -518,7 +518,6 @@ public function testCommitsInProgressIsUpdatedOnException() | |||
$this->expectExceptionMessage('This should not happen'); | |||
|
|||
$this->dm->flush(); | |||
$this->assertAttributeSame(0, 'commitsInProgress', $this->dm->getUnitOfWork()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace this assertion in a different way, maybe by accessing the attribute in a bound closure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm the thing about this line is that it never gets executed because the flush()
method throws an exception, but reading the test name: testCommitsInProgressIsUpdatedOnException
maybe that exception should be catch and check the commitsInProgress
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, yes. The method should catch the exception, check the commitsInProgress
property and then return. If no exception was caught, the test should fail using $this->fail()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect, done.
There should be added to the mongodb stub of psalm, we are using findUnusedPsalmSuppress configuration option, so it will warn us when this is fixed.
0d2380c
to
d1301c4
Compare
I've created #2317 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question about the new @psalm-suppress
, but the rest looks good!
@@ -518,7 +518,6 @@ public function testCommitsInProgressIsUpdatedOnException() | |||
$this->expectExceptionMessage('This should not happen'); | |||
|
|||
$this->dm->flush(); | |||
$this->assertAttributeSame(0, 'commitsInProgress', $this->dm->getUnitOfWork()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, yes. The method should catch the exception, check the commitsInProgress
property and then return. If no exception was caught, the test should fail using $this->fail()
.
Thanks @franmomu! |
Summary
Adding static analysis to
tests
directory allow us to spot some issues.In this case with psalm since with phpstan there are quite a lot issues, I'll be creating PRs to try to fix them little by little (there were more than 300).