Automated Testing and CI/CD
What This Section Covers
Section titled “What This Section Covers”A CI/CD pipeline runs your automated tests on a GitHub server every time you push code, and only prepares a deployment when every test passes. This section explains what the slim-mvc starter template ↗ provides for this, and guides you step by step:
- Testing Your Application with PHPUnit: install PHPUnit, configure it, and write unit, HTTP, and database tests.
- CI/CD with GitHub Actions: run the tests on every push, add a deployment stage, and prove that a failing test stops the deployment.
What the Template Provides
Section titled “What the Template Provides”Projects created from the current version of the template already contain:
| File | Purpose |
|---|---|
phpunit.xml | PHPUnit configuration: where the tests are and which settings they use. |
tests/bootstrap.php | Creates the Slim application once, before the tests run. |
tests/TestCase.php | Base class for HTTP tests, with get() and request() methods that send requests to your application. |
tests/Unit/ | Example unit tests (the Result class and the hs() helper). |
tests/Http/ | Example HTTP tests (the home page, a 404 page, an error route). |
.github/workflows/ci.yml | A GitHub Actions workflow that installs the application, checks the PHP syntax, and runs the tests. |
Run the tests from your project’s root folder:
.\composer.bat testFrom Your Computer to the Pipeline
Section titled “From Your Computer to the Pipeline”The work happens in this order:
- Tests on your computer:
composer testpasses (testing guide, Steps 1 to 7). - Tests on GitHub: the workflow runs on every push, and the Actions tab shows a green check (CI/CD guide, Steps 1 and 2).
- Deployment stage: a second job, which only runs when the tests pass, packages the application or builds a Docker image (CI/CD guide, Step 3).
- Proof: a run in which a failing test stops the deployment, captured in screenshots (CI/CD guide, Step 4).
The Pipeline and Deliverable 6
Section titled “The Pipeline and Deliverable 6”| Deliverable 6 section | Where the guides help |
|---|---|
| CI/CD tool selection and justification | CI/CD guide: Key ideas, Step 3 (choice of deployment target), and the report checklist |
| Pipeline configuration and design | CI/CD guide: Steps 1 and 3 (the workflow file), the flowchart example, and the trigger |
| Automated testing integration | Testing guide (the tests); CI/CD guide, Step 4 (the failed run that stops the deployment) |
| Demonstration and reflection | CI/CD guide: the report checklist and reflection questions |
The template’s workflow covers building and testing only. The deployment stage, the comments that explain each step, and the tests for your own features are your team’s work.