exercises and solutions
Composer/dependency exercises
Useful Commands
composer validate --strict
composer install
composer update vendor/package --with-dependencies
composer audit
composer show --outdated
Exercises should make learners explain the resulting composer.lock diff and run application checks. Do not teach composer update as a production deployment step.
Practice
Review A Dependency Update
Describe the commands and review steps for updating one Composer package safely. Explain why production deployment should use composer install, not an unrestricted update.
Show solution
Run composer validate --strict, update the selected package deliberately, review composer.json and composer.lock, run checks, and use composer audit. Commit the lock-file change.
Deployment should run composer install from the committed lock file so the resolved dependency set is repeatable.
Diagnose A Platform Constraint Failure
A package installs locally but CI rejects it because the required PHP version or extension is unavailable. Describe the Composer commands and files you would inspect before changing constraints.
Show solution
Inspect composer.json, the lock file, CI runtime version, and installed extensions. Run composer check-platform-reqs in the target environment and use composer why-not for the blocked package or PHP constraint.
Do not weaken the declared platform requirement until the application and deployment environments genuinely support the change.