Merge "docs: Fix typo"
[mediawiki.git] / tests / phpunit / includes / language / LocalizationUpdateSpyTrait.php
blob0a7aaed1b0541e94943b75eda94ac6602eeba0b1
1 <?php
3 namespace MediaWiki\Tests\Language;
5 use MessageCache;
7 /**
8 * Trait for asserting that the localization component is getting notified
9 * about changes as expected.
11 trait LocalizationUpdateSpyTrait {
13 /**
14 * Register expectations about updates that should get triggered.
15 * The parameters of this method represent known kinds of updates.
16 * If a parameter is added, tests calling this method should be forced
17 * to specify their expectations with respect to that kind of update.
18 * For this reason, this method should not be split, and all parameters
19 * should be required.
21 private function expectLocalizationUpdate( int $messageOverrides ) {
22 // Make sure LanguageEventIngress is triggered and updates the message
23 $messageCache = $this->createNoOpMock(
24 MessageCache::class,
26 'updateMessageOverride',
27 'figureMessage',
28 'get',
29 'transform',
30 'getMsgFromNamespace',
34 // this is the relevant assertion:
35 $messageCache->expects( $this->exactly( $messageOverrides ) )
36 ->method( 'updateMessageOverride' );
38 $messageCache->method( 'figureMessage' )
39 ->willReturn( [ 'xxx', 'en' ] );
41 $messageCache->method( 'get' )
42 ->willReturn( 'dummy test' );
44 $messageCache->method( 'transform' )
45 ->willReturn( 'dummy test' );
47 $messageCache->method( 'getMsgFromNamespace' )
48 ->willReturn( false );
50 $this->setService( 'MessageCache', $messageCache );