test: raise line coverage from 66% to 96% - #63
Merged
Merged
Conversation
Adds tests only - no production code was changed. Classes 38.88% -> 77.77% (7/18 -> 14/18) Methods 62.96% -> 92.59% (34/54 -> 50/54) Lines 66.66% -> 95.72% (156 -> 224 of 234) Tests 38 -> 84, assertions 100 -> 195 New coverage: - HttpErrorHandler (0% -> 100%): all six HttpException subtypes via a data provider, plus the generic-exception path and both displayErrorDetails branches, asserting details never leak when the flag is off. - DatabaseWrapper (0% -> 100%): Kreait's Reference and ApiClient are final and cannot be mocked, but ApiClient accepts a Guzzle ClientInterface. So the real SDK stack runs against a Guzzle MockHandler with canned responses - no emulator, no live database, deterministic in CI. Covers the HTTP verb and body for each operation and the null-key guard in push(). - ShutdownHandler / ResponseEmitter (0% -> 89% / 100%): message formatting per error type, asserted through the emitted JSON body, plus the buffer-discard path that keeps stray output from reaching the client. - Action (80% -> 100%): resolveArg's rejection path and the domain-to-HTTP 404 translation. - ActionPayload, ActionError, SessionMiddleware: 100%. Ten lines remain uncovered, each for a concrete reason: - ShutdownHandler 57-59: the E_USER_ERROR branch. trigger_error() with E_USER_ERROR halts the process, which would kill the test run. - JsonBodyParserMiddleware 23: reads php://input directly, always empty under the CLI SAPI. Reading $request->getBody() instead would make it testable. - FirebaseTodoRepository 20-24: the Factory branch needs real credentials. - InMemoryTodoRepository 33: an Xdebug line-attribution artifact - the closing bracket of a multi-line array literal is marked executable but never recorded as hit. Lines 27-32 are covered. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
Tests only — no production code was changed (
git diff master --stattouches nothing undersrc/).What's newly covered
HttpErrorHandler0% → 100% — all sixHttpExceptionsubtypes via a data provider, the generic-exception path, and bothdisplayErrorDetailsbranches. Includes an assertion that internal details never leak when the flag is off.DatabaseWrapper0% → 100% — this is the class I'd previously said would need the Firebase emulator. That was wrong.ReferenceandApiClientarefinaland unmockable, butApiClient's constructor takes Guzzle'sClientInterface, andKreait\Firebase\Databaseis publicly constructible. So the tests drive the real SDK stack against a GuzzleMockHandlerwith canned HTTP responses — no emulator, no live database, fully deterministic, and it runs in CI. Covers the HTTP verb and request body for each operation plus the null-key guard inpush().ShutdownHandler0% → 89%,ResponseEmitter0% → 100% — message formatting per error type, asserted through the emitted JSON body, plus the buffer-discard path that stops stray output reaching the client. Each runs#[RunInSeparateProcess]since they touch process globals.Action80% → 100% —resolveArg's rejection path and the domain-exception-to-HTTP-404 translation, via a minimal concrete subclass.ActionPayload,ActionError,SessionMiddleware— all to 100%.The ten lines still uncovered
Each has a concrete reason rather than being an oversight:
ShutdownHandler:57-59E_USER_ERRORbranch.trigger_error()withE_USER_ERRORhalts the process, which would kill the test run.JsonBodyParserMiddleware:23php://inputdirectly, always empty under the CLI SAPI.FirebaseTodoRepository:20-24Factorybranch needs real Firebase credentials.InMemoryTodoRepository:33];of a multi-line array literal is marked executable but never recorded as hit. Lines 27–32 are covered, so the default array is genuinely constructed. No test can reach it.Suggested follow-up (not done here)
JsonBodyParserMiddlewarereadsphp://inputdirectly instead of$request->getBody(). Switching to the PSR-7 body would be equivalent in production — Slim populates the request body fromphp://inputanyway — and would make the JSON-parsing path testable. I left it alone since it's a behaviour change to production code and this PR is deliberately tests-only.🤖 Generated with Claude Code