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()); + } +}