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:
@@ -334,7 +334,7 @@ final class MenuWriterTest extends TestCase
|
||||
} catch (WriteFailed $e) {
|
||||
self::assertTrue($e->rolledBack);
|
||||
self::assertStringContainsString('kaputt', $e->getMessage());
|
||||
self::assertSame('lit_write_failed', $e->toError()->get_error_code());
|
||||
self::assertToolError($e->toError(), 'write_failed');
|
||||
}
|
||||
|
||||
$restore = $calls[3];
|
||||
@@ -357,7 +357,7 @@ final class MenuWriterTest extends TestCase
|
||||
} catch (WriteFailed $e) {
|
||||
self::assertFalse($e->rolledBack);
|
||||
$error = $e->toError();
|
||||
self::assertSame('lit_partial_write', $error->get_error_code());
|
||||
self::assertToolError($error, 'partial_write');
|
||||
self::assertSame(3, $error->get_error_data()['menu_id']);
|
||||
self::assertSame('Home', $error->get_error_data()['previous_items'][0]['title']);
|
||||
self::assertStringContainsString('lit/menu-get', $error->get_error_data()['hint']);
|
||||
|
||||
Reference in New Issue
Block a user