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>
44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit;
|
|
|
|
use Brain\Monkey;
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Tests\Support\AssertsToolErrors;
|
|
use LIT\MCP\Tests\Support\FakeChangeLog;
|
|
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
|
use PHPUnit\Framework\TestCase as BaseTestCase;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
use AssertsToolErrors;
|
|
use MockeryPHPUnitIntegration;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Monkey\setUp();
|
|
|
|
// Pure helpers with obvious behaviour. Never use Functions\expect() on these
|
|
// names in a test: Brain Monkey forbids a stub and an expectation for the
|
|
// same function. Functions\when() may still redefine them.
|
|
Functions\stubs([
|
|
'wp_json_encode' => static fn ($data, int $flags = 0) => json_encode($data, $flags),
|
|
'is_wp_error' => static fn ($thing): bool => $thing instanceof \WP_Error,
|
|
'absint' => static fn ($value): int => abs((int) $value),
|
|
'wp_slash' => static fn ($value) => $value,
|
|
'wp_unslash' => static fn ($value) => $value,
|
|
'sanitize_text_field' => static fn ($value): string => trim(strip_tags((string) $value)),
|
|
]);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Monkey\tearDown();
|
|
parent::tearDown();
|
|
FakeChangeLog::verify();
|
|
}
|
|
}
|