Add cross-driver testsuite for MySQL and Postgres#119
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #119 +/- ##
=========================================
Coverage 99.71% 99.72%
- Complexity 145 149 +4
=========================================
Files 3 3
Lines 353 362 +9
=========================================
+ Hits 352 361 +9
Misses 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the test harness so the existing DB/Mapper integration tests can run against multiple PDO backends (SQLite/MySQL/Postgres) selected via environment variables, and it adjusts Mapper::checkNewIdentity() to avoid Postgres transaction aborts when lastInsertId() is undefined.
Changes:
- Introduce a shared
DatabaseTestCase+ConnectionFactoryto run tests across SQLite/MySQL/Postgres (defaulting to in-memory SQLite). - Add driver-aware DDL helpers (
Schema::pkAuto(),Schema::dateTime()) and fix raw SQL portability issues in tests. - Wrap Postgres
lastInsertId()inside a savepoint to contain transaction aborts, with targeted tests for the behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/MapperTest.php |
Migrates to shared DB test case, uses driver-aware schema, adds savepoint behavior tests, and fixes SQL portability issues. |
tests/DbTest.php |
Migrates to shared DB test case and makes one SQLite-specific assertion explicitly skipped on other drivers. |
tests/Database/Schema.php |
Adds driver-specific DDL fragments for auto PK and datetime types. |
tests/Database/DriverUnavailable.php |
Adds a typed exception for missing PDO drivers to cleanly skip tests. |
tests/Database/DatabaseTestCase.php |
Adds shared connection setup, table reset helper, and Postgres sequence resync helper. |
tests/Database/ConnectionFactory.php |
Adds env-driven PDO connection creation with default DSNs for local docker ports. |
src/Mapper.php |
Adds savepoint wrapping around Postgres lastInsertId() to prevent transaction abort from discarding inserts. |
phpunit.xml.dist |
Splits tests into unit vs database testsuites by explicit file list. |
docker-compose.yml |
Adds local MySQL/Postgres services on non-default host ports with healthchecks. |
composer.json |
Adds convenience scripts to run PHPUnit against sqlite/mysql/pgsql (and all in sequence). |
CONTRIBUTING.md |
Documents how to run the multi-driver tests locally with docker compose and composer scripts. |
.github/workflows/ci.yml |
Fans CI tests out into separate sqlite/mysql/pgsql jobs using GitHub Actions services. |
.env.example |
Documents supported DB environment variables for the integration tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactor DbTest and MapperTest onto a shared DatabaseTestCase so the existing tests run against SQLite, MySQL, and Postgres. The driver, DSN, and credentials are selected from environment variables; default to in-memory SQLite to preserve the current zero-config experience. A docker-compose.yml provides MySQL and Postgres locally on non-default ports, and CI fans out into a three-driver matrix using GitHub Actions services. Fix Mapper::checkNewIdentity to wrap lastInsertId() in a savepoint on Postgres. After an INSERT with an explicit id, Postgres errors with "lastval is not yet defined in this session" and marks the surrounding transaction as aborted; the catch swallowed the exception but the subsequent commit then discarded the row. The savepoint contains the abort. MySQL is excluded because issuing SAVEPOINT between the INSERT and LAST_INSERT_ID() resets the latter to 0. Also fix four raw-SQL portability bugs in MapperTest that SQLite and MySQL had hidden: double-quoted string literals (Postgres reads them as identifiers) and a VARCHAR/integer comparison.
Refactor DbTest and MapperTest onto a shared DatabaseTestCase so the existing tests run against SQLite, MySQL, and Postgres. The driver, DSN, and credentials are selected from environment variables; default to in-memory SQLite to preserve the current zero-config experience. A docker-compose.yml provides MySQL and Postgres locally on non-default ports, and CI fans out into a three-driver matrix using GitHub Actions services.
Fix Mapper::checkNewIdentity to wrap lastInsertId() in a savepoint on Postgres. After an INSERT with an explicit id, Postgres errors with "lastval is not yet defined in this session" and marks the surrounding transaction as aborted; the catch swallowed the exception but the subsequent commit then discarded the row. The savepoint contains the abort. MySQL is excluded because issuing SAVEPOINT between the INSERT and LAST_INSERT_ID() resets the latter to 0.
Also fix four raw-SQL portability bugs in MapperTest that SQLite and MySQL had hidden: double-quoted string literals (Postgres reads them as identifiers) and a VARCHAR/integer comparison.