Skip to content

Bring Mago back to green against phpdb 0.6.x - #16

Open
simon-mundy wants to merge 4 commits into
php-db:0.1.xfrom
simon-mundy:qa/mago-green
Open

simon-mundy wants to merge 4 commits into
php-db:0.1.xfrom
simon-mundy:qa/mago-green

Conversation

@simon-mundy

@simon-mundy simon-mundy commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Mago fails on this branch against current phpdb 0.6.x. This makes it pass again, and also gets the driver ready for php-db/phpdb#255. It is the first of the driver cleanup PRs; the analyzer and lint baselines are reduced in follow-ups.

Changes

  • Pdo\Driver::createResult(): the last generated value now comes from the driver's own getLastGeneratedValue(), which passes the call to the connection. Before, it was called on the raw resource type.
  • Driver::createStatement(): the connection resource is narrowed to PgSql\Connection. A RuntimeException is thrown when there is none, instead of passing null on to Statement::initialize().
  • Connection: it no longer redeclares $resource. The PgSql\Connection narrowing moves into getResource(), and the pg_* calls go through it. This keeps the class working once Mago compliance: settle the API decisions behind remaining src analyzer issues phpdb#255 types the parent property as mixed; with that PR merged, an untyped redeclaration would be a fatal error.
  • Metadata\Source: documents the row shapes of the column, schema and table queries, and keys the constraint and trigger caches by string names.
  • Formatting: the two container factories are reformatted.

Bugs found while adding tests

  • Trigger metadata: Metadata\Source::loadTriggerData() selected condition_timing, condition_reference_old_table and condition_reference_new_table. PostgreSQL renamed these to action_* in 9.1, so getTriggers() and getTrigger() failed with an SQL error on every supported server. The action_* columns are now selected directly.
  • PDO connection factory: PdoConnectionInterfaceFactory passed a null connection configuration to InvalidConnectionParametersException, whose parameters argument is an array. So a missing configuration raised a TypeError instead of the intended exception; it now passes an empty array. The native ConnectionInterfaceFactory has the same problem but is not touched here.

Baselines

  • Removed: 11 analyzer entries these changes fix.
  • Reduced: 2 counts.
  • Replaced: the constraint and trigger caches still carry keys that phpdb's MetadataData shapes do not declare. Their two property-type-coercion entries are replaced by the mixed-property-type-coercion wording the analyzer now reports.
  • Left alone: the 10 entries that were already stale before this branch. They are left for the analyzer cleanup.

Tests

  • Unit tests: the createStatement() exception and the createResult() generated value.

  • Integration tests:

    • Connection: transactions, execute(), the current schema, the last generated value, disconnect() and a refused connection;
    • Driver::createStatement() on a live connection;
    • Metadata\Source's constraint and trigger loading;
    • both PDO container factories.

    The fixture adds:

    • a test_child table with a foreign key, a check constraint and a trigger;
    • a test_connection table, which the connection tests truncate after each run.

Verification

mago fmt --dry-run, lint, analyze and guard all exit 0, the unit suite passes (9 tests), and the full suite passes (37 tests) against a local PostgreSQL 17, including in random order and against the latest phpdb 0.6.x. Every changed src line is covered.

- Pdo\Driver::createResult() called getLastGeneratedValue() on the
  connection's raw resource type; it now uses the driver's own method,
  which delegates to the connection.
- Driver::createStatement() narrows the connection resource to
  PgSql\Connection and throws a RuntimeException when there is none,
  instead of passing null on to Statement::initialize().
- Connection no longer redeclares $resource. The PgSql\Connection
  narrowing moves into getResource(), and the pg_* calls go through it,
  so the class keeps working once phpdb types the parent property.
- Metadata\Source documents the row shapes of the column, schema and
  table queries, and keys the constraint and trigger caches by string
  names.
- The two container factories are reformatted.

The fixed analyzer entries are removed from the baseline. The constraint
and trigger caches still carry keys that phpdb's MetadataData shapes do
not declare, so their two property-type-coercion entries are replaced by
the mixed-property-type-coercion wording the analyzer now reports.
On PHP 8.4 and later the formatter dropped the parentheses in
(new ConfigProvider())(), which PHP 8.3 cannot parse. mago.toml now sets
parentheses-around-new-in-member-access, as phpdb and phpdb-mysql do.

phpdb 0.6.x removed VunerablePlatformQuoteException; quoting without
driver support now throws Adapter\Exception\RuntimeException with the
same message. The parent class the old exception extended is expected
instead, with the message, so the test passes against both versions.
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…error

Metadata\Source::loadTriggerData() selected condition_timing,
condition_reference_old_table and condition_reference_new_table, which
PostgreSQL renamed to action_timing, action_reference_old_table and
action_reference_new_table in 9.1, so getTriggers() and getTrigger()
failed with an SQL error on every supported server. The action_*
columns are now selected directly, and the alias branch the column
list no longer needs is removed.

PdoConnectionInterfaceFactory passed a null connection configuration
straight to InvalidConnectionParametersException, whose parameters
argument is an array, so a missing configuration raised a TypeError
instead of the intended exception. It now passes an empty array.
…ration tests

- ConnectionTest exercises transactions, execute(), the current schema,
  the last generated value, disconnect() and a refused connection,
  against a test_connection table it truncates after each test, so the
  sequences other tests rely on are untouched.
- DriverTest prepares and runs a statement on a live connection.
- Metadata\SourceTest reads primary key, foreign key and check
  constraints and a trigger, which the fixture now defines on a new
  test_child table.
- PdoFactoriesTest builds the PDO connection and driver from parameters
  and checks the error for a missing configuration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review findings require changes.

No open issues 🎉

What changed in this PR

Updates the PostgreSQL driver for phpdb 0.6.x compatibility, restores Mago checks, and prepares for the parent connection’s typed resource property.

Changes:

  • Corrects connection-resource handling and PDO generated-value retrieval.
  • Fixes trigger metadata queries and PDO factory errors for missing configuration.
  • Adds regression coverage and database fixtures, and updates Mago formatting and baselines.
File Description
test/​unit/​Pdo/​DriverTest.php Tests generated-value propagation into PDO results.
test/​unit/​DriverTest.php Tests rejection of a missing PostgreSQL connection resource.
test/​integration/​TestFixtures/​pgsql.sql Adds connection, constraint, and trigger fixtures.
test/​integration/​Metadata/​SourceTest.php Tests constraint and trigger metadata loading.
test/​integration/​DriverTest.php Tests statement execution on a live connection.
test/​integration/​Container/​PdoFactoriesTest.php Tests PDO factory configuration and error handling.
test/​integration/​ConnectionTest.php Covers transactions, queries, connection lifecycle, schema, and generated values.
test/​integration/​AdapterPlatformTest.php Updates the expected quoting exception and message.
src/​Pdo/​Driver.php Retrieves generated values through the driver method.
src/​Metadata/​Source.php Documents query row shapes, casts cache keys, and fixes trigger column names.
src/​Driver.php Validates the connection resource before initializing statements.
src/​Container/​PdoDriverInterfaceFactory.php Adjusts formatting only.
src/​Container/​PdoConnectionInterfaceFactory.php Ensures invalid configuration produces the intended exception.
src/​Connection.php Removes the resource redeclaration and routes PostgreSQL calls through the typed getter.
mago.toml Configures parentheses around new expressions in member access.
lint-baseline.toml Reduces the resolved else-clause diagnostic count.
analyzer-baseline.toml Removes resolved diagnostics and updates remaining suppression counts and wording.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants