Implement container reaper and shutdown hook functionality.#19
Merged
gustavofreze merged 1 commit intomainfrom Apr 14, 2026
Merged
Implement container reaper and shutdown hook functionality.#19gustavofreze merged 1 commit intomainfrom
gustavofreze merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces infrastructure to improve container lifecycle management (shutdown hooks + a reaper container) and updates tests/tooling to support persistent containers across processes (e.g., mutation testing).
Changes:
- Added
ShutdownHookto make shutdown registration injectable/testable and wired it through container startup. - Added
ContainerReaper+DockerReapercommand and changedrunIfNotExists()to return a “shared” wrapper (Reused) that no-opsremove()/stopOnShutdown(). - Added Infection mutation-testing configuration and extended unit tests to validate new behaviors and command composition.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/MySQLDockerContainerTest.php | Adds assertions for generated docker commands, JDBC URL port behavior, granted-host/database setup behavior, and shutdown-hook delegation. |
| tests/Unit/Mocks/TestableMySQLDockerContainer.php | Allows injecting a ShutdownHook into test container construction. |
| tests/Unit/Mocks/TestableGenericDockerContainer.php | Wires ContainerReaper + ShutdownHook into test container construction. |
| tests/Unit/Mocks/ClientMock.php | Adds mock support for DockerPull. |
| tests/Unit/Internal/Containers/ShutdownHookTest.php | Unit test for ShutdownHook via namespaced override of register_shutdown_function. |
| tests/Unit/Internal/Containers/Overrides/register_shutdown_function_spy.php | Spy override to capture registered shutdown callbacks. |
| tests/Unit/Internal/Containers/Overrides/file_exists_outside_docker.php | Override to force “outside Docker” branch for deterministic tests. |
| tests/Unit/Internal/Containers/ContainerReaperTest.php | Adds a test covering the “outside Docker” early-return behavior. |
| tests/Unit/GenericDockerContainerTest.php | Updates shutdown-hook test and adds new Reused/reaper-related tests and pull assertions. |
| tests/Unit/FlywayDockerContainerTest.php | Updates names, adds a wall-clock wait assertion, and checks readiness/pull command execution. |
| src/Waits/ContainerWaitForDependency.php | Refactors polling loop logic for readiness/timeout checks. |
| src/Internal/Containers/Started.php | Injects ShutdownHook and routes stopOnShutdown() through it. |
| src/Internal/Containers/ShutdownHook.php | New wrapper around register_shutdown_function(). |
| src/Internal/Containers/Reused.php | New shared-wrapper implementation that no-ops removal/shutdown stop. |
| src/Internal/Containers/ContainerReaper.php | New reaper orchestration that starts a per-container reaper when in Docker. |
| src/Internal/Containers/ContainerLookup.php | Passes ShutdownHook into Started instances. |
| src/Internal/Commands/DockerReaper.php | New docker command to start the reaper sidecar container. |
| src/Internal/Commands/DockerList.php | Tightens container-name filtering to an anchored regex. |
| src/Internal/CommandHandler/ContainerCommandHandler.php | Requires a ShutdownHook and threads it into lookups. |
| src/GenericDockerContainer.php | Adds ContainerReaper, makes pullImage() synchronous, and wraps runIfNotExists() results in Reused. |
| src/FlywayDockerContainer.php | Reorders withValidateMigrationNaming() (functional no-op change). |
| src/DockerContainer.php | Documents new “shared” semantics for runIfNotExists(). |
| infection.json.dist | Adds Infection configuration. |
| composer.json | Adds Infection dependency and scripts, plus plugin allowlist. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.