Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<file>tests/HmacSessionStrategyTest.php</file>
<file>tests/ModelTest.php</file>
<file>tests/SignatureTest.php</file>
<file>tests/VersionTest.php</file>
</testsuite>
<testsuite name="aws">
<file>tests/AwsAcmTest.php</file>
Expand Down
35 changes: 30 additions & 5 deletions src/Core/Version.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
<?php
namespace Kyte\Core;

/**
* Reports the running kyte-php version.
*
* Reads Composer's runtime installed-package data via Composer\InstalledVersions
* (Composer 2.x API). Returns the pretty version string composer resolved:
*
* - Tagged install: "v4.3.2"
* - Branch install: "dev-master" / "dev-feature/phase-2-mcp-tokens"
* - Dev tree (no composer registration): "unknown"
*
* Replaces the old hardcoded MAJOR/MINOR/PATCH constants, which went stale
* (v4.1.1 was reported on v4.3.x installs because nobody bumped the consts).
*/
class Version
{
const MAJOR=4;
const MINOR=1;
const PATCH=1;
private const FALLBACK = 'unknown';
private const PACKAGE = 'keyqcloud/kyte-php';

public static function get()
public static function get(): string
{
return sprintf('v%s.%s.%s', self::MAJOR, self::MINOR, self::PATCH);
if (!class_exists(\Composer\InstalledVersions::class)) {
return self::FALLBACK;
}

try {
$version = \Composer\InstalledVersions::getPrettyVersion(self::PACKAGE);
} catch (\OutOfBoundsException $e) {
// Package not registered in Composer's runtime data — happens
// when running a dev tree that hasn't been composer-installed
// (e.g. directly from a git clone).
return self::FALLBACK;
}

return $version ?? self::FALLBACK;
}
}
38 changes: 38 additions & 0 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace Kyte\Test;

use PHPUnit\Framework\TestCase;

/**
* Characterization tests for Kyte\Core\Version::get().
*
* The previous implementation hardcoded MAJOR/MINOR/PATCH constants that
* were never bumped — every install reported v4.1.1 regardless of what
* composer actually pulled. v4.3.2 replaced that with a Composer\InstalledVersions
* lookup; these tests pin the new contract.
*/
class VersionTest extends TestCase
{
public function testGetReturnsNonEmptyString(): void
{
$version = \Kyte\Core\Version::get();
$this->assertIsString($version);
$this->assertNotSame('', $version);
}

public function testGetReturnsComposerInstalledVersion(): void
{
// Composer's runtime data is always present in a composer-installed
// tree (which the test suite is). Confirm we surface its pretty
// version, not the FALLBACK.
$expected = \Composer\InstalledVersions::getPrettyVersion('keyqcloud/kyte-php');
$this->assertSame($expected, \Kyte\Core\Version::get());
}

public function testGetDoesNotReturnHardcodedLegacyString(): void
{
// Guard against a regression where someone reintroduces the
// pre-v4.3.2 hardcoded "v4.1.1" string.
$this->assertNotSame('v4.1.1', \Kyte\Core\Version::get());
}
}
Loading