From 75faf3e0af1799439f902d63ca34e182139b9bf0 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Mon, 20 Apr 2026 17:44:01 +0200 Subject: [PATCH] test: make testLoadFeatureFlagsWrongKey deterministic Previously relied on a live HTTPS request with a fake personal API key and expected the real server to return a response that triggered an exception. That is flaky: network reachability and server behavior vary across CI runs. Mock the local_evaluation endpoint to return a payload with a "detail" key so loadFlags() always throws. Co-Authored-By: Claude Opus 4.7 (1M context) --- test/FeatureFlagLocalEvaluationTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/FeatureFlagLocalEvaluationTest.php b/test/FeatureFlagLocalEvaluationTest.php index 0a48f40..66580fc 100644 --- a/test/FeatureFlagLocalEvaluationTest.php +++ b/test/FeatureFlagLocalEvaluationTest.php @@ -1326,12 +1326,16 @@ public function testLoadFeatureFlags() public function testLoadFeatureFlagsWrongKey() { self::expectException(Exception::class); + $this->http_client = new MockedHttpClient( + host: "app.posthog.com", + flagEndpointResponse: ["detail" => "Invalid personal API key."] + ); $this->client = new Client( self::FAKE_API_KEY, [ "debug" => true, ], - null, + $this->http_client, self::FAKE_API_KEY ); PostHog::init(null, null, $this->client);