From 25801c918a21e305ce95982e843b889996777e71 Mon Sep 17 00:00:00 2001 From: Tycho Engberink Date: Thu, 22 Jan 2026 13:37:23 +0100 Subject: [PATCH 1/2] feat: add Health resource with check method - Add Health resource class with check() method for /api/public/health endpoint - Add HealthResponse DTO for health status response - Add test fixture and feature test --- src/Health.php | 29 ++++++++++++++++++++ src/Langfuse.php | 8 +++++- src/Responses/HealthResponse.php | 22 +++++++++++++++ src/Testing/Responses/GetHealthResponse.php | 30 +++++++++++++++++++++ tests/Feature/HealthTest.php | 24 +++++++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/Health.php create mode 100644 src/Responses/HealthResponse.php create mode 100644 src/Testing/Responses/GetHealthResponse.php create mode 100644 tests/Feature/HealthTest.php diff --git a/src/Health.php b/src/Health.php new file mode 100644 index 0000000..e396eeb --- /dev/null +++ b/src/Health.php @@ -0,0 +1,29 @@ +transporter->get( + uri: '/api/public/health', + ); + + /** @var array{status: string} $data */ + $data = json_decode($response->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR); + + return HealthResponse::fromArray($data); + } +} diff --git a/src/Langfuse.php b/src/Langfuse.php index ebe96f9..dded845 100644 --- a/src/Langfuse.php +++ b/src/Langfuse.php @@ -12,7 +12,13 @@ public function __construct( private readonly TransporterInterface $transporter, private readonly string $environment = 'default', private readonly string $label = 'latest', - ) { + ) {} + + public function health(): Health + { + return new Health( + transporter: $this->transporter, + ); } public function prompt(): Prompt diff --git a/src/Responses/HealthResponse.php b/src/Responses/HealthResponse.php new file mode 100644 index 0000000..713d4c5 --- /dev/null +++ b/src/Responses/HealthResponse.php @@ -0,0 +1,22 @@ +|string> $headers + * @param array $data + */ + public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) + { + parent::__construct($status, $headers, (string) json_encode($this->payload($data)), $version, $reason); + } + + /** + * @param array $data + * @return array + */ + public function payload(array $data = []): array + { + return array_merge([ + 'status' => 'OK', + ], $data); + } +} diff --git a/tests/Feature/HealthTest.php b/tests/Feature/HealthTest.php new file mode 100644 index 0000000..8c0aae8 --- /dev/null +++ b/tests/Feature/HealthTest.php @@ -0,0 +1,24 @@ + $handlerStack]); + + $health = (new Langfuse(new HttpTransporter($client))) + ->health() + ->check(); + + expect($health)->toBeInstanceOf(HealthResponse::class) + ->and($health->status)->toBe('OK'); +}); From 1e21f818098f6aa734c85ce16ed4be5cf01f1699 Mon Sep 17 00:00:00 2001 From: Tycho Engberink Date: Fri, 20 Feb 2026 13:37:19 +0100 Subject: [PATCH 2/2] chore: remove test:refactor dry-run --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9651b02..98892f9 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "test:lint": "@php vendor/bin/pint --config https://raw.githubusercontent.com/DIJ-digital/pint-config/main/pint.json", "test:unit": "pest", "test:types": "phpstan", - "test:refactor": "rector --dry-run", + "test:refactor": "rector", "test": [ "@test:lint", "@test:type-coverage",