feat: implement ConsoleCommandListener
This pull request refactors the handling of OS signals for daemon commands by introducing a dedicated ConsoleCommandListener that responds to Symfony's ConsoleSignalEvent. The signal handling logic is moved out of DaemonCommand, and comprehensive unit and integration tests are added to ensure correct behavior. The documentation is also updated to describe the new testing strategy and best practices.
Event-driven signal handling and listener introduction:
- Added a new
ConsoleCommandListenerclass that listens forConsoleSignalEventand triggers shutdown onDaemonCommandinstances when receiving SIGTERM or SIGINT, using Symfony's event system and PHP 8 attributes. (src/EventListener/ConsoleCommandListener.php) - Removed the direct
handleSignalmethod and related signal handler registration fromDaemonCommand, making signal handling fully event-driven. (src/Command/DaemonCommand.php) [1] [2]
Testing improvements:
- Added comprehensive unit tests for the new listener, covering all signal and command-type combinations, attribute configuration, and edge cases. (
tests/Unit/EventListener/ConsoleCommandListenerTest.php) - Added integration tests to verify the listener's behavior within Symfony's event system, including handling multiple listeners and signals. (
tests/Integration/EventListener/ConsoleCommandListenerIntegrationTest.php) - Updated the test fixture
DaemonCommandConcreteto include anisShutdownRequested()helper for easier assertions in tests. (tests/Fixtures/Command/DaemonCommandConcrete.php) - Removed obsolete signal handling tests from the old
DaemonCommandTest. (tests/Unit/Command/DaemonCommandTest.php)
Documentation updates:
- Added a detailed markdown document describing the new listener's tests, structure, best practices, and coverage statistics. (
docs/CONSOLE_COMMAND_LISTENER_TESTS.md)
Just squashed my commits
UP, please may the 2nd reviewer review, accept or reject. Our team need it, elsewhere we will go on forked solution. Thanks in advance :)
@pforesi thank you for your time and efforts here
this has been released in v9.0.0 (this was considered as a breaking change since we're dropping a public function from this bundle)