Skip to content

Improve test coverage to 100% and raise Infection thresholds - #11

Merged
loevgaard merged 1 commit into
masterfrom
improve-test-coverage
Aug 31, 2026
Merged

Improve test coverage to 100% and raise Infection thresholds#11
loevgaard merged 1 commit into
masterfrom
improve-test-coverage

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

Tests only — no changes to src/.

Before After
Line coverage 90.0% (297/330) 100% (330/330)
Method / class coverage 82% / 62% 100% / 100%
Tests / assertions 41 / 83 80 / 188
Infection MSI / covered MSI 74% / 80% 94% / 94%
Uncovered mutants 19 0
  • tests/Exception/ClientExceptionTest.php (new) — ClientException was 0% covered: all three factories, exact messages incl. subcode and user-facing title/message variants, previous exception.
  • tests/ValueObject/FbTest.php (new) — the abstract Fb base via Fbp: DateTimeInterface creation time, founding-date/future bounds, subdomain-index validation and immutability, defaults.
  • ClientTestsetRequestFactory/setStreamFactory (one request per pixel with the pixel's own token) and HTTP-client auto-discovery when nothing is injected, using a test DiscoveryStrategy prepended to Psr18ClientDiscovery (restored in finally, no network).
  • ErrorResponseTest — the three negative tests consolidated into one data provider covering 16 malformed responses (missing required fields plus a wrong type for every field).
  • FbqGeneratorTest — JSON-encode failure logs an error and returns ''.
  • EventTest/ContentTest/CustomTest — default event id/time, the standard-event list, invalid action_source/delivery_category rejection, full Custom payload, unsupported value rejection.
  • tests/TestLogger.php — moved out of ClientTest.php so FbqGeneratorTest can share it.
  • infection.json.dist — thresholds raised 61.74 → 90 (MSI) and 76.77 → 90 (covered MSI); CLAUDE.md updated to match.

The 14 remaining escaped mutants are either untestable (random_int bounds, ceil vs floor on microtime, JSON depth 512, time() + 1 upper bound) or a pcov attribution artifact (tests whose frames in a file are all unwound by an exception get no line attribution there, so Infection doesn't select them — verified by applying the Parameters.php:96 mutant by hand).

Test plan

  • vendor/bin/phpunit — 80 tests, 100% line coverage
  • vendor/bin/phpstan analyse (level max, incl. tests)
  • vendor/bin/ecs check
  • vendor/bin/composer-dependency-analyser, composer normalize --dry-run
  • vendor/bin/infection — MSI 94%, passes the raised thresholds
  • PHPUnit + PHPStan on PHP 8.1 with --prefer-lowest
  • Five consecutive PHPUnit runs stable (time-based tests use tolerant bounds)

Line coverage goes from 90% to 100% and the mutation score (MSI) from
74% to 94%; the Infection thresholds are raised from 61.74/76.77 to 90/90
to lock the gains in.

Tests only, no changes to src/:

- ClientExceptionTest (new): all three factories with exact messages,
  including subcode and the user facing title/message variants
- FbTest (new): DateTimeInterface creation time, founding date/future
  bounds, subdomain index validation and immutability
- ClientTest: injected request/stream factories (one request per pixel)
  and HTTP client auto discovery through a test DiscoveryStrategy
- ErrorResponseTest: data provider covering missing required fields and
  a wrong type for every field
- FbqGeneratorTest: JSON encode failure logs an error and returns ''
- EventTest/ContentTest/CustomTest: default event id/time, the standard
  event list, invalid action_source/delivery_category, full Custom
  payload, unsupported values
- TestLogger moved to tests/TestLogger.php so it can be shared
@loevgaard
loevgaard merged commit b495b39 into master Aug 31, 2026
28 checks passed
@loevgaard
loevgaard deleted the improve-test-coverage branch August 31, 2026 12:30
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