Testing Suite Overview
This document outlines the refreshed PHPUnit suite organization introduced in December 2025 and explains how to integrate it into everyday development.
π§± Test Architecture
| Layer | Location | Base class | Description |
|---|---|---|---|
| Core Unit | tests/TestCase/Core/Unit |
BaseTestCase |
Fast-running unit and table/service tests that operate purely on PHP objects or direct ORM calls. |
| Core Feature | tests/TestCase/Core/Feature |
HttpIntegrationTestCase |
HTTP-centric smoke tests that exercise controllers or routes without complex setup. |
| Plugins | tests/TestCase/Plugins |
PluginIntegrationTestCase |
Plugin-focused tests that access plugin tables or services while sharing the same seeded database. |
Support helpers live in tests/TestCase/Support:
SeedManagerβ centralizes loading../dev_seed_clean.sqlto thetestconnection.HttpIntegrationTestCaseβ thin HTTP feature base (extendsBaseTestCase+IntegrationTestTrait).PluginIntegrationTestCaseβ auto-loads the plugin under test before running assertions.
π± Guaranteed Seed Data
All suites load /workspaces/KMP/dev_seed_clean.sql during tests/bootstrap.php. The new SeedManager ensures the SQL file is applied once per run and exposes a reset() helper for heavy data mutation scenarios.
When extending BaseTestCase, call $this->reseedDatabase() if your test needs a full reset after destructive operations.
π Running Tests
| Command | Purpose |
|---|---|
vendor/bin/phpunit --testsuite core-unit |
Run fast unit/service coverage. |
vendor/bin/phpunit --testsuite core-feature |
Execute HTTP smoke tests. |
vendor/bin/phpunit --testsuite plugins |
Run cross-plugin coverage (includes tests/TestCase/Plugins and plugin-owned suites). |
vendor/bin/phpunit tests/TestCase/Core/Feature/Members/MembersLoginPageTest.php |
Target a single file. |
vendor/bin/phpunit --filter MembersTableSeedTest |
Target a single class/method. |
π‘ Need the old βeverythingβ run? Use
vendor/bin/phpunit --testsuite all.
π§ͺ Starter Tests
Core/Unit/Model/MembersTableSeedTestβ verifies the super-user seed and duplicate email guardrails.Core/Feature/Members/MembersLoginPageTestβ confirms anonymous access to/members/loginremains healthy.Plugins/Awards/Feature/RecommendationsSeedTestβ proves Awards plugin tables are reachable using the shared seed.
These examples demonstrate how to:
- Depend on canonical seed accounts defined in
/README.md. - Share HTTP helpers and plugin loaders.
- Keep new tests isolated with automatic transactions from
BaseTestCase.
π Extending the Suite
- Pick a layer (unit vs feature vs plugin) and drop the file in the matching folder.
- Extend the correct base (
BaseTestCase,HttpIntegrationTestCase, orPluginIntegrationTestCase). - Leverage the seed using constants like
BaseTestCase::ADMIN_MEMBER_IDor$this->reseedDatabase(). - Name tests clearly β the suite naming convention enables
--testsuitefiltering.
π Legacy Tests
Existing suites under tests/TestCase/Controller, Model, Services, etc., remain runnable and are included in core-unit, core-feature, or all. Migrate legacy coverage into the new layout over time for the cleanest experience.
Happy testing! π§ͺ