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:
@@ -96,7 +96,7 @@ final class AbilityRegistrarTest extends TestCase
|
||||
$result = ($this->registrarFor($ability)->argsFor($ability)['permission_callback'])([]);
|
||||
|
||||
self::assertInstanceOf(WP_Error::class, $result);
|
||||
self::assertSame('lit_forbidden', $result->get_error_code());
|
||||
self::assertToolError($result, 'forbidden');
|
||||
}
|
||||
|
||||
public function testPermissionDeniedOutsideOAuthServerRequest(): void
|
||||
@@ -109,7 +109,7 @@ final class AbilityRegistrarTest extends TestCase
|
||||
$result = ($this->registrarFor($ability)->argsFor($ability)['permission_callback'])([]);
|
||||
|
||||
self::assertInstanceOf(WP_Error::class, $result);
|
||||
self::assertSame('lit_forbidden', $result->get_error_code());
|
||||
self::assertToolError($result, 'forbidden');
|
||||
}
|
||||
|
||||
public function testPermissionDelegatesToAbilityWhenGatePasses(): void
|
||||
@@ -149,7 +149,7 @@ final class AbilityRegistrarTest extends TestCase
|
||||
}
|
||||
|
||||
self::assertInstanceOf(WP_Error::class, $result);
|
||||
self::assertSame('lit_internal_error', $result->get_error_code());
|
||||
self::assertToolError($result, 'internal_error');
|
||||
self::assertStringNotContainsString('/var/www', $result->get_error_message());
|
||||
self::assertStringContainsString('lit/test failed', (string) file_get_contents($log));
|
||||
unlink($log);
|
||||
@@ -170,7 +170,7 @@ final class AbilityRegistrarTest extends TestCase
|
||||
}
|
||||
|
||||
self::assertInstanceOf(WP_Error::class, $result);
|
||||
self::assertSame('lit_internal_error', $result->get_error_code());
|
||||
self::assertToolError($result, 'internal_error');
|
||||
self::assertStringNotContainsString('/var/www', $result->get_error_message());
|
||||
self::assertStringContainsString('lit/test failed', (string) file_get_contents($log));
|
||||
unlink($log);
|
||||
@@ -196,7 +196,7 @@ final class AbilityRegistrarTest extends TestCase
|
||||
ini_set('error_log', (string) $previous);
|
||||
}
|
||||
|
||||
self::assertSame('lit_partial_write', $result->get_error_code());
|
||||
self::assertToolError($result, 'partial_write');
|
||||
self::assertStringNotContainsString('/var/www', $result->get_error_message());
|
||||
self::assertStringContainsString('meta /var/www', (string) file_get_contents($log));
|
||||
unlink($log);
|
||||
|
||||
Reference in New Issue
Block a user