Fix test datasource configuration and add GitHub Actions CI - #215
Open
breckenedge wants to merge 3 commits into
Open
Fix test datasource configuration and add GitHub Actions CI#215breckenedge wants to merge 3 commits into
breckenedge wants to merge 3 commits into
Conversation
breckenedge
force-pushed
the
test-bootstrap-fix
branch
from
May 14, 2026 02:24
dfaa4a9 to
dec3778
Compare
Register a dedicated 'test' datasource in tests/bootstrap.php that mirrors the default connection but targets a separate '<db>-test' database. The FixtureManager re-aliases 'test' to 'default' on every run, which broke the previous alias-based setup; setting a real config survives that. Point the phpunit testsuite at ./src (where the test files actually live) so all 19 test classes are discovered, and fix five preexisting references to a typo'd fixture name (app.honorarias -> app.honoraria) that were failing fixture loading for those classes. Add a GitHub Actions workflow that boots MariaDB 10.11 as a service, installs PHP 7.4 + Composer deps, creates the test database, and runs the full PHPUnit suite on every push to master and on pull requests.
breckenedge
force-pushed
the
test-bootstrap-fix
branch
from
May 14, 2026 02:31
dec3778 to
a86787d
Compare
Author
|
Note that the updated specs passed on my own fork here: https://github.com/breckenedge/dallas-makerspace-calendar/actions/runs/25838167795/job/75917606374?pr=1 |
breckenedge
marked this pull request as ready for review
May 14, 2026 03:01
mandarl
reviewed
May 14, 2026
Member
There was a problem hiding this comment.
@breckenedge - thanks for doing this!
- Looks good overall. Do you want to add a sections for Tests in ./docs/README.md?
- Q: is there a risk that if a developer is pointing to Production in DATABASE_URL (I would never do this 😂but ...) then the test fixtures might delete data in prod. Ideally we would have multiple guardrails to prevent this but I am thinking of worst case scenarios.
Author
Good call, I'll add a guardrail so that this can only run locally, and update docs/README.md describing the test suite. |
Fixture setup TRUNCATEs every table it manages. If a developer's DATABASE_URL is pointing at prod when they run phpunit, the bootstrap would derive 'dms-calendar-test' from the prod host and FixtureManager would wipe whatever 'dms-calendar-test' schema happens to exist there. Allowlist: localhost, 127.0.0.1, ::1, db (the docker-compose service). CI uses DB_HOST=127.0.0.1, which is covered. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds a Tests section to docs/README.md covering where tests live, how the suite is run under Docker, how the test datasource is derived from the default connection, the hostname allowlist that prevents pointing fixtures at the prod RDS instance, and a pointer to the CI workflow. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Author
|
@mandarl this good to go as is? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five things in this PR:
Fix
tests/bootstrap.phpso the test runner can actually load fixtures. The previous bootstrap aliasedtest → default, but CakePHP'sFixtureManager::_aliasConnections()unconditionally callsalias('test', 'default')(the inverse direction) at line 124, overriding the bootstrap alias. After fixtures initialise, both names resolve to atestconfig that was never set up, so any test that touches a Table fails with:Replaced the alias with a real
testDatasource registration that clones the default connection config and swaps the database name. Fixtures truncate tables, so they get a dedicateddms-calendar-testschema rather than touching dev data.Make the PHPUnit suite actually discoverable. Two small things were preventing the suite from running:
phpunit.xml.distpointed at./tests/TestCase, which is empty — every test file in this repo lives undersrc/. Repointed the testsuite at./srcwith asuffix="Test.php"glob, which picks up all 19 test classes.app.honorarias(the actual fixture class isHonorariaFixture, singular). That caused fixture init to throw and aborted those classes' runs. Renamed them toapp.honorariainCommitteesControllerTest,ContactsControllerTest,EventsControllerTest,HonorariaControllerTest, andEventsTableTest.Add a GitHub Actions workflow (
.github/workflows/test.yml) that spins up MariaDB 10.11 as a service container, installs PHP 7.4 + Composer deps, symlinksconfig/app.phpto the default config (matching what the docker startup does), creates the test database, and runs the full PHPUnit suite on every push tomasterand on every PR.Refuse to run tests against a non-local DB host. Per review feedback: if a developer's
DATABASE_URLis misconfigured to point at the prod RDS instance, the bootstrap would derivedms-calendar-testfrom it andFixtureManagerwould happilyTRUNCATEevery table it manages against the prod host. The bootstrap now exits 1 with a clear error if the resolveddefaulthost isn't on a small allowlist (localhost,127.0.0.1,::1,db— the docker-compose service name). CI usesDB_HOST=127.0.0.1, which is covered. If a future use case legitimately needs another host, the allowlist is one line intests/bootstrap.php.Document the whole thing in
docs/README.md(new## Testssection): where tests live, thedocker compose execcommand to run them, how thetestdatasource is derived fromdefault, the production guardrail, and a pointer to the CI workflow.Setup note for local devs
After this PR, running tests locally requires the test database to exist on the same MariaDB server (CI handles this automatically):
Fixtures auto-create their own tables from each fixture's
$fieldsdefinition, so no schema import is required.What CI runs
The full suite — 100 test methods across all 19 test classes. Today most of them are still master's
markTestIncompleteskeletons, but each class'ssetUp()exercises fixture init against the newtestdatasource, so any future regression in bootstrap/fixture wiring would fail CI immediately. Branches that add real tests on top of this inherit CI without any further setup.