From 30e123540f0685fe5dd14073131d92c49fb0b90b Mon Sep 17 00:00:00 2001 From: edwh Date: Wed, 23 Sep 2026 07:32:35 +0100 Subject: [PATCH] Stop StubGeocoderTest failing on forked PRs CI writes GEOCODER_STUB=true into .env when it has no geocoding key, which is every forked PR. The test asserted the live config was false, so it failed on exactly the runs the stub exists for (#906 build 5844). Check the config file's default with the variable cleared instead, and add the converse so the default check can't pass vacuously. Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/Unit/StubGeocoderTest.php | 43 ++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/Unit/StubGeocoderTest.php b/tests/Unit/StubGeocoderTest.php index b50acaf4b..611c5fe50 100644 --- a/tests/Unit/StubGeocoderTest.php +++ b/tests/Unit/StubGeocoderTest.php @@ -11,10 +11,51 @@ class StubGeocoderTest extends TestCase * GEOCODER_STUB is deliberately set, which only CI does and only when it * has no key. (The container binding itself can't be asserted here - * TestCase binds a GeocoderMock for every test.) + * + * This reads the config file's default with GEOCODER_STUB unset rather + * than the live config, because CI sets it on the key-less runs forked + * PRs get - and this test runs there too. */ public function testStubIsOffUnlessDeliberatelyEnabled(): void { - self::assertFalse((bool) config('restarters.geocoder_stub')); + $saved = [getenv('GEOCODER_STUB'), $_ENV['GEOCODER_STUB'] ?? null, $_SERVER['GEOCODER_STUB'] ?? null]; + putenv('GEOCODER_STUB'); + unset($_ENV['GEOCODER_STUB'], $_SERVER['GEOCODER_STUB']); + + try { + $config = require config_path('restarters.php'); + self::assertFalse((bool) $config['geocoder_stub']); + } finally { + if ($saved[0] !== false) { + putenv('GEOCODER_STUB=' . $saved[0]); + } + if ($saved[1] !== null) { + $_ENV['GEOCODER_STUB'] = $saved[1]; + } + if ($saved[2] !== null) { + $_SERVER['GEOCODER_STUB'] = $saved[2]; + } + } + } + + /** + * And the switch does turn it on - otherwise the test above proves nothing. + */ + public function testStubCanBeEnabled(): void + { + $saved = $_SERVER['GEOCODER_STUB'] ?? null; + $_SERVER['GEOCODER_STUB'] = 'true'; + + try { + $config = require config_path('restarters.php'); + self::assertTrue((bool) $config['geocoder_stub']); + } finally { + if ($saved === null) { + unset($_SERVER['GEOCODER_STUB']); + } else { + $_SERVER['GEOCODER_STUB'] = $saved; + } + } } public function testStubStillSatisfiesTheGeocoderContract(): void