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:
@@ -8,9 +8,10 @@ use Brain\Monkey\Actions;
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
use LIT\MCP\Integrations\WordPress\Status\PostCloner;
|
||||
use LIT\MCP\Integrations\WordPress\Status\PostDuplicateAbility;
|
||||
use LIT\MCP\Tests\Support\FakeChangeLog;
|
||||
use LIT\MCP\Tests\Support\SchemaFixture;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
use WP_Post;
|
||||
@@ -34,8 +35,7 @@ final class PostDuplicateAbilityTest extends TestCase
|
||||
|
||||
private function ability(PostCloner $cloner, ChangeLog $log): PostDuplicateAbility
|
||||
{
|
||||
$schema = Mockery::mock(ContentSchema::class);
|
||||
$schema->allows('isManaged')->andReturn(true);
|
||||
$schema = SchemaFixture::managed();
|
||||
|
||||
return new PostDuplicateAbility($schema, $cloner, $log);
|
||||
}
|
||||
@@ -45,8 +45,7 @@ final class PostDuplicateAbilityTest extends TestCase
|
||||
$cloner = Mockery::mock(PostCloner::class);
|
||||
$cloner->expects('duplicate')->with($this->original)->andReturn(77);
|
||||
Actions\expectDone('lit_mcp_after_save')->once()->with(77, 'lit/post-duplicate', ['post_id' => 5]);
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->expects('record')->with('lit/post-duplicate', 'page', '77', 'Kopie von "Team" (ID 5) angelegt', null)->andReturn(8);
|
||||
$log = new FakeChangeLog(8);
|
||||
|
||||
$result = $this->ability($cloner, $log)->execute(['post_id' => 5]);
|
||||
|
||||
@@ -55,6 +54,13 @@ final class PostDuplicateAbilityTest extends TestCase
|
||||
self::assertSame(8, $result['log_id']);
|
||||
self::assertSame(Rev::ofPost($this->copy), $result['rev']);
|
||||
self::assertSame([], $result['warnings']);
|
||||
$log->assertRecorded([
|
||||
'ability' => 'lit/post-duplicate',
|
||||
'object_type' => 'page',
|
||||
'object_id' => '77',
|
||||
'summary' => 'Kopie von "Team" (ID 5) angelegt',
|
||||
'revision_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testNeedsTheRightToCreateEntriesOfThatType(): void
|
||||
@@ -63,7 +69,7 @@ final class PostDuplicateAbilityTest extends TestCase
|
||||
$cloner = Mockery::mock(PostCloner::class);
|
||||
$cloner->expects('duplicate')->never();
|
||||
|
||||
$result = $this->ability($cloner, Mockery::mock(ChangeLog::class))->execute(['post_id' => 5]);
|
||||
$result = $this->ability($cloner, FakeChangeLog::forbidden())->execute(['post_id' => 5]);
|
||||
|
||||
self::assertSame('lit_forbidden', $result->get_error_code());
|
||||
}
|
||||
@@ -74,14 +80,14 @@ final class PostDuplicateAbilityTest extends TestCase
|
||||
$cloner = Mockery::mock(PostCloner::class);
|
||||
$cloner->expects('duplicate')->never();
|
||||
|
||||
$result = $this->ability($cloner, Mockery::mock(ChangeLog::class))->execute(['post_id' => 5]);
|
||||
$result = $this->ability($cloner, FakeChangeLog::forbidden())->execute(['post_id' => 5]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
}
|
||||
|
||||
public function testIsIndirectAndNotIdempotent(): void
|
||||
{
|
||||
$ability = $this->ability(Mockery::mock(PostCloner::class), Mockery::mock(ChangeLog::class));
|
||||
$ability = $this->ability(Mockery::mock(PostCloner::class), FakeChangeLog::forbidden());
|
||||
|
||||
self::assertFalse($ability->isDirect());
|
||||
self::assertFalse($ability->annotations()['idempotent']);
|
||||
|
||||
Reference in New Issue
Block a user