- WriteFailed::rolledBack()/partial() replace the 11-parameter constructor (now private); the hint/state of either error are plain $hint/$state. - Rollback::attempt(...steps) runs every undo step and collects failure messages; used by ContentCreate::discard, ContentUpdate::rollBack, MediaUpdate::rollBack and DiviSaver::restore. - Errors::clientMessage/codeOf/fieldsOf replace DiviReplaceTextAbility::reason, the JSON digging in MediaUpdateAbility::failure and ContentCreateAbility::fields. - Errors docblock documents the exception/WP_Error split. - ContentCreateAbility::discard takes the client reason as a parameter (both callers still pass REASON_EXTRAS; changing the Divi text needs a ruling). Error payloads unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Abilities;
|
|
|
|
use LIT\MCP\Abilities\Rollback;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use RuntimeException;
|
|
|
|
final class RollbackTest extends TestCase
|
|
{
|
|
public function testAllStepsRunInOrderAndNothingFailed(): void
|
|
{
|
|
$ran = [];
|
|
|
|
$failures = Rollback::attempt(
|
|
static function () use (&$ran): void {
|
|
$ran[] = 1;
|
|
},
|
|
static function () use (&$ran): void {
|
|
$ran[] = 2;
|
|
}
|
|
);
|
|
|
|
self::assertSame([], $failures);
|
|
self::assertSame([1, 2], $ran);
|
|
}
|
|
|
|
public function testAFailingStepDoesNotStopTheOthersAndItsMessageIsCollected(): void
|
|
{
|
|
$ran = [];
|
|
|
|
$failures = Rollback::attempt(
|
|
static function (): void {
|
|
throw new RuntimeException('Begriffe nicht gelöscht');
|
|
},
|
|
static function () use (&$ran): void {
|
|
$ran[] = 2;
|
|
},
|
|
static function (): void {
|
|
throw new \Error('Zeile nicht zurückgesetzt');
|
|
}
|
|
);
|
|
|
|
self::assertSame(['Begriffe nicht gelöscht', 'Zeile nicht zurückgesetzt'], $failures);
|
|
self::assertSame([2], $ran);
|
|
}
|
|
|
|
public function testAReturnValueIsNoFailure(): void
|
|
{
|
|
self::assertSame([], Rollback::attempt(static fn (): string => 'egal', static fn (): bool => false));
|
|
}
|
|
}
|