Repository navigation
Run PHPStan on tests and fix reported issues - #206
Merged
Merged
Conversation
Add `tests` to the PHPStan paths (level 9 unchanged) and scan the wp-cli-tests TestCase so PHPStan knows the base class and its polyfills. Fix the 169 errors this reports in the test code: - add `void` return types to test methods and helpers - document parameters, properties and data provider return types with precise array types and shapes - reference `cli\table\Ascii` / `cli\table\Tabular` with their declared lowercase namespace - assert that fopen()/file_get_contents() succeeded before use - use assertCount() instead of assertSame() on count() - pass values that match the documented types (strings instead of ints in table rows, a valid int type for an invalid alignment, `false` instead of `null` to reset Colors) - test null cell values through the renderer and the Table constructor, which both accept mixed values, instead of through addRow() - avoid PHPStan remembering Colors::colorize() results across Colors::disable() by asserting on local variables - only restore mb_detect_order() with a non-empty list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5n3ZupvgHr4fEBJCGp
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PHPStan now analyses
tests/as well aslib/(level 9 unchanged). This PR fixes all 169 errors that turned up in the test code. It adds no ignores, no baseline and noignoreErrorsentries.Config
teststoparameters.paths.vendor/wp-cli/wp-cli-tests/tests/includes/TestCase.phptoscanFiles. The tests extendWP_CLI\Tests\TestCase, which isn't autoloaded, so PHPStan needs to scan it to know the base class.Test fixes
voidreturn types to test methods and helpers. Added@param/@vartypes and data provider return types with precise array shapes.cli\Table\Ascii/cli\Table\Tabulartocli\table\..., the case they are declared with (class.nameCase).assertNotFalse()/assertIsString()checks sofopen()andfile_get_contents()results are known to be valid before use.assertSame( n, count( ... ) )withassertCount().99)Colors::enable( false )replacesenable( null ); both reset to auto-detectionTabular::row()and theTableconstructor. Both accept mixed values, whereasaddRow()is documented asarray<int, string>. The expected output is the same.Colors::colorize()results are now asserted through local variables, because PHPStan otherwise carries the narrowed result acrossColors::disable().mb_detect_order()is only restored when the saved list is not empty.Testing
composer phpstan: no errors.composer phpunit: 105 tests pass. The single PHPUnit deprecation notice was already there before this change.Generated by Claude Code
Summary by CodeRabbit
Tests
Chores