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

Analyze tests directory with psalm #2311

Merged
merged 18 commits into from
May 31, 2021
Merged

Analyze tests directory with psalm #2311

merged 18 commits into from
May 31, 2021

Conversation

franmomu
Copy link
Contributor

Q A
Type improvement
BC Break no
Fixed issues

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).

@@ -22,8 +22,9 @@ class UnitOfWorkPerformanceTest extends BaseTest
*/
public function testComputeChanges()
{
$n = 10000;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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.

@franmomu
Copy link
Contributor Author

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.

Copy link
Member

@alcaeus alcaeus left a 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());
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

perfect, done.

@franmomu franmomu force-pushed the sa_tests branch 2 times, most recently from 0d2380c to d1301c4 Compare May 26, 2021 12:54
@franmomu
Copy link
Contributor Author

You mentioned there being a number of errors left. How would one go about fixing those?

I've created #2317

Copy link
Member

@alcaeus alcaeus left a 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());
Copy link
Member

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().

@alcaeus alcaeus merged commit 2355a19 into doctrine:2.3.x May 31, 2021
@alcaeus alcaeus added this to the 2.3.0 milestone May 31, 2021
@alcaeus alcaeus added the Task label May 31, 2021
@alcaeus alcaeus self-assigned this May 31, 2021
@alcaeus
Copy link
Member

alcaeus commented May 31, 2021

Thanks @franmomu!

@alcaeus alcaeus modified the milestones: 2.3.0-alpha1, 2.3.0 Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants