- 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>
105 lines
3.5 KiB
PHP
105 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Support;
|
|
|
|
use LIT\MCP\Tests\Support\FakeChangeLog;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use LogicException;
|
|
use PHPUnit\Framework\AssertionFailedError;
|
|
use RuntimeException;
|
|
|
|
final class FakeChangeLogTest extends TestCase
|
|
{
|
|
public function testRecordsCallsWithIncreasingIds(): void
|
|
{
|
|
$log = new FakeChangeLog(41);
|
|
|
|
self::assertSame(41, $log->record('lit/a', 'page', '5', 'eins', 811));
|
|
self::assertSame(42, $log->record('lit/a', 'page', '6', 'zwei'));
|
|
$log->assertRecorded(
|
|
['object_id' => '5', 'summary' => 'eins', 'revision_id' => 811, 'result' => 'ok'],
|
|
['object_id' => '6', 'revision_id' => null]
|
|
);
|
|
self::assertSame(['eins', 'zwei'], $log->summaries());
|
|
}
|
|
|
|
public function testAFailureIsThrownAfterTheCallIsNoted(): void
|
|
{
|
|
$log = new FakeChangeLog(1, new RuntimeException('db weg'));
|
|
|
|
try {
|
|
$log->record('lit/a', 'page', '5', 'x');
|
|
self::fail('RuntimeException expected');
|
|
} catch (RuntimeException $e) {
|
|
self::assertSame('db weg', $e->getMessage());
|
|
}
|
|
$log->assertRecorded(['ability' => 'lit/a']);
|
|
}
|
|
|
|
public function testAssertRecordedChecksTheNumberOfCalls(): void
|
|
{
|
|
$log = new FakeChangeLog();
|
|
$log->record('lit/a', 'page', '5', 'x');
|
|
|
|
$this->expectException(AssertionFailedError::class);
|
|
$log->assertRecorded([], []);
|
|
}
|
|
|
|
public function testAssertPartialsChecksTheNamedArguments(): void
|
|
{
|
|
$log = FakeChangeLog::partialsOnly();
|
|
$log->recordPartial('lit/a', 'page', '5', 'teilweise', 811);
|
|
$log->assertPartials(['ability' => 'lit/a', 'revision_id' => 811]);
|
|
|
|
$this->expectException(AssertionFailedError::class);
|
|
$log->assertPartials(['object_id' => '6']);
|
|
}
|
|
|
|
public function testACallTheFakeDoesNotAllowThrowsAndFailsTheTestEvenWhenSwallowed(): void
|
|
{
|
|
$log = FakeChangeLog::forbidden();
|
|
|
|
try {
|
|
$log->record('lit/a', 'page', '5', 'x');
|
|
self::fail('LogicException expected');
|
|
} catch (LogicException $e) {
|
|
self::assertStringContainsString('record(lit/a, page, 5)', $e->getMessage());
|
|
}
|
|
|
|
try {
|
|
FakeChangeLog::verify();
|
|
self::fail('verify() must fail');
|
|
} catch (AssertionFailedError $e) {
|
|
self::assertStringContainsString('Unexpected change log calls', $e->getMessage());
|
|
}
|
|
FakeChangeLog::verify();
|
|
}
|
|
|
|
public function testRecordOnlyFakesRefusePartialsAndPartialsOnlyFakesRefuseRecords(): void
|
|
{
|
|
foreach ([[new FakeChangeLog(), 'recordPartial'], [FakeChangeLog::partialsOnly(), 'record']] as [$log, $method]) {
|
|
try {
|
|
$log->$method('lit/a', 'page', '5', 'x');
|
|
self::fail($method . ' must be refused');
|
|
} catch (LogicException $e) {
|
|
self::assertStringContainsString($method, $e->getMessage());
|
|
}
|
|
}
|
|
|
|
$this->expectException(AssertionFailedError::class);
|
|
$this->expectExceptionMessage('Unexpected change log calls: recordPartial(lit/a, page, 5); record(lit/a, page, 5)');
|
|
FakeChangeLog::verify();
|
|
}
|
|
|
|
public function testAnyAllowsBoth(): void
|
|
{
|
|
$log = FakeChangeLog::any(9);
|
|
|
|
self::assertSame(9, $log->record('lit/a', 'page', '5', 'x'));
|
|
$log->recordPartial('lit/a', 'page', '5', 'y');
|
|
$log->assertPartials(['summary' => 'y']);
|
|
}
|
|
}
|