This also requires you to have docker.mk installed.
php_tests_phpunit: DKR_COMPOSE_FILE = -f ./docker-compose.yaml -f ./docker-compose.phpunit.yaml
php_tests_behat: DKR_COMPOSE_FILE = -f ./docker-compose.yaml -f ./docker-compose.behat.yamlmake php_composer_installPACKAGE=psr/log make php_composer_installmake php_composer_updatePACKAGE=psr/log make php_composer_updatemake php_tests_phpunitmake php_tests_behatRun the suite against a git worktree's code while reusing the already-running local stack (image, compose files, secrets, services), with a per-worktree database so parallel worktree runs never collide with each other or the main checkout.
This needs no changes in the consuming repo. Bring the main stack up as usual and run this from the MAIN checkout, pointing at a worktree — decrypted env/secret files (which are gitignored and absent in a worktree) are still sourced from the main stack:
make dkr_up_local # once: the stack it reuses must be up
make php_tests_worktree WORKTREE=/path/to/worktreePick a suite, or run an arbitrary command, with TESTS / COMMAND:
make php_tests_worktree WORKTREE=/path/to/worktree TESTS=behat
make php_tests_worktree WORKTREE=/path/to/worktree COMMAND="php artisan test"How it works:
- stack reuse — it finds the running
clicontainer for the compose project and reuses the exact compose files, image and services that created it (so it never rebuilds a stale image, and secrets come from the main stack'senv_file). Bring the stack up first. - source — only the code bind-mount is redirected to the worktree, via an auto-generated
ephemeral compose override — your compose files are not edited. The app directory
(the one holding
composer.json) is auto-detected from the running mount; override withAPP_DIR=<path relative to the repo root>if detection can't find it. - database isolation — the run gets a unique, sanitised
DB_DATABASEderived from the worktree path (override withDB_DATABASE=...), reusing the shared MySQL server. The database is created, granted to the app user, and migrated before the suite runs. AddDB_SEED=1for suites whose feature tests need seeded reference data, orDB_FRESH=1to drop and rebuild it for a clean slate. - composer drift — if the worktree's
composer.lockdiffers from the main checkout's (or itsvendor/is missing) dependencies are installed into the worktree first; otherwise the worktree'svendor/is reused, so re-runs are fast.