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

PHPStanTestCase: Added a helper method to assert no errors happend #894

Merged
merged 1 commit into from
Dec 28, 2021

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Dec 28, 2021

in case the assertNoErrors assertion fails, the helper prints out the emitted errors to ease debugging.

before this PR a unit test which does not expect errors failed with:

$ vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php --bootstrap tests/bootstrap-static-reflection.php
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.

Warning:       No code coverage driver available

..............F.....................................              52 / 52 (100%)

Time: 00:02.842, Memory: 94.00 MB

There was 1 failure:

1) PHPStan\Analyser\AnalyserIntegrationTest::testExtendsPdoStatementCrash
Failed asserting that actual size 6 matches expected size 0.

DX wise this is not really helpful, as the next step is to add debugging statements, so we can actually see the errors.

with this PR we add a new assertNoErrors helper method which prints out the errors, so we can directly see the problem

$ vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php --bootstrap tests/bootstrap-static-reflection.php
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.

Warning:       No code coverage driver available

..............F.....................................              52 / 52 (100%)

Time: 00:02.842, Memory: 94.00 MB

There was 1 failure:

1) PHPStan\Analyser\AnalyserIntegrationTest::testExtendsPdoStatementCrash
Failed asserting that actual size 2 matches expected size 0.

Emitted errors:
- PHPDoc tag @return with type bool is incompatible with native type void
  in C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser\data\extends-pdo-statement.php on line 88

- Method ExtendsPdoStatementCrash\CrashSix::setFetchMode() with return type void returns true but should not return anything
  in C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser\data\extends-pdo-statement.php on line 90

@staabm staabm changed the title Added a helper method to assert no errors happend PHPStanTestCase: Added a helper method to assert no errors happend Dec 28, 2021
@staabm staabm marked this pull request as ready for review December 28, 2021 11:07
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.

Thank you!

  1. Emitted-Errors - space instead of - and lower caps e in Errors please.
  2. Please include the error line in the error message as well.

@staabm
Copy link
Contributor Author

staabm commented Dec 28, 2021

adjusted per feedback. I went a step further and formatted the errors a bit more.

example:

$ vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php --bootstrap tests/bootstrap-static-reflection.php
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.

Warning:       No code coverage driver available

..............F.....................................              52 / 52 (100%)

Time: 00:03.076, Memory: 94.00 MB

There was 1 failure:

1) PHPStan\Analyser\AnalyserIntegrationTest::testExtendsPdoStatementCrash
Failed asserting that actual size 2 matches expected size 0.

Emitted errors:
- PHPDoc tag @return with type bool is incompatible with native type void
  in C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser\data\extends-pdo-statement.php on line 88

- Method ExtendsPdoStatementCrash\CrashSix::setFetchMode() with return type void returns true but should not return anything
  in C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser\data\extends-pdo-statement.php on line 90

in case the assertion fails, the helper prints out the emitted errors to ease debugging
@staabm
Copy link
Contributor Author

staabm commented Dec 28, 2021

remaining errors seem unrelated

@ondrejmirtes ondrejmirtes merged commit abf3cbe into phpstan:master Dec 28, 2021
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the no-errors branch December 28, 2021 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants