Remove dead code in Profiler, add static analysis annotations#142
Merged
Conversation
…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.
Rename ~30 test methods across Adapter test suite to follow the convention of naming tests after what they verify rather than which method they call. Pattern applied: - Fluent/chaining tests: testFluent<Method> - Getter tests: test<Method>Returns<What> - Throw tests: test<Method>ThrowsOn<Condition> - Delegation tests: test<Method>DelegatesToX Simple getter/setter tests (testSetSql, testOffsetGet, etc.) left as-is where the method name already describes the behaviour.
Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com>
Member
|
There's still merge conflicts. I'm assuming this PR needs merged before #143 ? |
…-cleanup # Conflicts: # src/Adapter/Profiler/Profiler.php # test/unit/Adapter/Container/AdapterInterfaceDelegatorTest.php # test/unit/Adapter/Driver/Pdo/ConnectionTest.php # test/unit/Adapter/Driver/Pdo/PdoTest.php
tyrsson
approved these changes
Jul 1, 2026
simon-mundy
added a commit
to simon-mundy/phpdb
that referenced
this pull request
Jul 1, 2026
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.
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.
Summary
Dead-code removal in
src/plus expansion of unit-test coverage. No behavioural changes.src/changessrc/Sql/AbstractSql.php— Remove dead codeprocessValuesArgument()and itsValuesmatch armis_string/is_callablejoin-name branch and itsInvalidArgumentExceptionthrowsrc/ResultSet/AbstractResultSet.php— Remove dead codeIterator/elsebranches ininitialize(),valid(), andrewind(). ATraversablethat is neitherIteratornorIteratorAggregateis not constructible in PHP, so thekey()/reset()fallbacks and theInvalidArgumentExceptionthrow were unreachable. The narrowed assignment is annotated with@phpstan-ignore.src/Adapter/Driver/Pdo/AbstractPdo.php— Mark unreachable throw@codeCoverageIgnoreStart/Endaround theextension_loaded('PDO')throw incheckEnvironment(). The throw cannot fire in practice:AbstractPdorequires the PDO extension to even be loadable.Test coverage