Skip to content

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

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

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

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Mago fails on this branch against current phpdb 0.6.x. This makes it pass again. It is the first of the driver cleanup PRs; the analyzer and lint baselines are reduced in follow-ups.

Changes

  • Pdo\Driver::createResult():
    • columnCount() is only called when the resource is a PDOStatement.
    • 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 PDO.
  • Pdo\Feature\SqliteRowCounter: both count paths now fetch through a private fetchCount(). It throws PhpDb\Adapter\Exception\RuntimeException when the count query does not produce a PDOStatement; before, fetch() was called on false. Its @throws are documented.
  • Metadata\Source: the column, constraint, table and trigger caches are keyed by the name cast to string.

Baselines

  • Removed or reduced: the entries these changes fix.
  • Replaced one for one: the cached metadata arrays still carry keys (such as constraint_name and trigger_name) that phpdb's MetadataData shapes do not declare. So the five property-type-coercion entries for those assignments are now reported as three mixed-property-type-coercion and two invalid-property-assignment-value, and their baseline entries are swapped for the new wording. Typing the rows properly is left to the analyzer cleanup.

Tests

The SqliteRowCounter tests are rewritten to cover every path, and createResult() tests are added to the Pdo\Driver tests.

Verification

mago fmt --dry-run, lint, analyze and guard all exit 0. The unit suite passes (110 tests), and so does the integration suite (18 tests).

Driver::createResult() called columnCount() on a resource documented as
PDOStatement|resource, and getLastGeneratedValue() on a connection that
may be a raw PDO. The row counter is now only consulted for a
PDOStatement, and the last generated value is read through
AbstractPdo::getLastGeneratedValue(), which delegates to the connection.

SqliteRowCounter fetched the count from PDO::query() (PDOStatement|false)
and from a result resource typed as mixed. Both paths now go through a
private fetchCount() that requires a PDOStatement and throws a
RuntimeException otherwise. The thrown exceptions are documented on the
public methods and on the row count closure.

Tests cover the row counter for SQL and statement contexts, the failure
paths, and how createResult() wires the row counter and generated value.
Baseline entries made obsolete by these changes are removed or reduced.
The column, constraint, table and trigger loops used the mixed name
from each row as an array key, which the analyzer reports as an
invalid index type. The names are now cast to string.

The cached arrays still carry keys that phpdb's MetadataData shapes do
not declare, so the five baselined property-type-coercion entries for
these assignments are now reported as mixed-property-type-coercion and
invalid-property-assignment-value. Their baseline entries are replaced
one for one; typing the rows properly is left to the analyzer cleanup.
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.

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 issues remain for the SQLite adapter compatibility and Mago updates.

No open issues 🎉

What changed in this PR

This PR updates the SQLite adapter for phpdb 0.6.x compatibility and restores Mago checks, leaving broader driver and baseline cleanup to follow-up PRs.

Changes:

  • Guards PDO statement access, delegates generated-value retrieval through the driver, and centralizes count-query validation.
  • Casts metadata cache keys to strings and updates Mago configuration and baselines.
  • Expands driver and row-counter tests and aligns quoting-exception expectations with phpdb.
File Description
test/​unit/​Pdo/​Feature/​SqliteRowCounterTest.php Covers count queries, failure handling, and row-count closures.
test/​unit/​Pdo/​DriverTest.php Adds generated-value and row-counter selection tests.
test/​unit/​AdapterPlatformTest.php Updates expected quoting exceptions and messages.
src/​Pdo/​Feature/​SqliteRowCounter.php Shares count fetching, validates statements, and documents exceptions.
src/​Pdo/​Driver.php Guards columnCount() and uses driver-level generated-value retrieval.
src/​Metadata/​Source.php Casts column, constraint, table, and trigger cache keys to strings.
mago.toml Configures parentheses around new expressions used in member access.
lint-baseline.toml Removes or reduces entries resolved by the changes.
analyzer-baseline.toml Updates metadata diagnostics and reduces row-counter baseline entries.

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