DaemonBundle icon indicating copy to clipboard operation
DaemonBundle copied to clipboard

feat: implement ConsoleCommandListener

Open pforesi opened this issue 2 months ago • 1 comments

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 ConsoleCommandListener class that listens for ConsoleSignalEvent and triggers shutdown on DaemonCommand instances when receiving SIGTERM or SIGINT, using Symfony's event system and PHP 8 attributes. (src/EventListener/ConsoleCommandListener.php)
  • Removed the direct handleSignal method and related signal handler registration from DaemonCommand, 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 DaemonCommandConcrete to include an isShutdownRequested() 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)

pforesi avatar Nov 28 '25 15:11 pforesi

Just squashed my commits

pforesi avatar Dec 11 '25 17:12 pforesi

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 avatar Jan 14 '26 11:01 pforesi

@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)

Oliboy50 avatar Jan 14 '26 15:01 Oliboy50