Skip to content

Automated Testing and CI/CD

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:

  1. Testing Your Application with PHPUnit: install PHPUnit, configure it, and write unit, HTTP, and database tests.
  2. CI/CD with GitHub Actions: run the tests on every push, add a deployment stage, and prove that a failing test stops the deployment.

Projects created from the current version of the template already contain:

FilePurpose
phpunit.xmlPHPUnit configuration: where the tests are and which settings they use.
tests/bootstrap.phpCreates the Slim application once, before the tests run.
tests/TestCase.phpBase 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.ymlA GitHub Actions workflow that installs the application, checks the PHP syntax, and runs the tests.

Run the tests from your project’s root folder:

Running the tests with Wampoon
.\composer.bat test

The work happens in this order:

  1. Tests on your computer: composer test passes (testing guide, Steps 1 to 7).
  2. Tests on GitHub: the workflow runs on every push, and the Actions tab shows a green check (CI/CD guide, Steps 1 and 2).
  3. 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).
  4. Proof: a run in which a failing test stops the deployment, captured in screenshots (CI/CD guide, Step 4).

Deliverable 6 sectionWhere the guides help
CI/CD tool selection and justificationCI/CD guide: Key ideas, Step 3 (choice of deployment target), and the report checklist
Pipeline configuration and designCI/CD guide: Steps 1 and 3 (the workflow file), the flowchart example, and the trigger
Automated testing integrationTesting guide (the tests); CI/CD guide, Step 4 (the failed run that stops the deployment)
Demonstration and reflectionCI/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.