Skip to content

Bumps phpunit to ^12#60

Merged
MekDrop merged 1 commit intoimponeer:mainfrom
MekDrop:bump-phpunit-to-12
Jul 8, 2025
Merged

Bumps phpunit to ^12#60
MekDrop merged 1 commit intoimponeer:mainfrom
MekDrop:bump-phpunit-to-12

Conversation

@MekDrop
Copy link
Copy Markdown
Member

@MekDrop MekDrop commented Jul 8, 2025

Resolves #57

Summary by CodeRabbit

  • Chores

    • Updated development dependencies to require PHPUnit ^12.0 and removed Mockery.
    • Simplified test script command for running tests.
  • Tests

    • Modernized test classes to use PHP 8 attribute syntax for data providers and named arguments for assertions.
    • Refactored tests to remove Mockery dependency, using anonymous classes instead.
    • Streamlined PHPUnit assertions and improved configuration for stricter test enforcement and output formatting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 8, 2025

Walkthrough

The changes update the project's testing setup to support PHPUnit 12. This includes modifying development dependencies in composer.json, enhancing the PHPUnit configuration in phpunit.xml.dist, and refactoring test files to use modern PHPUnit and PHP syntax, removing Mockery and legacy annotations.

Changes

Files/Group Change Summary
composer.json Updated PHPUnit to ^12.0, removed older PHPUnit and Mockery dependencies, simplified test script.
phpunit.xml.dist Added namespace/schema, new attributes, enabled testdox, removed code coverage filter/whitelist.
tests/ErrorsCollectionTest.php Replaced docblock data providers with attributes, made providers static, used named assertion args.
tests/ErrorsTraitTest.php Removed Mockery usage, used anonymous class for trait, simplified assertions and method names.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Composer
    participant PHPUnit
    participant TestSuite

    Developer->>Composer: Run composer install/update
    Composer->>PHPUnit: Install PHPUnit ^12.0
    Developer->>PHPUnit: Run tests (via script)
    PHPUnit->>TestSuite: Execute tests with new config and syntax
    TestSuite-->>PHPUnit: Return results (testdox format enabled)
    PHPUnit-->>Developer: Display test results
Loading

Assessment against linked issues

Objective Addressed Explanation
Update PHPUnit to ^12 in composer.json (#57)
Update test code and config for PHPUnit 12 (#57)

Possibly related issues

Poem

In the warren where tests do run,
PHPunit twelve now leads the fun!
Old mocks and scripts have hopped away,
New syntax shines with each array.
With config neat and code so bright,
Our tests leap forward—what a sight!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4aa06d9 and f770e84.

📒 Files selected for processing (4)
  • composer.json (2 hunks)
  • phpunit.xml.dist (1 hunks)
  • tests/ErrorsCollectionTest.php (8 hunks)
  • tests/ErrorsTraitTest.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/ErrorsTraitTest.php (1)
src/ErrorsTrait.php (4)
  • getErrors (32-35)
  • getHtmlErrors (50-53)
  • hasError (58-61)
  • setErrors (42-45)
tests/ErrorsCollectionTest.php (1)
src/ErrorsCollection.php (10)
  • ErrorsCollection (14-201)
  • add (125-150)
  • offsetGet (50-53)
  • offsetSet (61-64)
  • isEmpty (83-86)
  • clear (91-94)
  • getHtml (101-106)
  • count (155-158)
  • toArray (186-189)
  • toJson (196-199)
🔇 Additional comments (13)
composer.json (2)

11-11: LGTM! PHPUnit dependency upgrade is clean and appropriate.

The consolidation to PHPUnit ^12.0 simplifies dependency management and aligns with the PR objective. The removal of legacy versions and Mockery (as mentioned in the AI summary) modernizes the testing setup.


35-35: Good simplification of the test script.

Removing the --testdox flag from the test script makes sense since this is now configured in phpunit.xml.dist (line 10). This provides better separation of concerns between script definition and test execution configuration.

phpunit.xml.dist (1)

2-11: Excellent PHPUnit 12 configuration modernization.

The configuration enhancements provide several benefits:

  • Schema validation: Proper XML namespace and schema location for IDE support
  • Execution control: executionOrder="depends,defects" optimizes test run order
  • Stricter failure conditions: failOnRisky="true" and failOnWarning="true" improve test quality
  • Performance: cacheDirectory=".phpunit.cache" enables result caching
  • Output formatting: testdox="true" provides readable test output

These changes fully leverage PHPUnit 12's capabilities and improve the overall testing experience.

tests/ErrorsTraitTest.php (4)

11-16: Excellent refactoring to remove Mockery dependency.

The anonymous class approach is much cleaner than the previous Mockery partial mock setup. This directly instantiates a class that uses the ErrorsTrait, providing a more straightforward way to test trait functionality without external dependencies.


22-23: Good simplification of assertions.

The removal of conditional checks for assertIsString and assertIsArray is appropriate since PHPUnit 12 includes these methods natively. The streamlined assertions improve readability while maintaining the same test coverage.


30-30: Consistent assertion modernization.

The direct use of assertIsString without conditional checks aligns with the PHPUnit 12 upgrade and improves code consistency.


37-42: Test logic remains robust with cleaner assertions.

The hasError() test logic is preserved while benefiting from simplified assertions. The test correctly verifies the boolean return type and the state changes after adding errors.

tests/ErrorsCollectionTest.php (6)

10-10: Good addition of PHPUnit attributes import.

The import of DataProvider attribute enables the modern syntax used throughout the test class, replacing traditional docblock annotations.


26-26: Excellent modernization to PHP 8 attributes.

The #[DataProvider('provideConstructorParams')] attribute syntax is more explicit and type-safe than the traditional @dataProvider docblock annotation. This change aligns with modern PHP and PHPUnit practices.


22-22: Named arguments improve assertion readability.

Using message: as a named argument makes the assertion intent clearer and is more maintainable than positional arguments.


147-147: Required static modifier for attribute-based data providers.

Making the data provider method static is necessary when using PHP 8 attributes with PHPUnit. This change ensures compatibility with the new attribute syntax.


176-176: Consistent use of modern attribute syntax.

The #[DataProvider('provideTestAddData')] attribute maintains consistency with the other data provider usage in the class.


204-204: Proper static method declaration for attribute compatibility.

The provideConstructorParams method is correctly declared as static to work with the PHP 8 attribute syntax, maintaining the same functionality while adopting modern practices.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MekDrop MekDrop merged commit a4a1f95 into imponeer:main Jul 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Bump phpunit to ^12

1 participant