From 8fd49a5b4ba61364ac62a4c2bbf79c2f5827acd3 Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Sun, 14 Jun 2026 02:44:23 +0200 Subject: [PATCH] :white_check_mark: test: Exception-Hierarchie-Tests + CLI-Compose-Runner + GitHub-Action [*] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ExceptionTest für Bc4ApiException/RequestException/InvalidGrantException ergänzt; CLI-only docker-compose-Runner und GitHub-Actions-Workflow hinzugefügt. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/tests.yml | 24 +++++++++++++ docker-compose.yml | 15 ++++++++ tests/Exception/ExceptionTest.php | 57 +++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 docker-compose.yml create mode 100644 tests/Exception/ExceptionTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..4fecb4b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,24 @@ +# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC +name: Tests + +on: + push: + branches: [main, master, "feature/**"] + pull_request: + +jobs: + phpunit: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ["8.4"] + name: PHPUnit (PHP ${{ matrix.php }}) + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + - run: composer install --no-interaction --no-progress + - run: vendor/bin/phpunit diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..118bccb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC +# CLI-only test runner for this library — no MySQL/FPM required. +# Usage (on host): +# docker compose run --rm php +# Runs `composer install` then PHPUnit against tests/. +services: + php: + build: + dockerfile_inline: | + FROM php:8.4-cli-alpine + COPY --from=composer:2 /usr/bin/composer /usr/bin/composer + working_dir: /repo + volumes: + - .:/repo + command: sh -c "composer install --no-interaction --no-progress && vendor/bin/phpunit" diff --git a/tests/Exception/ExceptionTest.php b/tests/Exception/ExceptionTest.php new file mode 100644 index 0000000..4387538 --- /dev/null +++ b/tests/Exception/ExceptionTest.php @@ -0,0 +1,57 @@ +getMessage()); + } + + public function testRequestExceptionExposesStatusAndBody(): void + { + $exception = new RequestException('Not Found', 404, '{"error":"missing"}'); + + self::assertInstanceOf(Bc4ApiException::class, $exception); + self::assertSame('Not Found', $exception->getMessage()); + self::assertSame(404, $exception->getStatusCode()); + self::assertSame('{"error":"missing"}', $exception->getResponseBody()); + self::assertSame(0, $exception->getCode()); + } + + public function testRequestExceptionResponseBodyDefaultsToEmpty(): void + { + self::assertSame('', (new RequestException('Server Error', 500))->getResponseBody()); + } + + public function testRequestExceptionPreservesPreviousThrowable(): void + { + $previous = new \LogicException('root cause'); + $exception = new RequestException('Bad Gateway', 502, '', $previous); + + self::assertSame($previous, $exception->getPrevious()); + } +}