Skip to content

Refactor the tests and make them pass PHPStan - #966

Merged
giuscris merged 7 commits into
2.xfrom
tests/refactor
Oct 19, 2026
Merged

giuscris merged 7 commits into
2.xfrom
tests/refactor

Conversation

@giuscris

Copy link
Copy Markdown
Member

This pull request introduces several improvements to the test infrastructure and static analysis configuration, focusing on better management of temporary directories during tests, enhanced exception handling in test assertions, and improved static analysis for PHPUnit integration. The changes also refine how test fixtures are excluded from code analysis tools, ensuring more accurate and maintainable test and code quality processes.

Test Infrastructure Improvements:

  • Refactored test classes (TestCase and various unit tests) to use the UsesTempDirectory attribute for automatic setup and teardown of temporary directories, replacing manual directory management methods. This ensures consistent and reliable cleanup of test artifacts. [1] [2] [3] [4] [5] [6]
  • Added utility methods to TestCase, such as unchecked() for passing deliberately invalid arguments and captureException() for concise exception assertion and retrieval in tests.
  • Updated test cases to use captureException() for clearer and more robust exception testing, replacing manual try/catch blocks. [1] [2] [3] [4] [5] [6] [7]

Static Analysis and Code Quality:

  • Added phpstan/phpstan-phpunit to composer.json and enabled its extension in phpstan.neon, improving static analysis for PHPUnit-specific code. [1] [2]
  • Improved phpstan.neon by refining ignored error patterns and adjusting excluded paths to focus on fixtures rather than entire test directories.
  • Adjusted .php-cs-fixer.php and .rector.php configuration files to more accurately exclude only test fixtures from code formatting and refactoring tools, rather than all tests. [1] [2]

Type and Signature Improvements:

  • Added an explicit mixed return type to callMethod() in Methods.php for improved type safety and clarity.

Minor Enhancements:

  • Added missing docblocks and minor code cleanups, such as improved variable naming and stricter type casting in test assets. [1] [2]

These changes collectively enhance test reliability, code quality, and maintainability, especially in how temporary resources and exceptions are managed during testing.

claude and others added 7 commits October 18, 2026 16:36
…ch blocks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PaCuQk8vH2QvAo5vXUe7t7
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add precise PHPDoc types to the test helpers and fixtures, narrow nullable
values and DOM query results, and pass deliberately invalid arguments through
`TestCase::unchecked()` instead of suppressing the errors.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@giuscris giuscris self-assigned this Oct 18, 2026
@giuscris
giuscris merged commit 085747f into 2.x Oct 19, 2026
1 check passed
@giuscris
giuscris deleted the tests/refactor branch October 19, 2026 21:08
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.

2 participants