Skip to content

Achieve 100% test coverage for Adapter/* classes#2

Closed
simon-mundy wants to merge 1 commit into
refactor/dead-code-cleanupfrom
test/adapter-coverage-100
Closed

Achieve 100% test coverage for Adapter/* classes#2
simon-mundy wants to merge 1 commit into
refactor/dead-code-cleanupfrom
test/adapter-coverage-100

Conversation

@simon-mundy

Copy link
Copy Markdown
Owner

Summary

Closes the remaining 29 uncovered lines across Adapter/* by adding targeted tests, fixing coverage attribution, and introducing two new test assets. Brings Adapter/* from 93% to 100% line coverage.

Root causes of the gaps

The uncovered lines fell into three categories:

  1. Wrong test asset hierarchyAbstractConnectionTest used ConnectionWrapper which extends AbstractPdoConnection. Since AbstractPdoConnection overrides setConnectionParameters() and provides its own isConnected(), the inherited AbstractConnection methods were never exercised.

  2. Missing #[CoversMethod] attributionPdoTest tested formatParameterName() extensively via data providers but didn't declare #[CoversMethod(AbstractPdo::class, 'formatParameterName')], so 16 lines of coverage weren't credited.

  3. Untested code pathsStatement::bindParametersFromContainer() early-return when already bound (requires double-execute), Statement::__clone() with a non-null ParameterContainer, and AbstractPlatform::quoteValue() which was always tested through Sql92 (which overrides it).

New test assets

  • TestConnection (test/unit/Adapter/Driver/TestAsset/) — Extends AbstractConnection directly, not through AbstractPdoConnection. Provides a resource-based isConnected() so disconnect() and getResource() auto-connect work correctly against the base class.

  • TestPlatform (test/unit/Adapter/Platform/TestAsset/) — Extends AbstractPlatform without overriding quoteValue(), allowing direct coverage of the base class throw (no driver) and escape (with driver) paths.

Test changes

File What changed
AbstractConnectionTest Switched from ConnectionWrapper to TestConnection so AbstractConnection::setConnectionParameters(), getResource() auto-connect, and getDriverName() are exercised directly
PdoTest Added #[CoversMethod] for formatParameterName; added @phpstan-ignore for method.resultUnused on expected-throw test
StatementTest Added testSecondExecuteSkipsBindingWhenAlreadyBound (double-execute covers the parametersBound early return) and testCloneClonesParameterContainerWhenSet
Sql92Test Added testAbstractPlatformQuoteValueThrowsWithoutDriver and testAbstractPlatformQuoteValueEscapesWithDriver via TestPlatform
ProfilerTest Split testProfilerStart into testProfilerStartWithString and testProfilerStartWithStatementContainer; removed dead TypeError assertion (union type covers it)
ParameterContainerTest Removed stale @phpstan-ignore argument.type (method accepts mixed)
phpunit.xml.dist Re-enabled AdapterAwareTraitTest — the test works correctly, the exclusion was a leftover

Test plan

  • ./vendor/bin/phpunit — 1446 tests pass, 0 failures
  • ./vendor/bin/phpstan — 0 errors
  • ./vendor/bin/phpcs — no new violations
  • XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text — Adapter/* shows 100%

Add targeted tests and fix coverage attribution to close the remaining
29 uncovered lines across Adapter/*.

New test assets:
- TestConnection: extends AbstractConnection directly (not via
  AbstractPdoConnection) to test inherited methods like
  setConnectionParameters() and getResource() auto-connect
- TestPlatform: extends AbstractPlatform without overriding quoteValue(),
  allowing direct coverage of the base class throw/escape paths

Test changes:
- AbstractConnectionTest: switch from ConnectionWrapper (which goes
  through AbstractPdoConnection overrides) to TestConnection so
  AbstractConnection methods are exercised directly
- PdoTest: add missing #[CoversMethod] for formatParameterName, fix
  phpstan method.resultUnused warning
- StatementTest: add double-execute test (bindParametersFromContainer
  early-return path) and clone-with-container test
- Sql92Test: add tests for AbstractPlatform::quoteValue() throw and
  escape paths via TestPlatform
- ProfilerTest: split combined test into separate string/container
  tests, remove dead TypeError assertion (covered by union type)
- ParameterContainerTest: remove stale @PHPStan-Ignore

Config:
- phpunit.xml.dist: re-enable AdapterAwareTraitTest (the test works,
  the exclusion was a leftover)
@simon-mundy
simon-mundy marked this pull request as draft March 25, 2026 09:50
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.

1 participant