[PHPSpec to PHPUnit] Review Bundle#18047
Conversation
WalkthroughThis 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
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
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
❌ Preview Environment deleted from BunnyshellAvailable commands:
|
1ce0187 to
b5a7879
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Sylius/Bundle/ReviewBundle/Tests/EventListener/ReviewChangeListenerTest.php (1)
29-29: Consider renaming property for better naming consistencyThe property
$averageRatingUpdatershould be renamed to$reviewableRatingUpdaterto match the interface typeReviewableRatingUpdaterInterfaceit 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
📒 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\\toTests\\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
LoadMetadataSubscribercorrectly 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 coverageThis PHPUnit test class is well-designed and effectively verifies the behavior of the
ReviewChangeListener. The test covers all the key scenarios:
- Handling review deletion and triggering subject rating recalculation
- Properly processing pre-remove events by removing the review from its subject
- 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.
|
Thank you @rust-le! 🎉 |
Rewrite PHPSpec to PHPUnit tests in Review Bundle
Summary by CodeRabbit