Skip to content

Commit 90e7088

Browse files
JeroenDeDauwclaude
andcommitted
Use isolated HookContainer mock in test to avoid global state pollution
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d3e4ba5 commit 90e7088

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

tests/Unit/SubPageList/SetupTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests\Unit\SubPageList;
44

5+
use MediaWiki\HookContainer\HookContainer;
56
use MediaWiki\MediaWikiServices;
67
use MediaWiki\Page\ProperPageIdentity;
78
use MediaWiki\Title\Title;
@@ -38,6 +39,14 @@ public function testRun() {
3839
}
3940

4041
public function testDeletedPageInvalidatesCache() {
42+
$registeredCallbacks = [];
43+
44+
$hookContainer = $this->createMock( HookContainer::class );
45+
$hookContainer->method( 'register' )
46+
->willReturnCallback( function ( $name, $callback ) use ( &$registeredCallbacks ) {
47+
$registeredCallbacks[$name] = $callback;
48+
} );
49+
4150
$cacheInvalidator = $this->createMock( CacheInvalidator::class );
4251
$cacheInvalidator->expects( $this->once() )
4352
->method( 'invalidateCaches' )
@@ -51,16 +60,15 @@ public function testDeletedPageInvalidatesCache() {
5160
$extension->method( 'getCacheInvalidator' )
5261
->willReturn( $cacheInvalidator );
5362

54-
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
55-
5663
$setup = new Setup( $extension, $hookContainer, __DIR__ . '/..' );
5764
$setup->run();
5865

5966
$page = $this->createMock( ProperPageIdentity::class );
6067
$page->method( 'getNamespace' )->willReturn( NS_MAIN );
6168
$page->method( 'getDBkey' )->willReturn( 'TestPage' );
6269

63-
$hookContainer->run( 'PageDeleteComplete', [ $page, null, null, 0, null, null, 0 ] );
70+
$this->assertArrayHasKey( 'PageDeleteComplete', $registeredCallbacks );
71+
$registeredCallbacks['PageDeleteComplete']( $page );
6472
}
6573

6674
private function newExtension() {

0 commit comments

Comments
 (0)