Repository navigation
Bring Mago back to green against phpdb 0.6.x - #16
Open
simon-mundy wants to merge 4 commits into
Open
simon-mundy wants to merge 4 commits into
simon-mundy wants to merge 4 commits into
Conversation
- 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 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.
There was a problem hiding this comment.
🟢 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
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.
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 owngetLastGeneratedValue(), which passes the call to the connection. Before, it was called on the raw resource type.Driver::createStatement(): the connection resource is narrowed toPgSql\Connection. ARuntimeExceptionis thrown when there is none, instead of passingnullon toStatement::initialize().Connection: it no longer redeclares$resource. ThePgSql\Connectionnarrowing moves intogetResource(), and thepg_*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 asmixed; 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.Bugs found while adding tests
Metadata\Source::loadTriggerData()selectedcondition_timing,condition_reference_old_tableandcondition_reference_new_table. PostgreSQL renamed these toaction_*in 9.1, sogetTriggers()andgetTrigger()failed with an SQL error on every supported server. Theaction_*columns are now selected directly.PdoConnectionInterfaceFactorypassed anullconnection configuration toInvalidConnectionParametersException, whose parameters argument is an array. So a missing configuration raised aTypeErrorinstead of the intended exception; it now passes an empty array. The nativeConnectionInterfaceFactoryhas the same problem but is not touched here.Baselines
MetadataDatashapes do not declare. Their twoproperty-type-coercionentries are replaced by themixed-property-type-coercionwording the analyzer now reports.Tests
Unit tests: the
createStatement()exception and thecreateResult()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;The fixture adds:
test_childtable with a foreign key, a check constraint and a trigger;test_connectiontable, which the connection tests truncate after each run.Verification
mago fmt --dry-run,lint,analyzeandguardall 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 changedsrcline is covered.