Skip to content

Run PHPStan on tests and fix reported issues - #206

Merged
swissspidy merged 1 commit into
mainfrom
claude/elegant-mendel-hm9kcu
Dec 4, 2026
Merged

swissspidy merged 1 commit into
mainfrom
claude/elegant-mendel-hm9kcu

Conversation

@swissspidy

@swissspidy swissspidy commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Summary

PHPStan now analyses tests/ as well as lib/ (level 9 unchanged). This PR fixes all 169 errors that turned up in the test code. It adds no ignores, no baseline and no ignoreErrors entries.

Config

  • Added tests to parameters.paths.
  • Added vendor/wp-cli/wp-cli-tests/tests/includes/TestCase.php to scanFiles. The tests extend WP_CLI\Tests\TestCase, which isn't autoloaded, so PHPStan needs to scan it to know the base class.

Test fixes

  • Added void return types to test methods and helpers. Added @param/@var types and data provider return types with precise array shapes.
  • Changed cli\Table\Ascii / cli\Table\Tabular to cli\table\..., the case they are declared with (class.nameCase).
  • Added assertNotFalse() / assertIsString() checks so fopen() and file_get_contents() results are known to be valid before use.
  • Replaced assertSame( n, count( ... ) ) with assertCount().
  • Test inputs now match the documented lib types:
    • table cells are strings instead of ints
    • the invalid alignment uses an int (99)
    • Colors::enable( false ) replaces enable( null ); both reset to auto-detection
  • The null-cell test now goes through Tabular::row() and the Table constructor. Both accept mixed values, whereas addRow() is documented as array<int, string>. The expected output is the same.
  • Colors::colorize() results are now asserted through local variables, because PHPStan otherwise carries the narrowed result across Colors::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

    • Expanded coverage for command-line argument parsing and help-screen formatting, including cases with no options and flags-only output.
    • Strengthened checks for table rendering, null values, alignment validation, and temporary output handling.
    • Improved test setup and assertions across command-line, color, shell, and table tests.
  • Chores

    • Extended static analysis to include additional test code.

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
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

PHPStan now analyzes the tests directory and the WP-CLI test TestCase.php file. Test files add type declarations and annotations, update argument and table test inputs, and add checks for help output and temporary-file handling.

Changes: PHPStan Test Coverage and Test Updates

Layer / File(s) Summary
Expand PHPStan analysis scope
phpstan.neon.dist
PHPStan now analyzes the tests directory and the WP-CLI test TestCase.php file.
Update argument test fixtures and help-screen checks
tests/Test_Arguments.php
Argument fixtures use empty arrays, and argument-vector setup handles a non-array $_SERVER['argv']. Tests now check help-screen sections and whitespace.
Add types and guards to CLI test helpers
tests/Test_Cli.php, tests/Test_Colors.php, tests/Test_Shell.php, tests/bootstrap.php
Tests and the autoloader add return types or annotations. CLI test setup and multibyte detection guards are updated.
Update table renderer tests and inputs
tests/Test_Table.php, tests/Test_Table_Ascii.php
Table tests use the lowercase renderer namespace, add return types and output checks, and update inputs and assertions.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Other

Suggested reviewers: gitlost, mrsdizzie

Merge Risk: Minimal · up to 398d8

This change widens static analysis to the test suite and adds types and assertions to the tests. It does not change library behavior, so merge risk is minimal.

Security architecture risk: Minimal · up to 398d8

PHPStan now checks the test suite at the existing analysis level. The changes affect development checks and how tests exercise the CLI library, not how production callers use it.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Run PHPStan on tests and fix reported issues" matches the main change. The PR adds tests/ to PHPStan analysis, includes the wp-cli TestCase file, and fixes the resulting test-code errors th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Run PHPStan on tests and fix reported issues" matches the main change. The PR adds tests/ to PHPStan analysis, includes the wp-cli TestCase file, and fixes the resulting test-code errors through type annotations, namespace corrections, and input adjustments. The title is specific and concise, and it names both the analysis scope and the fixes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 132ffd18-9a16-45b2-a6e0-76c8d9e347d8
Commits

Reviewing files that changed from the base of the PR and between c64cd26 and 398d858.

Files selected for processing: 8

  • phpstan.neon.dist
  • tests/Test_Arguments.php
  • tests/Test_Cli.php
  • tests/Test_Colors.php
  • tests/Test_Shell.php
  • tests/Test_Table.php
  • tests/Test_Table_Ascii.php
  • tests/bootstrap.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy
swissspidy marked this pull request as ready for review December 4, 2026 21:26
@swissspidy
swissspidy requested a review from a team as a code owner December 4, 2026 21:26
Copilot AI balanced review requested due to automatic review settings December 4, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@swissspidy
swissspidy merged commit e386875 into main Dec 4, 2026
30 checks passed
@swissspidy
swissspidy deleted the claude/elegant-mendel-hm9kcu branch December 4, 2026 22:14
@github-actions github-actions Bot added this to the 0.13.4 milestone Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants