Skip to content

Commit 3d7e457

Browse files
JeroenDeDauwclaude
andcommitted
Replace mock expectation with spy and direct assertions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 90e7088 commit 3d7e457

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

tests/Unit/SubPageList/SetupTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ public function testDeletedPageInvalidatesCache() {
4747
$registeredCallbacks[$name] = $callback;
4848
} );
4949

50-
$cacheInvalidator = $this->createMock( CacheInvalidator::class );
51-
$cacheInvalidator->expects( $this->once() )
52-
->method( 'invalidateCaches' )
53-
->with( $this->callback( function ( Title $title ) {
54-
return $title->getDBkey() === 'TestPage' && $title->getNamespace() === NS_MAIN;
55-
} ) );
50+
$cacheInvalidator = new class implements CacheInvalidator {
51+
public ?Title $invalidatedTitle = null;
52+
53+
public function invalidateCaches( Title $title ): void {
54+
$this->invalidatedTitle = $title;
55+
}
56+
};
5657

5758
$extension = $this->createMock( Extension::class );
5859
$extension->method( 'getSettings' )
@@ -69,6 +70,9 @@ public function testDeletedPageInvalidatesCache() {
6970

7071
$this->assertArrayHasKey( 'PageDeleteComplete', $registeredCallbacks );
7172
$registeredCallbacks['PageDeleteComplete']( $page );
73+
74+
$this->assertSame( 'TestPage', $cacheInvalidator->invalidatedTitle->getDBkey() );
75+
$this->assertSame( NS_MAIN, $cacheInvalidator->invalidatedTitle->getNamespace() );
7276
}
7377

7478
private function newExtension() {

0 commit comments

Comments
 (0)