Skip to content

feature/enhance-event-listener#80

Merged
RamyHakam merged 4 commits intomasterfrom
feature/enhance-event-listener
Feb 15, 2026
Merged

feature/enhance-event-listener#80
RamyHakam merged 4 commits intomasterfrom
feature/enhance-event-listener

Conversation

@RamyHakam
Copy link
Owner

This pull request refactors the DbSwitchEventListener to improve its design, simplify dependency injection, and enhance testing. The most important changes include replacing the use of ContainerInterface with ManagerRegistry, updating event handling logic, and modernizing the class implementation and its tests.

Refactoring and Dependency Injection:

  • Replaced the dependency on ContainerInterface with ManagerRegistry in DbSwitchEventListener, allowing direct access to Doctrine connections and improving type safety and clarity. (src/EventListener/DbSwitchEventListener.php)
  • Updated the constructor and all usages to inject ManagerRegistry directly, removing unnecessary container access. (src/EventListener/DbSwitchEventListener.php, tests/Unit/EventListener/DbSwitchEventListenerTest.php) [1] [2]

Event Handling Improvements:

  • Renamed the event handler method from onHakamMultiTenancyBundleEventSwitchDbEvent to onSwitchDb and updated the event subscription mapping for clarity and consistency. (src/EventListener/DbSwitchEventListener.php, tests/Unit/EventListener/DbSwitchEventListenerTest.php) [1] [2]
  • Improved tenant switching logic by tracking only the current tenant identifier and database name, and skipping redundant switches if the tenant hasn't changed. (src/EventListener/DbSwitchEventListener.php)

Testing Updates:

  • Refactored unit tests to use ManagerRegistry mocks instead of container mocks, simplifying test setup and expectations. (tests/Unit/EventListener/DbSwitchEventListenerTest.php) [1] [2] [3] [4] [5]
  • Updated test method names and event dispatches to match the new handler and event subscription. (tests/Unit/EventListener/DbSwitchEventListenerTest.php) [1] [2] [3] [4]

Code Modernization:

  • Converted DbSwitchEventListener to a final class and implemented ResetInterface for better lifecycle management and compatibility with Symfony's service reset mechanism. (src/EventListener/DbSwitchEventListener.php)
  • Extracted connection parameter building into a dedicated method for improved readability and maintainability. (src/EventListener/DbSwitchEventListener.php)

@RamyHakam RamyHakam self-assigned this Feb 14, 2026
@RamyHakam RamyHakam added the enhancement New feature or request label Feb 14, 2026
@RamyHakam RamyHakam merged commit c3182f6 into master Feb 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant