Skip to content

[PHPSpec to PHPUnit] Review Bundle#18047

Merged
GSadee merged 3 commits intoSylius:2.1from
rust-le:OP-571-review-bundle
May 21, 2025
Merged

[PHPSpec to PHPUnit] Review Bundle#18047
GSadee merged 3 commits intoSylius:2.1from
rust-le:OP-571-review-bundle

Conversation

@rust-le
Copy link
Copy Markdown
Contributor

@rust-le rust-le commented May 20, 2025

Q A
Branch? 2.1
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets OP-571
License MIT

Rewrite PHPSpec to PHPUnit tests in Review Bundle

Summary by CodeRabbit

  • Tests
    • Added new PHPUnit test classes for review metadata mapping, review change listener behavior, and average rating updater functionality.
    • Removed legacy PhpSpec test classes and configuration files.
    • Updated PHPUnit configuration with new test directory and schema path.
  • Chores
    • Updated development dependencies and autoload settings in the package configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented May 20, 2025

Walkthrough

This update migrates the Sylius ReviewBundle from PhpSpec-based testing to PHPUnit. It removes all PhpSpec specs and their configuration, adds equivalent PHPUnit test classes for key components, and updates Composer and PHPUnit configuration files to reflect the new test structure. No production code changes are included.

Changes

File(s) Change Summary
src/Sylius/Bundle/ReviewBundle/Tests/Doctrine/ORM/Subscriber/LoadMetadataSubscriberTest.php Added PHPUnit test class for LoadMetadataSubscriber, covering event subscription and ORM association mapping.
src/Sylius/Bundle/ReviewBundle/Tests/EventListener/ReviewChangeListenerTest.php Added PHPUnit test class for ReviewChangeListener, testing rating updates and review removal logic.
src/Sylius/Bundle/ReviewBundle/Tests/Updater/AverageRatingUpdaterTest.php Added PHPUnit test class for AverageRatingUpdater, verifying rating calculation and persistence logic.
src/Sylius/Bundle/ReviewBundle/composer.json Removed phpspec/phpspec from dev dependencies; updated autoload-dev PSR-4 mapping for PHPUnit tests.
src/Sylius/Bundle/ReviewBundle/phpunit.xml.dist Updated PHPUnit config: schema path, suite name, and added new test directory.
src/Sylius/Bundle/ReviewBundle/phpspec.yml Deleted PhpSpec configuration file.
src/Sylius/Bundle/ReviewBundle/spec/... (all files in spec/) Deleted all PhpSpec specification classes for LoadMetadataSubscriber, ReviewChangeListener, and AverageRatingUpdater.

Sequence Diagram(s)

sequenceDiagram
    participant PHPUnit
    participant TestClass
    participant MockedDependency
    participant SUT

    PHPUnit->>TestClass: Run test method
    TestClass->>MockedDependency: Set up expectations/mocks
    TestClass->>SUT: Invoke method under test
    SUT->>MockedDependency: Interact as per logic
    MockedDependency-->>SUT: Return mock responses
    TestClass->>PHPUnit: Assert outcomes
Loading

Poem

In burrows deep, where tests once slept,
The specs have hopped away.
Now PHPUnit, with bounding leap,
Ensures our code will stay
Robust and strong, with bunnies proud—
Our tests are here to play!
🐇✨

✨ 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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 20, 2025

❌ Preview Environment deleted from Bunnyshell

Available commands:

  • 🚀 /bns:deploy to redeploy the environment

@rust-le rust-le force-pushed the OP-571-review-bundle branch from 1ce0187 to b5a7879 Compare May 20, 2025 13:09
@rust-le rust-le changed the title [WIP][PHPSpec to PHPUnit] Review Bundle [PHPSpec to PHPUnit] Review Bundle May 20, 2025
@rust-le rust-le marked this pull request as ready for review May 20, 2025 13:39
@rust-le rust-le requested review from a team as code owners May 20, 2025 13:39
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/Sylius/Bundle/ReviewBundle/Tests/EventListener/ReviewChangeListenerTest.php (1)

29-29: Consider renaming property for better naming consistency

The property $averageRatingUpdater should be renamed to $reviewableRatingUpdater to match the interface type ReviewableRatingUpdaterInterface it implements. This would improve code clarity and make it easier to understand the relationship between the property and the interface.

-    private MockObject $averageRatingUpdater;
+    private MockObject $reviewableRatingUpdater;

Also update references to this property in the rest of the class.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between b749c9b and b5a7879.

📒 Files selected for processing (9)
  • src/Sylius/Bundle/ReviewBundle/Tests/Doctrine/ORM/Subscriber/LoadMetadataSubscriberTest.php (1 hunks)
  • src/Sylius/Bundle/ReviewBundle/Tests/EventListener/ReviewChangeListenerTest.php (1 hunks)
  • src/Sylius/Bundle/ReviewBundle/Tests/Updater/AverageRatingUpdaterTest.php (1 hunks)
  • src/Sylius/Bundle/ReviewBundle/composer.json (1 hunks)
  • src/Sylius/Bundle/ReviewBundle/phpspec.yml (0 hunks)
  • src/Sylius/Bundle/ReviewBundle/phpunit.xml.dist (1 hunks)
  • src/Sylius/Bundle/ReviewBundle/spec/Doctrine/ORM/Subscriber/LoadMetadataSubscriberSpec.php (0 hunks)
  • src/Sylius/Bundle/ReviewBundle/spec/EventListener/ReviewChangeListenerSpec.php (0 hunks)
  • src/Sylius/Bundle/ReviewBundle/spec/Updater/AverageRatingUpdaterSpec.php (0 hunks)
💤 Files with no reviewable changes (4)
  • src/Sylius/Bundle/ReviewBundle/phpspec.yml
  • src/Sylius/Bundle/ReviewBundle/spec/Updater/AverageRatingUpdaterSpec.php
  • src/Sylius/Bundle/ReviewBundle/spec/EventListener/ReviewChangeListenerSpec.php
  • src/Sylius/Bundle/ReviewBundle/spec/Doctrine/ORM/Subscriber/LoadMetadataSubscriberSpec.php
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: WIP
🔇 Additional comments (14)
src/Sylius/Bundle/ReviewBundle/phpunit.xml.dist (3)

4-4: Good schema location update.

Changing the schema location from a fixed URL to a local path is a good practice as it references the locally installed PHPUnit version, providing better stability and avoiding potential network issues.


12-12: Consistent naming convention.

Using lowercase with underscores for the test suite name (sylius_review_bundle_test_suite) follows a more standardized approach and aligns with common Symfony naming practices.


14-14: Good directory structure addition.

Adding the ./Tests/ directory to the test suite configuration is necessary to include the new PHPUnit tests being migrated from PHPSpec, ensuring comprehensive test coverage.

src/Sylius/Bundle/ReviewBundle/composer.json (1)

79-79: Appropriate autoload configuration update.

The updated PSR-4 namespace mapping from Sylius\\Bundle\\ReviewBundle\\spec\\ to Tests\\Sylius\\Bundle\\ReviewBundle\\ correctly reflects the migration from PhpSpec to PHPUnit testing structure. This ensures proper autoloading of the new test classes.

src/Sylius/Bundle/ReviewBundle/Tests/Doctrine/ORM/Subscriber/LoadMetadataSubscriberTest.php (6)

25-68: Well-structured test class setup and interface verification.

The test class setup is comprehensive with proper mocking of dependencies and clear verification that the subscriber implements the expected interface and subscribes to the correct events.


75-159: Thorough testing of review model mapping.

This test method effectively verifies that the LoadMetadataSubscriber correctly maps the many-to-one associations for the review model, including proper join columns and cascade options. The callback approach for verification is a good practice.


161-192: Good edge case coverage for existing associations.

This test properly verifies that no mapping occurs when the associations already exist, preventing potential duplicate mappings and ensuring the subscriber behaves correctly in all scenarios.


194-227: Complete testing of reviewable model mapping.

The test effectively verifies that the one-to-many association for the reviewable model is mapped correctly with appropriate cascade settings and mapped by relationships.


229-255: Proper verification for skipping existing relations.

This test confirms that the subscriber correctly avoids mapping relations when they already exist on the reviewable model, preventing potential duplicate mappings or overrides.


257-294: Good coverage of metadata mismatch scenarios.

The test properly verifies that the subscriber skips mapping when the metadata class name doesn't match the configured review model, ensuring the subscriber only operates on the intended entities.

src/Sylius/Bundle/ReviewBundle/Tests/Updater/AverageRatingUpdaterTest.php (3)

25-53: Clear test class structure and interface verification.

The class is well-organized with proper setup of mock objects and dependencies. The interface implementation test is a good practice to ensure the updater fulfills its contract.


55-69: Effective testing of direct update functionality.

This test method thoroughly verifies that the updater correctly calculates and sets the average rating on the review subject, and persists the changes via the object manager.


71-88: Complete coverage of update from review functionality.

The test effectively verifies that the updater can extract the review subject from a review instance and update its average rating accordingly, ensuring both update pathways work as expected.

src/Sylius/Bundle/ReviewBundle/Tests/EventListener/ReviewChangeListenerTest.php (1)

26-89: Well-structured test implementation with good coverage

This PHPUnit test class is well-designed and effectively verifies the behavior of the ReviewChangeListener. The test covers all the key scenarios:

  1. Handling review deletion and triggering subject rating recalculation
  2. Properly processing pre-remove events by removing the review from its subject
  3. Gracefully handling non-review objects

The test structure follows PHPUnit best practices with proper mocking, expectations, and assertions. Good job on the migration from PhpSpec to PHPUnit.

@GSadee GSadee added DX Issues and PRs aimed at improving Developer eXperience. Maintenance CI configurations, READMEs, releases, etc. labels May 21, 2025
@GSadee GSadee merged commit 1b1132b into Sylius:2.1 May 21, 2025
26 of 27 checks passed
@GSadee
Copy link
Copy Markdown
Member

GSadee commented May 21, 2025

Thank you @rust-le! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DX Issues and PRs aimed at improving Developer eXperience. Maintenance CI configurations, READMEs, releases, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants