Skip to content

[TEST] Add unit tests for Exception class hierarchy (4 classes have zero dedicated tests) #102

Description

@jeromesinolanka

Priority: 🟠 High

Description

The library ships four exception classes but none have a dedicated test file:

  • src/Fetch/Exceptions/ClientException.php
  • src/Fetch/Exceptions/HttpException.php
  • src/Fetch/Exceptions/NetworkException.php
  • src/Fetch/Exceptions/RequestException.php

These classes appear in the codebase as catch targets and thrown types, but their construction, message formatting, code propagation, and $previous chaining are never directly validated. If a refactor changes a constructor signature or message format, no test will catch it.

This gap is particularly important given issue #81 ([HIGH-1]), which recommends throwing domain exceptions instead of RuntimeException — that change has no test coverage to land on.

Recommended Fix

Create tests/Unit/Exceptions/ExceptionTest.php (or one file per class) covering:

// Example structure
it('constructs with message and code', function () {
    $e = new NetworkException('Connection refused', 503);
    expect($e->getMessage())->toBe('Connection refused');
    expect($e->getCode())->toBe(503);
});

it('preserves $previous exception chain', function () {
    $previous = new \RuntimeException('original');
    $e = new NetworkException('Wrapped', 0, $previous);
    expect($e->getPrevious())->toBe($previous);
});

it('extends the correct parent class', function () {
    expect(new NetworkException(''))->toBeInstanceOf(\RuntimeException::class);
});

Test all four classes. Confirm the inheritance hierarchy matches the documented contract.

Related

Issue #81 — HIGH-1: Guzzle exceptions re-wrapped as RuntimeException

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

error-handlingException types, wrapping, and propagationneeds-triageNeeds review before work beginspriority: highSignificant bug or architectural issuetestingTest coverage, fixtures, or testing infrastructure

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions