Debian Codegraph @

tests/phpunit/unit/includes/HookContainer/FauxGlobalHookArrayTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\HookContainer;
4
5 use MediaWiki\HookContainer\FauxGlobalHookArray;
6 use MediaWiki\HookContainer\HookContainer;
7 use MediaWiki\HookContainer\StaticHookRegistry;
8 use MediaWikiUnitTestCase;
9 use Wikimedia\ObjectFactory\ObjectFactory;
10
11 /**
12 * Tests that all arguments passed into FauxGlobalHookArray are passed along to HookContainer.
13 * @covers \MediaWiki\HookContainer\FauxGlobalHookArray
14 * @covers \MediaWiki\HookContainer\FauxHookHandlerArray
15 */
16 class FauxGlobalHookArrayTest extends MediaWikiUnitTestCase {
17
18 public function testRegisterHandler() {
19 $this->expectDeprecationAndContinue( '/Accessing \$wgHooks directly is deprecated/' );
20
21 $counter = 0;
22
23 $handler = static function () use ( &$counter ) {
24 $counter++;
25 };
26
27 $registry = new StaticHookRegistry();
28 $factory = $this->createNoOpMock( ObjectFactory::class );
29 $container = new HookContainer( $registry, $factory );
30 $hooks = new FauxGlobalHookArray( $container );
31
32 $this->expectDeprecationAndContinue( '/getHandlerCallbacks/' );
33
34 // Register a handler via the array
35 $hooks['FirstHook'][] = $handler;
36
37 $this->assertTrue( $container->isRegistered( 'FirstHook' ) );
38 $this->assertCount( 1, $container->getHandlerCallbacks( 'FirstHook' ) );
39
40 $this->assertTrue( isset( $hooks['FirstHook'] ) );
41 $this->assertCount( 1, $hooks['FirstHook'] );
42
43 $first = $hooks['FirstHook'][0];
44 $this->assertSame( $handler, $first );
45
46 $container->run( 'FirstHook' );
47 $this->assertSame( 1, $counter );
48
49 // Register a handler via the HookContainer
50 $container->register( 'SecondHook', $handler );
51
52 $this->assertTrue( isset( $hooks['SecondHook'] ) );
53 $this->assertCount( 1, $hooks['SecondHook'] );
54
55 $first = $hooks['SecondHook'][0];
56 $this->assertSame( $handler, $first );
57 }
58
59 }