Skip to content

[#483] Increase Tracer ErrorHandler unit-test coverage - #486

Merged
armanist merged 5 commits into
quantum-php:masterfrom
armanist:feature/483-tracer-coverage
Apr 30, 2026
Merged

armanist merged 5 commits into
quantum-php:masterfrom
armanist:feature/483-tracer-coverage

Conversation

@armanist

@armanist armanist commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #483

Summary by CodeRabbit

  • Tests
    • Expanded test suite for error handling and exception processing, including validation of logging behavior, stack trace rendering, and error type identification in both debug and production environments.

@coderabbitai

coderabbitai Bot commented Apr 30, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@armanist has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 50 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5aa831d1-afac-42ce-9eaa-14b72854d4ae

📥 Commits

Reviewing files that changed from the base of the PR and between feb0bf9 and e20aad4.

📒 Files selected for processing (4)
  • src/Tracer/ErrorHandler.php
  • tests/Unit/Tracer/ErrorHandlerTest.php
  • tests/_root/shared/views/errors/500.php
  • tests/_root/shared/views/errors/trace.php
📝 Walkthrough

Walkthrough

Expanded unit test suite for the ErrorHandler class with 249 new lines of test code, covering private behaviors via reflection, exception handling in CLI and web contexts, logging behavior across debug and production modes, and stack trace rendering internals.

Changes

Cohort / File(s) Summary
ErrorHandler Test Coverage Expansion
tests/Unit/Tracer/ErrorHandlerTest.php
Added comprehensive unit tests for ErrorHandler class covering exception handling in CLI and web contexts, debug vs. production mode behavior, logging scenarios, stack trace composition, source code retrieval, error type mapping via data provider, and internal formatting logic. Includes reflection-based helper for invoking private methods and temporary view template creation/cleanup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

testing

Poem

A rabbit hops through error logs with glee,
Testing traces and exceptions so carefully,
With 249 lines of tests so bright,
ErrorHandler coverage shines in the light,
From CLI to web, all paths now gleaming,
Coverage climbing—the rabbit's dreaming! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change—expanding unit-test coverage for the Tracer ErrorHandler class, which directly aligns with the changeset.
Linked Issues check ✅ Passed The PR addresses issue #483 by expanding ErrorHandler unit tests to cover exception handling, logging, stack trace rendering, and error type mappings, contributing to the >=90% line coverage goal.
Out of Scope Changes check ✅ Passed All changes are within tests/Unit/Tracer/ErrorHandlerTest.php and directly serve the objective of increasing test coverage for src/Tracer/ErrorHandler, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 3 minutes and 50 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.83%. Comparing base (317224b) to head (e20aad4).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #486      +/-   ##
============================================
+ Coverage     86.98%   87.83%   +0.85%     
- Complexity     2903     2904       +1     
============================================
  Files           249      249              
  Lines          7651     7653       +2     
============================================
+ Hits           6655     6722      +67     
+ Misses          996      931      -65     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@armanist armanist added this to the 3.0.0 milestone Apr 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/Unit/Tracer/ErrorHandlerTest.php`:
- Around line 182-205: The temp file cleanup in ErrorHandlerTest uses
createFile(...) then invokes composeStackTrace via invokePrivateMethod(...) and
calls removeFile(...) only after the happy path; change the test to wrap the
invocation/assertions in a try { ... } finally { $this->removeFile($sourceFile);
} so removeFile(...) always runs even on failures, and apply the same
try/finally pattern to the similar temp-file block around lines 287-293.
- Around line 113-117: The test testHandleExceptionCliWritesExceptionMessage
currently calls $this->errorHandler->handleException(new Exception('CLI
failure')) with no assertions; change it to capture and assert the CLI output by
either using output buffering (ob_start/ob_get_clean) around the handleException
call or by mocking/stubbing whatever output/writer dependency the ErrorHandler
uses, then assert the emitted string contains "CLI failure" (or the exact
formatted message) so the test verifies the output behavior of
ErrorHandler::handleException for CLI.
- Around line 275-283: This test mutates FileSystemFactory::instances without
restoring it, risking side effects for other tests; capture the original
instances value from the ReflectionProperty
($instancesProperty->getValue($factory)) before calling setValue, then ensure
you restore it after the test (either in a try/finally surrounding the
mutation/assertion or by resetting it in tearDown) using
$instancesProperty->setValue($factory, $original) so
FileSystemFactory::instances is returned to its prior state.
- Around line 30-40: The test currently overwrites shared view files in setUp
and unconditionally deletes them in tearDown, which can remove real fixtures;
modify setUp/tearDown in ErrorHandlerTest to preserve existing templates by
checking file existence and backing up original content: in setUp, if
traceViewPath or error500ViewPath exist, read and store their original contents
in private properties (e.g., $originalTraceView, $originalError500View) and set
a flag (e.g., $createdTraceView, $createdError500View) when you create a new
file via createFile; in tearDown, if an original content was saved, restore it
(write back the original content) instead of deleting, and only call removeFile
for paths that were actually created by the test (use the created* flags) so
existing fixtures are not lost.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c857b9da-6fe2-49e3-b572-64e1889961af

📥 Commits

Reviewing files that changed from the base of the PR and between 317224b and feb0bf9.

📒 Files selected for processing (1)
  • tests/Unit/Tracer/ErrorHandlerTest.php

Comment thread tests/Unit/Tracer/ErrorHandlerTest.php Outdated
Comment thread tests/Unit/Tracer/ErrorHandlerTest.php
Comment thread tests/Unit/Tracer/ErrorHandlerTest.php Outdated
Comment thread tests/Unit/Tracer/ErrorHandlerTest.php
@armanist
armanist merged commit fc78cf1 into quantum-php:master Apr 30, 2026
7 checks passed
@armanist
armanist deleted the feature/483-tracer-coverage branch April 30, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase Tracer package unit-test coverage to >=90%

1 participant