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>
125 lines
4.7 KiB
PHP
125 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Release;
|
|
|
|
use LIT\MCP\Compatibility\CheckStep;
|
|
use LIT\MCP\Integrations\Divi\Release\DiviCheckSteps;
|
|
use LIT\MCP\Compatibility\CompatibilityCheck;
|
|
use LIT\MCP\Compatibility\ManifestCheck;
|
|
use LIT\MCP\Compatibility\Manifest;
|
|
use LIT\MCP\Compatibility\Mirror;
|
|
use LIT\MCP\Compatibility\Profile;
|
|
use LIT\MCP\Compatibility\Tier;
|
|
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
|
use LIT\MCP\Integrations\Divi\Release\FormatCheck;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Brain\Monkey\Functions;
|
|
use Closure;
|
|
use Mockery;
|
|
use RuntimeException;
|
|
|
|
final class DiviCheckStepsTest extends TestCase
|
|
{
|
|
public function testAStepCarriesItsLabel(): void
|
|
{
|
|
$step = DiviCheckSteps::step(DiviCheckSteps::CATALOG, ['x']);
|
|
|
|
self::assertSame('catalog', $step->key);
|
|
self::assertSame(['x'], $step->problems);
|
|
self::assertSame('Modulkatalog (Kurzform-Pfade)', $step->label());
|
|
self::assertTrue(DiviCheckSteps::step(DiviCheckSteps::WRITE, [], true)->skipped);
|
|
}
|
|
|
|
public function testTheLabelOfAnOldReportStepComesFromTheKey(): void
|
|
{
|
|
self::assertSame(
|
|
'Schreibtest auf einer Wegwerfseite',
|
|
DiviCheckSteps::label(new CheckStep(DiviCheckSteps::WRITE, []))
|
|
);
|
|
self::assertSame(
|
|
'Divi-Funktionen, Klassen und Registrierungen',
|
|
DiviCheckSteps::label(new CheckStep(CheckStep::MANIFEST, []))
|
|
);
|
|
self::assertSame('stored', DiviCheckSteps::label(new CheckStep('catalog', [], false, 'stored')));
|
|
self::assertSame('other', DiviCheckSteps::label(new CheckStep('other', [])));
|
|
}
|
|
|
|
/** @param array<string, Closure(): bool> $code */
|
|
private function check(array $code, array $mirrors, ?Closure $probe = null, ?Closure $catalog = null): CompatibilityCheck
|
|
{
|
|
Functions\when('wp_generate_uuid4')->justReturn('uuid-1');
|
|
$manifests = Mockery::mock(ManifestCheck::class);
|
|
$manifests->allows('codeChecks')->andReturn($code);
|
|
$manifests->allows('registrationChecks')->andReturn([]);
|
|
$manifests->allows('mirrorChecks')->andReturn($mirrors);
|
|
$format = Mockery::mock(FormatCheck::class);
|
|
$format->allows('problems')->andReturn([]);
|
|
$profile = new Profile(
|
|
id: 'divi',
|
|
label: 'Divi',
|
|
tier: Tier::ReleasePerVersion,
|
|
capabilities: DiviFeature::cases(),
|
|
manifests: [new Manifest('Seiten', mirrors: [new Mirror('m', 'f.php', 'fn', null, 'x')])],
|
|
version: static fn (): ?string => '5.3.0',
|
|
matrix: static fn () => throw new RuntimeException('unused'),
|
|
stateKey: static fn (string $version): string => 'key-' . $version,
|
|
extraSteps: DiviCheckSteps::extra(
|
|
$catalog ?? static fn (): array => [],
|
|
$format,
|
|
$probe ?? static fn (): array => []
|
|
)
|
|
);
|
|
|
|
return new CompatibilityCheck($profile, $manifests);
|
|
}
|
|
|
|
public function testTheDiviStepOrderIsUnchanged(): void
|
|
{
|
|
$report = $this->check([], [])->run(7);
|
|
|
|
self::assertTrue($report->green());
|
|
self::assertSame(
|
|
['manifest', 'mirrors', 'catalog', 'format', 'write'],
|
|
array_map(static fn (CheckStep $step): string => $step->key, $report->steps)
|
|
);
|
|
self::assertSame('Schreibtest auf einer Wegwerfseite', $report->step('write')?->label());
|
|
self::assertSame('Divi-Funktionen, Klassen und Registrierungen', $report->step('manifest')?->label());
|
|
self::assertSame('key-5.3.0', $report->stateKey);
|
|
}
|
|
|
|
public function testNoWriteTestWhenDiviFunctionsAreMissing(): void
|
|
{
|
|
$ran = false;
|
|
$probe = static function () use (&$ran): array {
|
|
$ran = true;
|
|
|
|
return [];
|
|
};
|
|
|
|
$report = $this->check(['Seiten: et_x()' => static fn (): bool => false], [], $probe)->run(7);
|
|
|
|
self::assertSame(['Seiten: et_x()'], $report->step(CheckStep::MANIFEST)?->problems);
|
|
self::assertTrue($report->step(DiviCheckSteps::WRITE)?->skipped);
|
|
self::assertFalse($ran);
|
|
}
|
|
|
|
public function testChangedFingerprintsStillRunTheWriteTest(): void
|
|
{
|
|
$report = $this->check([], ['TB: Nachbau von y()' => static fn (): bool => false])->run(7);
|
|
|
|
self::assertFalse($report->green());
|
|
self::assertTrue($report->step(DiviCheckSteps::WRITE)?->green());
|
|
}
|
|
|
|
public function testAThrowingStepIsARedStep(): void
|
|
{
|
|
$report = $this->check([], [], null, static function (): never {
|
|
throw new RuntimeException('Katalog weg');
|
|
})->run(7);
|
|
|
|
self::assertSame(['Prüfschritt abgebrochen (Details im PHP-Error-Log).'], $report->step(DiviCheckSteps::CATALOG)?->problems);
|
|
}
|
|
}
|