refactor: WriteFailed named constructors, Rollback runner, Errors read-back helpers (H6)
- 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>
This commit is contained in:
@@ -114,4 +114,24 @@ final class ErrorsTest extends TestCase
|
||||
self::assertStringContainsString('Entwurf', $payload['message']);
|
||||
self::assertArrayNotHasKey('post_id', $payload);
|
||||
}
|
||||
|
||||
public function testClientMessageReadsTheJsonMessageBack(): void
|
||||
{
|
||||
self::assertSame('Titel fehlt.', Errors::clientMessage(Errors::invalidInput('Titel fehlt.')));
|
||||
self::assertSame('WordPress sagt nein', Errors::clientMessage(new \WP_Error('db', 'WordPress sagt nein')));
|
||||
self::assertSame('{"code":"x"}', Errors::clientMessage(new \WP_Error('db', '{"code":"x"}')));
|
||||
}
|
||||
|
||||
public function testCodeOfDropsTheLitPrefixOnly(): void
|
||||
{
|
||||
self::assertSame('validation_failed', Errors::codeOf(Errors::invalidInput('x')));
|
||||
self::assertSame('db_error', Errors::codeOf(new \WP_Error('db_error', 'x')));
|
||||
}
|
||||
|
||||
public function testFieldsOfReturnsTheFieldsOrNothing(): void
|
||||
{
|
||||
self::assertSame(['title' => 'Pflichtfeld'], Errors::fieldsOf(Errors::invalidInput('x', ['title' => 'Pflichtfeld'])));
|
||||
self::assertSame([], Errors::fieldsOf(Errors::invalidInput('x')));
|
||||
self::assertSame([], Errors::fieldsOf(new \WP_Error('db', 'x', 'kein Array')));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user