Files
WP-LIT-MCP/tests/Unit/Compatibility/CompatibilityComponentTest.php
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

116 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Compatibility;
use Closure;
use LIT\MCP\Compatibility\Call;
use LIT\MCP\Compatibility\Compatibility;
use LIT\MCP\Compatibility\CompatibilityComponent;
use LIT\MCP\Compatibility\CompatibilityMatrix;
use LIT\MCP\Compatibility\Manifest;
use LIT\MCP\Compatibility\Profile;
use LIT\MCP\Compatibility\Tier;
use LIT\MCP\Integrations\Core\EnvironmentComponent;
use LIT\MCP\Tests\Support\FakeCapability;
use LIT\MCP\Tests\Unit\TestCase;
use LogicException;
final class CompatibilityComponentTest extends TestCase
{
private function profile(bool $active, bool $broken = false): Profile
{
return new Profile(
id: 'fake',
label: 'Fake Plugin',
tier: Tier::LockOnFailure,
capabilities: [FakeCapability::Read, FakeCapability::Write],
manifests: [new Manifest(
'Fake',
calls: $broken ? [new Call('lit_mcp_missing_function', 0, [FakeCapability::Write])] : []
)],
active: static fn (): bool => $active,
version: static fn (): string => '4.2.0'
);
}
private function component(Profile $profile): EnvironmentComponent
{
return new CompatibilityComponent($profile, static fn (): Compatibility => new Compatibility([$profile]));
}
public function testAnInactivePluginIsReportedAsNotInstalledWithoutProblems(): void
{
self::assertSame(
['id' => 'fake', 'active' => false, 'version' => null, 'problems' => [], 'release' => null],
$this->component($this->profile(false))->describe()
);
}
public function testAnActiveWorkingPluginHasItsVersionAndNoProblems(): void
{
self::assertSame(
['id' => 'fake', 'active' => true, 'version' => '4.2.0', 'problems' => [], 'release' => null],
$this->component($this->profile(true))->describe()
);
}
public function testAnActiveButBrokenPluginListsItsProblems(): void
{
$described = $this->component($this->profile(true, broken: true))->describe();
self::assertTrue($described['active']);
self::assertSame('4.2.0', $described['version']);
self::assertNotSame([], $described['problems']);
self::assertContainsOnly('string', $described['problems']);
self::assertNull($described['release']);
}
public function testTheCompatibilityIsAskedOnlyWhenDescribing(): void
{
$asked = 0;
$profile = $this->profile(true);
$component = new CompatibilityComponent($profile, static function () use (&$asked, $profile): Compatibility {
$asked++;
return new Compatibility([$profile]);
});
self::assertSame(0, $asked);
$component->describe();
self::assertSame(1, $asked);
}
public function testAReleasePerVersionProfileHasItsOwnComponent(): void
{
$profile = new Profile(
id: 'rel',
label: 'Rel',
tier: Tier::ReleasePerVersion,
capabilities: [FakeCapability::Other],
matrix: static fn (): CompatibilityMatrix => CompatibilityMatrix::allReleased([FakeCapability::Other])
);
$this->expectException(LogicException::class);
new CompatibilityComponent($profile, static fn (): Compatibility => new Compatibility([$profile]));
}
public function testForProfilesBuildsAComponentPerProfileWithoutReleasePerVersion(): void
{
$plain = $this->profile(true);
$release = new Profile(
id: 'rel',
label: 'Rel',
tier: Tier::ReleasePerVersion,
capabilities: [FakeCapability::Other],
matrix: static fn (): CompatibilityMatrix => CompatibilityMatrix::allReleased([FakeCapability::Other])
);
$components = CompatibilityComponent::forProfiles(new Compatibility([$release, $plain]));
self::assertSame(['fake'], array_map(static fn (CompatibilityComponent $c): string => $c->describe()['id'], $components));
}
}