testing php applications
Continuous Integration
Continuous integration, commonly shortened to CI, runs repeatable checks on shared infrastructure whenever code changes. It prevents "works on my machine" assumptions and gives reviewers evidence before merge.
Start From A Clean Checkout
Install dependencies from the lock file, prepare test services, run migrations or schema setup, execute checks, and preserve useful failure output. Test supported PHP versions when the project promises a runtime range.
Keep CI Deterministic
Pin action or image versions deliberately, cache only safe reusable artifacts, keep secrets scoped narrowly, and avoid tests that depend on external live services or execution order.
steps:
- run: composer install --no-interaction --prefer-dist
- run: vendor/bin/phpunit
- run: composer audit
Common Mistakes
- Running
composer updatein CI instead of installing the lock file. - Depending on hidden developer-machine state.
- Leaking secrets into logs.
- Ignoring flaky tests until reruns become normal.
What To Practise
- Describe a clean CI run.
- Install locked dependencies.
- Keep CI deterministic and observable.
Practice
Practice: Plan A PHP CI Job
Outline a CI job for a Composer-managed PHP application.
Requirements
- Start from a clean checkout.
- Install from
composer.lock. - Run tests and dependency audit.
- Include services or migrations if integration tests need them.
Show solution
The outline keeps the pipeline small and reproducible.
1. Check out the commit.
2. Configure the supported PHP runtime and required extensions.
3. Run composer install --no-interaction --prefer-dist.
4. Start isolated test services and apply migrations where needed.
5. Run the test suite, static analysis, and composer audit.
6. Preserve logs and reports on failure.
The exact CI syntax depends on the provider, but the clean-checkout workflow is portable.