From 605e7668f66438906713fce55500c387334e670b Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 1 Jul 2026 00:02:35 +0200 Subject: [PATCH] test(api): assert /version sources from ApplicationInfo, not removed constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ApiV1Test::testVersionConstantExists` / `testReleaseDateConstantExists` asserted that `ApiV1::VERSION` / `ApiV1::RELEASE_DATE` still exist. Those local constants were removed when the `/version` endpoint was switched to source from `ApplicationInfo` (the single source of truth, commit 48d418dc1) — the hardcoded `VERSION = "3.0.2"` had silently misreported the API version through 3.1.x and 3.2.0. The tests skip in unit CI (no MySQL → `ApiV1Test::setUp()` skips the whole class), so they stayed green on CI and never blocked a release — but they fail in any run with a test database present (local / integration). Rewrite them to assert the real contract: ApiV1 no longer carries a drift-prone version constant, and the values the endpoint serves come from `ApplicationInfo` in the API's promised shape (bare semver `X.Y.Z` / ISO date). Gates: phpcs PSR12 (0), psalm --threads=1 (0), full phpunit — 0 failures (previously 2 with a DB present). --- tests/backend/Api/V1/ApiV1Test.php | 36 +++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/backend/Api/V1/ApiV1Test.php b/tests/backend/Api/V1/ApiV1Test.php index cc8272967..6980c34c7 100644 --- a/tests/backend/Api/V1/ApiV1Test.php +++ b/tests/backend/Api/V1/ApiV1Test.php @@ -5,6 +5,7 @@ namespace Lwt\Tests\Api\V1; use Lwt\Api\V1\ApiV1; +use Lwt\Shared\Infrastructure\ApplicationInfo; use Lwt\Shared\Infrastructure\Globals; use Lwt\Shared\Infrastructure\Container\Container; use Lwt\Shared\Infrastructure\Container\CoreServiceProvider; @@ -137,21 +138,44 @@ public function testConstructorAcceptsContainer(): void } /** - * Test VERSION constant exists. + * The `version` endpoint must source its version from ApplicationInfo + * (the single source of truth), not a local constant that drifts. + * + * Regression guard: ApiV1 used to carry a hardcoded `VERSION = "3.0.2"` + * that was never bumped, so the API misreported the version through 3.1.x + * and 3.2.0. It now reads from ApplicationInfo and strips the `-fork` + * suffix to serve bare semver to clients. */ - public function testVersionConstantExists(): void + public function testVersionSourcedFromApplicationInfo(): void { + // ApiV1 must not reintroduce its own version constant. $reflection = new \ReflectionClass(ApiV1::class); - $this->assertTrue($reflection->hasConstant('VERSION')); + $this->assertFalse( + $reflection->hasConstant('VERSION'), + 'ApiV1 should source its version from ApplicationInfo, not a local constant' + ); + + // The value the endpoint serves is bare semver (X.Y.Z, no "-fork"). + $apiVersion = \explode('-', ApplicationInfo::getRawVersion())[0]; + $this->assertMatchesRegularExpression('/^\d+\.\d+\.\d+$/', $apiVersion); } /** - * Test RELEASE_DATE constant exists. + * The `version` endpoint must source its release date from ApplicationInfo, + * not a local constant. */ - public function testReleaseDateConstantExists(): void + public function testReleaseDateSourcedFromApplicationInfo(): void { $reflection = new \ReflectionClass(ApiV1::class); - $this->assertTrue($reflection->hasConstant('RELEASE_DATE')); + $this->assertFalse( + $reflection->hasConstant('RELEASE_DATE'), + 'ApiV1 should source its release date from ApplicationInfo, not a local constant' + ); + + $this->assertMatchesRegularExpression( + '/^\d{4}-\d{2}-\d{2}$/', + ApplicationInfo::getReleaseDate() + ); } /**