Files
WP-LIT-MCP/tests/Unit/Compatibility/ReleaseStoreTest.php
T
Jan-Niclas LoosenandClaude Opus 5.5 7d6a97a54e refactor(compat): Freigabe-Bausteine generisch
ReleaseStore, CheckReportStore, CheckReport, CheckStep und CompatibilityCheck liegen im Kern und arbeiten je Profil (Optionen lit_mcp_<id>_releases|_check_report; Divi behält Namen und Schlüssel divi_version). Divi hängt Katalog-, Format- und Schreibtest über Profile::extraSteps an. Ein roter Prüfbericht für den aktuellen Stand sperrt LockOnFailure-Profile bis zur nächsten grünen Prüfung; Sperrgründe nennen nur Schritt-Labels, Ausnahmen gehen ins Error-Log. Profile bekommt testedVersions, stateKey, extraSteps, manifestCheck und reportVersionKey und wird mit benannten Argumenten gebaut.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 12:51:03 +01:00

90 lines
3.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Compatibility;
use Brain\Monkey\Functions;
use LIT\MCP\Compatibility\ReleaseStore;
use LIT\MCP\Tests\Unit\TestCase;
final class ReleaseStoreTest extends TestCase
{
/** @var array<string, mixed> */
private array $options = [];
protected function setUp(): void
{
parent::setUp();
$this->options = [];
Functions\when('get_option')->alias(
fn (string $name, mixed $default = false): mixed => $this->options[$name] ?? $default
);
Functions\when('update_option')->alias(function (string $name, mixed $value, mixed $autoload = null): bool {
$this->options[$name] = $value;
self::assertFalse($autoload, 'releases are read only by the gate – no autoload');
return true;
});
}
public function testAddsFindsAndWithdrawsPerVersionAndPluginVersion(): void
{
$store = new ReleaseStore('divi', 'divi_version');
$store->add('5.3.0', '0.6.0', 1, 'r1');
$store->add('5.3.0', '0.6.0', 2, 'r2');
self::assertCount(1, $store->entries(), 'one entry per version pair');
self::assertSame(2, $store->find('5.3.0', '0.6.0')['user_id'] ?? null);
self::assertNull($store->find('5.3.0', '0.7.0'), 'another plugin version needs its own check');
self::assertTrue($store->withdraw('5.3.0', '0.6.0'));
self::assertFalse($store->withdraw('5.3.0', '0.6.0'));
self::assertSame([], $store->entries());
}
public function testDiviKeepsOptionAndFormat(): void
{
$this->options['lit_mcp_divi_releases'] = [[
'divi_version' => '5.2.2', 'plugin_version' => '0.6.0', 'user_id' => 3,
'released_at' => '2026-10-01T08:00:00+00:00', 'report_id' => 'r',
]];
$store = new ReleaseStore('divi', 'divi_version');
self::assertSame('r', $store->find('5.2.2', '0.6.0')['report_id'] ?? null);
$store->add('5.3.0', '0.6.0', 1, 'r1');
$written = $this->options['lit_mcp_divi_releases'];
self::assertSame(['lit_mcp_divi_releases'], array_keys($this->options));
self::assertSame(
['divi_version', 'plugin_version', 'user_id', 'released_at', 'report_id'],
array_keys($written[1])
);
self::assertSame($this->options['lit_mcp_divi_releases'][0], [
'divi_version' => '5.2.2', 'plugin_version' => '0.6.0', 'user_id' => 3,
'released_at' => '2026-10-01T08:00:00+00:00', 'report_id' => 'r',
]);
}
public function testAnotherProfileGetsItsOwnOptionAndTheVersionKey(): void
{
$store = new ReleaseStore('pods');
$store->add('3.3.9.2', '0.6.0', 1, 'r1');
self::assertSame(['lit_mcp_pods_releases'], array_keys($this->options));
self::assertSame('3.3.9.2', $this->options['lit_mcp_pods_releases'][0]['version']);
self::assertSame('r1', $store->find('3.3.9.2', '0.6.0')['report_id'] ?? null);
self::assertSame([], (new ReleaseStore('divi', 'divi_version'))->entries());
}
public function testIgnoresBrokenRows(): void
{
$this->options['lit_mcp_divi_releases'] = ['x', ['divi_version' => '5.3.0'], [
'divi_version' => '5.2.2', 'plugin_version' => '0.6.0', 'user_id' => 3,
'released_at' => 'd', 'report_id' => 'r',
]];
self::assertSame(['5.2.2'], array_column((new ReleaseStore('divi', 'divi_version'))->entries(), 'divi_version'));
self::assertSame([], (new ReleaseStore('divi'))->entries(), 'rows hold divi_version, not version');
}
}