mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-09-26 04:02:51 +02:00
feat(modules): resolve module update sources + weekly update-check cron
ModuleUpdateChecker resolves the latest available version per module by source: git (via GitHubReleases), url (version.json), platform (best-effort), bundled (no-op). ModuleUpdatesCronJob (cron:module_updates) records available_version into config/modules.php; migration 008 registers it to run weekly. Network-free unit tests cover the routing.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use XcVm\Core\Module\ModuleUpdateChecker;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Network-free coverage of the source routing + guards. The actual git/url
|
||||
* fetches are integration concerns (they hit the network) and are not exercised
|
||||
* here — only the branches that resolve without any HTTP call.
|
||||
*/
|
||||
final class ModuleUpdateCheckerTest extends TestCase {
|
||||
|
||||
private ModuleUpdateChecker $checker;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->checker = new ModuleUpdateChecker();
|
||||
}
|
||||
|
||||
public function testBundledReturnsOnDiskVersion(): void {
|
||||
$result = $this->checker->latestAvailable([
|
||||
'update' => ['source' => 'bundled'],
|
||||
'version' => '1.2.0',
|
||||
'installed_version' => '1.0.0',
|
||||
]);
|
||||
$this->assertSame('1.2.0', $result);
|
||||
}
|
||||
|
||||
public function testAbsentUpdateBlockTreatedAsBundled(): void {
|
||||
$result = $this->checker->latestAvailable([
|
||||
'version' => '2.0.0',
|
||||
'installed_version' => '1.0.0',
|
||||
]);
|
||||
$this->assertSame('2.0.0', $result);
|
||||
}
|
||||
|
||||
public function testUrlSourceRejectsNonHttps(): void {
|
||||
$result = $this->checker->latestAvailable([
|
||||
'update' => ['source' => 'url', 'url' => 'http://example.com/version.json'],
|
||||
'installed_version' => '1.0.0',
|
||||
]);
|
||||
$this->assertNull($result); // https-only guard, no network
|
||||
}
|
||||
|
||||
public function testGitSourceWithInvalidRepoReturnsNull(): void {
|
||||
$result = $this->checker->latestAvailable([
|
||||
'update' => ['source' => 'git', 'repository' => 'not-a-github-url'],
|
||||
'installed_version' => '1.0.0',
|
||||
]);
|
||||
$this->assertNull($result); // regex fails before any network call
|
||||
}
|
||||
|
||||
public function testPlatformWithoutExtensionReturnsNull(): void {
|
||||
// The xcvm_core extension is not loaded in the test runtime, so the
|
||||
// platform branch short-circuits to null.
|
||||
$result = $this->checker->latestAvailable([
|
||||
'update' => ['source' => 'platform', 'slug' => 'watch'],
|
||||
'installed_version' => '1.0.0',
|
||||
]);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user