Skip to content

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

Open
simon-mundy wants to merge 4 commits intophp-db:0.6.xfrom
simon-mundy:test/adapter-coverage-100
Open

Achieve 100% test coverage for Adapter/* classes#143
simon-mundy wants to merge 4 commits intophp-db:0.6.xfrom
simon-mundy:test/adapter-coverage-100

Conversation

@simon-mundy
Copy link
Member

@simon-mundy simon-mundy commented Mar 25, 2026

Summary

Stacked on #142 — review that PR first. The diff here will simplify once #142 merges.

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

…rastructure

- Add ~270 new test methods across 60 files, bringing line coverage
  from 84% (2809/3354) to 99.13% (3289/3318)
- Achieve 100% coverage for Sql/*, ResultSet/*, Metadata/*, Container/*
- Remove dead code in AbstractSql (unreachable processValuesArgument,
  defensive throw in processJoin) and AbstractResultSet (unreachable
  non-Iterator branches in valid/rewind, unreachable throw in initialize)
- Remove 9 permanently-skipped tests that were redundant, had
  contradictory logic, or tested removed functionality
- Replace all anonymous classes in tests with proper TestAsset classes
  for reusability and consistency
- Fix invalid #[CoversMethod] attributes causing PHPUnit warnings
- Fix #[CoversMethod] parentheses in method name strings
- Add REFACTOR.md documenting completed work and remaining Adapter/* gaps

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
- Profiler::profilerStart(): remove unreachable else-branch. The union
  type `string|StatementContainerInterface` guarantees only those two
  types can be passed; the if/elseif handles both exhaustively, making
  the else+throw dead code. Clean up unused imports (InvalidArgumentException,
  is_string).

- AbstractPdo::checkEnvironment(): mark the throw inside
  `if (!extension_loaded('PDO'))` with @codeCoverageIgnore. PDO is a
  hard requirement — this branch cannot execute in any environment where
  the class is loadable.

- AbstractResultSet::initialize(): add @phpstan-ignore for Traversable
  assignment. After array and IteratorAggregate branches are handled, the
  remaining Traversable is necessarily an Iterator, but PHPStan cannot
  narrow it.
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 self-assigned this Mar 25, 2026
@simon-mundy simon-mundy added bug Something isn't working qa Improvements in quality assurance of the project labels Mar 25, 2026
@github-project-automation github-project-automation bot moved this to Todo in @phpdb Mar 25, 2026
@simon-mundy simon-mundy moved this from Todo to In Progress in @phpdb Mar 25, 2026
@simon-mundy simon-mundy modified the milestone: 0.6.0 Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working qa Improvements in quality assurance of the project

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant