Skip to content

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

Merged
simon-mundy merged 7 commits into
php-db:0.6.xfrom
simon-mundy:test/adapter-coverage-100
Jul 1, 2026
Merged

Achieve 100% test coverage for Adapter/* classes#143
simon-mundy merged 7 commits into
php-db:0.6.xfrom
simon-mundy:test/adapter-coverage-100

Conversation

@simon-mundy

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

Copy link
Copy Markdown
Member

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

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
Resolve conflicts and reconcile with upstream API changes (PR php-db#144 phpstan-type
Profiler, PR php-db#145 provide-driver-defaults):

- Profiler.php: take upstream's phpstan-typed version (supersedes PR's dead-code pass)
- AdapterInterfaceDelegatorTest: union of both test sets; keep PR's #[Group]/
  #[CoversMethod] plus upstream's testDelegatorWithPluginManager
- ConnectionTest: keep upstream's testResource and the PR's real
  testConstructorWithPdoResourceSetsConnected (drop skipped placeholder)
- Remove getDatabasePlatformName from test assets (API method removed upstream)
- Rewrite TestPdoWithFeatures constructor to set properties directly
  (AbstractPdo constructor removed upstream)
- Drop obsolete testCloneWithNullParameterContainerDoesNotClone
  (Statement parameter container is now non-nullable)
- Remove invalid #[CoversMethod(...'__construct')] attributes in ConnectionTest
  and PdoTest that were marking tests risky and discarding coverage

Suite: 1444 tests pass, PHPStan clean, PHPCS clean, 99.94% line coverage.
The trait was incorrectly covered (CoversMethod instead of CoversTrait) and
its test was accidentally excluded from the suite. Now 1446 tests, 100%
coverage.
ConnectionIntegrationTest ran in neither suite (excluded from unit, absent
from the empty integration suite) and added no coverage the unit tests don't
already provide. Also drop the exclude for AdapterServiceFactoryTest, which
no longer exists.
This test checks that values are bound with the correct PDO type when a
statement runs, which nothing else covers. It was excluded from the suite
before, so it never ran. It is worth keeping, so now it runs.
Resolves 7-file conflict caused by PR php-db#142's test-method renames and
attribute cleanup overlapping with this branch's coverage work.

- AdapterAwareTraitTest: adopt CoversMethod over CoversTrait to match
  the rest of the suite (78 other files use CoversMethod; this was the
  only CoversTrait usage)
- AbstractConnectionTest/TestConnection: kept this branch's TestConnection
  fixture (extends AbstractConnection directly) over upstream's
  ConnectionWrapper, which extends AbstractPdoConnection and would have
  reintroduced the wrong-hierarchy coverage gap this PR fixes. Also gave
  TestConnection a constructor param for driverName so
  testGetDriverNameReturnsValueWhenSet genuinely exercises a non-null
  value instead of asserting null
- AdapterInterfaceDelegatorTest: both branches independently added the
  same three tests at different positions; deduplicated to one copy
- PdoTest: adopted upstream's `$unused = $pdo->getProfiler()` over a
  phpstan-ignore comment to silence the unused-result warning
- ProfilerTest: kept this branch's split of testProfilerStart into
  separate string/container tests (one logical assertion per test)
  over upstream's combined version
- Dropped upstream's `CoversMethod(..., '__construct')` additions on
  AbstractPdo/AbstractPdoConnection in PdoTest/ConnectionTest since
  neither class declares its own constructor

Full unit suite (1451 tests), phpcs, and phpstan all pass post-merge.
Comment thread test/unit/Adapter/Container/TestAsset/TestPluginManager.php
@simon-mundy simon-mundy merged commit 70ed3aa into php-db:0.6.x Jul 1, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @phpdb Jul 1, 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: Done

Development

Successfully merging this pull request may close these issues.

2 participants