Skip to content

Analyse tests with PHPStan - #137

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 the tests/ folder in addition to src/ and dist-archive-command.php.

Changes

  • phpstan.neon.dist: add tests to paths, and add vendor/wp-cli/wp-cli-tests/tests/includes/TestCase.php to scanFiles, since WP_CLI\Tests\TestCase is loaded by the wp-cli-tests bootstrap rather than autoloaded.
  • tests/Distignore_Filter_Iterator_Test.php:
    • Fixed 5 method.nonObject errors: the items yielded by RecursiveIteratorIterator are mixed, so the test now checks them with assertInstanceOf( SplFileInfo::class, $item ) before calling getPathname().
    • The class already extended WP_CLI\Tests\TestCase. Its setUp(): void/tearDown(): void overrides are now the Yoast polyfill set_up()/tear_down() fixtures, calling the matching parent methods.

No ignores, baseline entries or level changes were added.

Testing

  • composer phpstan: no errors
  • composer phpunit: 10 tests pass. The one PHPUnit deprecation (deprecated XML config schema) was already there before this change.
  • composer phpcs: clean

Generated by Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded iterator checks to verify that returned items are file entries.
    • Updated test setup and cleanup to align with the test framework’s lifecycle conventions.
  • Chores
    • Extended static analysis coverage to include tests and an additional test support file.

Add the tests/ folder to PHPStan's paths and scan the wp-cli-tests
TestCase so PHPStan knows the base class and its polyfilled assertions.

Fix the errors this reports: narrow the items yielded by
RecursiveIteratorIterator to SplFileInfo with assertInstanceOf()
before calling getPathname().

Also switch the setUp()/tearDown() overrides to the Yoast polyfill
set_up()/tear_down() fixtures provided by WP_CLI\Tests\TestCase.

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 includes the test directory in its analysis paths and scans WP-CLI’s test case. The iterator test fixture updates its lifecycle methods and adds assertions that yielded items are SplFileInfo instances.

Changes: Test Analysis and Iterator Assertions

Layer / File(s) Summary
Configure test analysis and update iterator tests
phpstan.neon.dist, tests/Distignore_Filter_Iterator_Test.php
PHPStan includes tests in its paths and scans WP-CLI’s TestCase.php. The fixture uses set_up() and tear_down(), and five tests assert that each yielded item is an SplFileInfo.

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

Change: Other

Suggested reviewers: brianhenryie

Merge Risk: Minimal · up to 026dc

This change only updates static-analysis configuration and the iterator tests, and it does not affect production behavior. The PHP 8.6 Behat failures come from the CI environment, not from these edits. The merge risk is minimal.

Security architecture risk: Minimal · up to 026dc

The changes are limited to static analysis and tests. They do not change how the WP-CLI dist-archive command runs or filters files.

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 "Analyse tests with PHPStan" matches the main change. The PR adds tests/ to PHPStan's analysis paths, scans the wp-cli-tests TestCase.php for base-class recognition, and fixes test code so P…
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 "Analyse tests with PHPStan" matches the main change. The PR adds tests/ to PHPStan's analysis paths, scans the wp-cli-tests TestCase.php for base-class recognition, and fixes test code so PHPStan reports no errors in the test suite. The title is short, specific, and states the primary intent. It does not mention the lifecycle method renames or the SplFileInfo assertions, which is acceptable because the title need not cover every detail.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • 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: 803eacba-5f9e-4226-8e8a-dd6fe8dfc3a5
Commits

Reviewing files that changed from the base of the PR and between f677997 and 026dc13.

Files selected for processing: 2

  • phpstan.neon.dist
  • tests/Distignore_Filter_Iterator_Test.php

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

@github-actions github-actions Bot added automated-pr command:dist-archive Related to 'dist-archive' command enhancement scope:testing Related to testing labels Dec 4, 2026
@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!

Copy link
Copy Markdown
Member Author

The failing Behat jobs are all on PHP 8.6, and they fail on the environment rather than on anything this PR changes. It only touches phpstan.neon.dist and the PHPUnit test in tests/.

  • Every failing step is wp dist-archive ... --format=targz exiting with tar: <dir>: Cannot stat: No such file or directory.
  • Behat passes on PHP 7.4 to 8.5 in the same run, and the source and feature files are unchanged.
  • The PHP 8.6 Behat jobs in Run PHPStan on tests folder and fix reported errors i18n-command#523 fail at the same time for a different environment reason: The mbstring extension is required. That points at the PHP 8.6 test environment.

The last run on main skipped Behat, so I can't compare with it directly. I'll rerun the failed jobs once after the workflow finishes.


Generated by Claude Code

@swissspidy
swissspidy marked this pull request as ready for review December 4, 2026 21:27
@swissspidy
swissspidy requested a review from a team as a code owner December 4, 2026 21:27
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 bc102c4 into main Dec 4, 2026
120 of 134 checks passed
@swissspidy
swissspidy deleted the claude/elegant-mendel-hm9kcu branch December 4, 2026 22:12
@github-actions github-actions Bot added this to the 3.2.4 milestone Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-pr command:dist-archive Related to 'dist-archive' command enhancement scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants