Skip to content

Commit 2c005e0

Browse files
authored
Merge pull request #1 from dmstr/feature/unit-tests
✅ Exception-Hierarchie-Tests + CI
2 parents 13bdf97 + 8fd49a5 commit 2c005e0

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC
2+
name: Tests
3+
4+
on:
5+
push:
6+
branches: [main, master, "feature/**"]
7+
pull_request:
8+
9+
jobs:
10+
phpunit:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php: ["8.4"]
16+
name: PHPUnit (PHP ${{ matrix.php }})
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: ${{ matrix.php }}
22+
coverage: none
23+
- run: composer install --no-interaction --no-progress
24+
- run: vendor/bin/phpunit

‎docker-compose.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC
2+
# CLI-only test runner for this library — no MySQL/FPM required.
3+
# Usage (on host):
4+
# docker compose run --rm php
5+
# Runs `composer install` then PHPUnit against tests/.
6+
services:
7+
php:
8+
build:
9+
dockerfile_inline: |
10+
FROM php:8.4-cli-alpine
11+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
12+
working_dir: /repo
13+
volumes:
14+
- .:/repo
15+
command: sh -c "composer install --no-interaction --no-progress && vendor/bin/phpunit"

‎tests/Exception/ExceptionTest.php‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
// file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC
3+
4+
declare(strict_types=1);
5+
6+
namespace Dmstr\Bc4Client\Tests\Exception;
7+
8+
use Dmstr\Bc4Client\Exception\Bc4ApiException;
9+
use Dmstr\Bc4Client\Exception\InvalidGrantException;
10+
use Dmstr\Bc4Client\Exception\RequestException;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* Unit tests for the BC4 client exception hierarchy — verifies the type
15+
* relationships callers rely on for catch-block dispatch, plus the
16+
* RequestException payload accessors.
17+
*/
18+
final class ExceptionTest extends TestCase
19+
{
20+
public function testBc4ApiExceptionIsRuntimeException(): void
21+
{
22+
self::assertInstanceOf(\RuntimeException::class, new Bc4ApiException('boom'));
23+
}
24+
25+
public function testInvalidGrantExceptionExtendsBc4ApiException(): void
26+
{
27+
$exception = new InvalidGrantException('refresh token rejected');
28+
29+
self::assertInstanceOf(Bc4ApiException::class, $exception);
30+
self::assertInstanceOf(\RuntimeException::class, $exception);
31+
self::assertSame('refresh token rejected', $exception->getMessage());
32+
}
33+
34+
public function testRequestExceptionExposesStatusAndBody(): void
35+
{
36+
$exception = new RequestException('Not Found', 404, '{"error":"missing"}');
37+
38+
self::assertInstanceOf(Bc4ApiException::class, $exception);
39+
self::assertSame('Not Found', $exception->getMessage());
40+
self::assertSame(404, $exception->getStatusCode());
41+
self::assertSame('{"error":"missing"}', $exception->getResponseBody());
42+
self::assertSame(0, $exception->getCode());
43+
}
44+
45+
public function testRequestExceptionResponseBodyDefaultsToEmpty(): void
46+
{
47+
self::assertSame('', (new RequestException('Server Error', 500))->getResponseBody());
48+
}
49+
50+
public function testRequestExceptionPreservesPreviousThrowable(): void
51+
{
52+
$previous = new \LogicException('root cause');
53+
$exception = new RequestException('Bad Gateway', 502, '', $previous);
54+
55+
self::assertSame($previous, $exception->getPrevious());
56+
}
57+
}

0 commit comments

Comments
 (0)