test: AssertsToolErrors helper for tool error assertions (T3)

tests/Support/AssertsToolErrors (used by TestCase): assertToolError($result, code)
checks the WP_Error code lit_<code> and the code of the client JSON and returns the
payload; clientError() decodes the payload; errorFields() returns the fields and
asserts they exist. Replaces the private clientError() decoders of
DiviWriteAbilitiesTest/DiviReplaceTextAbilityTest, 216 single-line
assertSame('lit_…', …->get_error_code()) assertions, 24 get_error_data()['fields']
digs and two json_decode(message) reads. ErrorsTest keeps json_decode: it tests
the format itself. Tests 1404 -> 1409 (AssertsToolErrorsTest); no test has fewer
assertions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-26 17:55:35 +02:00
co-authored by Claude Opus 5.5
parent 72eeaa46ad
commit 60290c85a5
50 changed files with 337 additions and 256 deletions
@@ -54,9 +54,9 @@ final class DiviWriterTest extends TestCase
$writer = $this->writer(Mockery::mock(DiviSaver::class), FakeChangeLog::forbidden());
self::assertInstanceOf(DiviPage::class, $writer->page(['post_id' => 7, 'tree_rev' => Rev::of($content)]));
self::assertSame('lit_rev_mismatch', $writer->page(['post_id' => 7])->get_error_code());
self::assertToolError($writer->page(['post_id' => 7]), 'rev_mismatch');
$stale = $writer->page(['post_id' => 7, 'tree_rev' => Rev::ofPost(DiviFixtures::givenPost($content))]);
self::assertSame('lit_rev_mismatch', $stale->get_error_code(), 'the post rev is no tree_rev');
self::assertToolError($stale, 'rev_mismatch', 'the post rev is no tree_rev');
self::assertStringContainsString('nichts wurde', $stale->get_error_message());
}
@@ -72,7 +72,7 @@ final class DiviWriterTest extends TestCase
Mockery::mock(DiviComposition::class)
);
self::assertSame('lit_unsupported', $writer->page(['post_id' => 7, 'tree_rev' => Rev::of($content)])->get_error_code());
self::assertToolError($writer->page(['post_id' => 7, 'tree_rev' => Rev::of($content)]), 'unsupported');
}
public function testSectionLabelOfANode(): void