Skip to content

Clear the Mago lint findings in the test suite - #254

Open
simon-mundy wants to merge 5 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-test-lint
Open

simon-mundy wants to merge 5 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-test-lint

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Problem

lint-baseline.toml carried 92 Mago lint findings in the test suite (test/unit/Sql, test/unit/Adapter, test/unit/ResultSet), including:

  • @ error suppression and an empty catch;
  • snake_case test names;
  • literal arguments passed by position;
  • service-name strings shaped like namespaces;
  • redundant variables, and assignments inside call arguments.

Fix

  • Named arguments: optional literal arguments are passed by name (TableIdentifierFactory::__invoke, str_replace, random_int, var_export, assert).
  • Service names: AbstractAdapterInterfaceFactoryTest uses plain adapter service names (WriteAdapter, ReadAdapter), matching the docs, and its data providers are labelled.
  • No @ suppression:
    • The profiler-on-error test uses PDO::ERRMODE_SILENT. The failing query takes the same false path and still throws InvalidQueryException, without emitting a warning.
    • Sql92Test::quoteValueThrowsWithoutDriver drops assertions that could never run after the first throw, and checks the exception message instead.
  • Tidying: the empty catch, redundant variables and assignments inside arguments are removed.
  • Names:
    • The _get, _isset, _set, _unset and _construct tests get behaviour-describing camelCase names, and lose their @codingStandardsIgnore markers.
    • SelectTest's provider variables are camelCased.
  • Test assets and helpers:
    • isset, empty and elseif are replaced (??=, early returns, array_key_exists()).
    • Predicate\Expression is imported instead of written as a fully qualified name.
    • Quoted identifiers use string interpolation.
  • Removed: a stale commented-out TODO fixture.
  • Baseline: the lint baseline goes from 153 to 71 issues.

What stays the same

  • No src/ changes. No assertion is weakened, and one exception-message assertion is added.
  • The same number of tests.
  • The gateway tests are untouched.
  • 10 findings stay baselined on purpose:
    • no-isset ×6, where the test checks that isset() reaches ArrayAccess or __isset;
    • halstead ×2, on two data providers that are large fixture tables;
    • excessive-parameter-list and no-boolean-flag-parameter on SelectTest::prepareStatement, whose signature has to match the shared provider's row shape.

Verification

  • mago format --check, lint, analyze and guard exit 0 on PHP 8.3, 8.4 and 8.5, with no stale baseline entries.
  • The full PHPUnit suite passes with the same test count as 0.6.x, and no warnings or notices.

Pass optional literal arguments by name and replace namespace-shaped adapter service names with plain names, matching the documented configuration style.
Use PDO::ERRMODE_SILENT so the failing query takes the same error path without emitting a warning, drop the unreachable suppressed assertions in Sql92Test in favour of asserting the exception message, connect directly instead of swallowing exceptions, and drop unused credentials from the SQLite fixture.
…e names

Rename the _get/_isset/_set/_unset/_construct tests, drop their coding standards ignore markers, camel-case the SelectTest data provider variables, and remove a redundant variable and an assignment in an argument.
Replace isset/empty/elseif in test assets and helpers, describe assertions, use a deterministic consecutive return in ResultTest, import the predicate Expression class, interpolate quoted identifiers, and drop a stale commented-out TODO fixture. Remove the lint-baseline entries these commits fixed.
@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!

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 lint cleanup across SQL, adapter, and result-set tests.

No open issues 🎉

What changed in this PR

This PR cleans up Mago lint findings across the SQL, adapter, and result-set tests without changing production code or gateway tests.

Changes:

  • Uses named arguments, clearer test names, and simpler fixture setup.
  • Removes error suppression and redundant code, and adds an exception-message assertion.
  • Reduces the lint baseline from 153 to 71 findings, retaining intentional exceptions.
File Description
test/​unit/​Sql/​UpdateTest.php Imports the predicate expression class.
test/​unit/​Sql/​TableIdentifierFactoryTest.php Uses named factory arguments.
test/​unit/​Sql/​SqlTest.php Renames and relocates the constructor-related test.
test/​unit/​Sql/​SelectTest.php Clarifies fixture names and removes redundant assignments.
test/​unit/​Sql/​Predicate/​PredicateTest.php Simplifies expression assertions.
test/​unit/​Sql/​Platform/​AbstractPlatformTest.php Uses interpolation for quoted identifiers.
test/​unit/​Sql/​InsertTest.php Renames magic-method tests and removes an unused variable.
test/​unit/​Sql/​InsertIgnoreTest.php Gives magic-method tests descriptive names.
test/​unit/​Sql/​Ddl/​AlterTableTest.php Uses named string-replacement arguments.
test/​unit/​Sql/​AbstractSqlFunctionalTestCase.php Updates array-key checks and removes a commented-out fixture.
test/​unit/​ResultSet/​ResultSetIntegrationTest.php Uses named utility-function arguments.
test/​unit/​ResultSet/​AbstractResultSetTest.php Adds an assertion description.
test/​unit/​Adapter/​Platform/​Sql92Test.php Removes suppression and checks the exception message.
test/​unit/​Adapter/​Driver/​Pdo/​TestAsset/​TestConnection.php Simplifies constructor flow and DSN initialization.
test/​unit/​Adapter/​Driver/​Pdo/​TestAsset/​SqliteMemoryPdo.php Types the SQL argument and makes empty-value checks explicit.
test/​unit/​Adapter/​Driver/​Pdo/​StatementTest.php Separates PDO creation from method arguments.
test/​unit/​Adapter/​Driver/​Pdo/​StatementIntegrationTest.php Separates mock creation from initialization.
test/​unit/​Adapter/​Driver/​Pdo/​ResultTest.php Uses deterministic mock results and describes an assertion.
test/​unit/​Adapter/​Driver/​Pdo/​PdoTest.php Removes an unused assignment.
test/​unit/​Adapter/​Driver/​Pdo/​ConnectionTransactionsTest.php Avoids unnecessary counter mutations in assertions.
test/​unit/​Adapter/​Driver/​Pdo/​ConnectionTest.php Removes suppression, an empty catch, and redundant setup.
test/​unit/​Adapter/​Container/​AbstractAdapterInterfaceFactoryTest.php Simplifies service names and labels provider cases.
test/​unit/​Adapter/​AdapterTest.php Separates profiler creation from assignment.
lint-baseline.toml Removes entries for resolved lint findings.

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