test: FakeChangeLog and SchemaFixture instead of repeated mocks (T2)

- tests/Support/FakeChangeLog extends ChangeLog: records record()/recordPartial()
  calls, increasing ids, optional failure; new FakeChangeLog(id) / partialsOnly() /
  any(id) / forbidden() mirror what the replaced mocks allowed. assertRecorded() /
  assertPartials() check count and the named arguments. Calls a fake does not allow
  throw and are also verified in TestCase::tearDown (one assertion per test that
  uses a fake), so swallowed change-log calls still fail like a never() expectation.
- All ChangeLog mocks of ability/integration tests replaced (the admin tests that
  stub query/purge/clear keep their mocks); expectException tests that checked the
  partial log now catch and assert.
- SchemaFixture::managed(?divi) replaces the 21 isManaged-only ContentSchema mocks;
  DiviFixtures::schema() uses it.
Tests 1397 -> 1404 (FakeChangeLogTest); 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:53:54 +02:00
co-authored by Claude Opus 5.5
parent 3d96a41366
commit 72eeaa46ad
34 changed files with 725 additions and 353 deletions
@@ -7,10 +7,9 @@ namespace LIT\MCP\Tests\Unit\Integrations\WordPress;
use Brain\Monkey\Actions;
use Brain\Monkey\Functions;
use LIT\MCP\Abilities\Rev;
use LIT\MCP\ChangeLog\ChangeLog;
use LIT\MCP\Integrations\WordPress\PostChangeResult;
use LIT\MCP\Tests\Support\FakeChangeLog;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
use RuntimeException;
use WP_Post;
@@ -38,8 +37,7 @@ final class PostChangeResultTest extends TestCase
$post = new WP_Post(['ID' => 5, 'post_title' => 'Team']);
Actions\expectDone('lit_mcp_after_save')->once()->with(5, 'lit/content-update', ['post_id' => 5]);
Functions\when('get_post')->justReturn($post);
$log = Mockery::mock(ChangeLog::class);
$log->expects('record')->with('lit/content-update', 'page', '5', 'geändert', 811)->andReturn(9);
$log = new FakeChangeLog(9);
$change = new PostChangeResult('lit/content-update', $log, 5, 'die Änderung', ['vorher']);
$change->afterSave(['post_id' => 5]);
@@ -52,6 +50,13 @@ final class PostChangeResultTest extends TestCase
self::assertSame(Rev::ofPost($post), $result['rev']);
self::assertSame(9, $result['log_id']);
self::assertSame(['vorher'], $result['warnings']);
$log->assertRecorded([
'ability' => 'lit/content-update',
'object_type' => 'page',
'object_id' => '5',
'summary' => 'geändert',
'revision_id' => 811,
]);
}
public function testFailuresAfterTheWriteBecomeWarnings(): void
@@ -60,8 +65,7 @@ final class PostChangeResultTest extends TestCase
throw new RuntimeException('listener kaputt');
});
Functions\when('get_post')->justReturn(null);
$log = Mockery::mock(ChangeLog::class);
$log->expects('record')->andThrow(new RuntimeException('log kaputt'));
$log = new FakeChangeLog(1, new RuntimeException('log kaputt'));
$fallback = new WP_Post(['ID' => 5]);
$change = new PostChangeResult('lit/post-publish', $log, 5);
@@ -77,13 +81,14 @@ final class PostChangeResultTest extends TestCase
'Änderungsprotokoll konnte nicht geschrieben werden; die Änderung ist gespeichert.',
], $result['warnings']);
self::assertStringContainsString('listener kaputt', (string) file_get_contents($this->errorLog));
$log->assertRecorded([]);
}
public function testWithoutAReadablePostTheRevIsNull(): void
{
Functions\when('get_post')->justReturn(null);
$change = new PostChangeResult('lit/content-create', Mockery::mock(ChangeLog::class), 5, 'der Entwurf');
$change = new PostChangeResult('lit/content-create', FakeChangeLog::forbidden(), 5, 'der Entwurf');
self::assertNull($change->reread());
self::assertNull($change->result('ok', null)->toArray()['rev']);