Debian Codegraph @

tests/phpunit/mocks/languages/MockLocalisationCacheTrait.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Language;
4
5 use LCStoreDB;
6 use LocalisationCache;
7 use MediaWiki\Config\ServiceOptions;
8 use MediaWiki\Tests\Unit\DummyServicesTrait;
9 use Psr\Log\NullLogger;
10
11 /**
12 * Allows the construction of a mock {@link LocalisationCache} that has a limited pre-determined list of
13 * message keys.
14 */
15 trait MockLocalisationCacheTrait {
16 use DummyServicesTrait;
17
18 /**
19 * @param array $hooks Hook overrides
20 * @param array $options Service options (see {@link LocalisationCache::CONSTRUCTOR_OPTIONS})
21 * @return LocalisationCache
22 */
23 protected function getMockLocalisationCache( array $hooks = [], array $options = [] ): LocalisationCache {
24 $hookContainer = $this->createHookContainer( $hooks );
25
26 // in case any of the LanguageNameUtils hooks are being used
27 $langNameUtils = $this->getDummyLanguageNameUtils(
28 [ 'hookContainer' => $hookContainer ]
29 );
30
31 $options += [
32 'forceRecache' => false,
33 'manualRecache' => false,
34 'ExtensionMessagesFiles' => [],
35 'MessagesDirs' => [],
36 'TranslationAliasesDirs' => [],
37 ];
38
39 $lc = $this->getMockBuilder( LocalisationCache::class )
40 ->setConstructorArgs( [
41 new ServiceOptions( LocalisationCache::CONSTRUCTOR_OPTIONS, $options ),
42 new LCStoreDB( [] ),
43 new NullLogger,
44 [],
45 $langNameUtils,
46 $hookContainer
47 ] )
48 ->onlyMethods( [ 'getMessagesDirs' ] )
49 ->getMock();
50 $lc->method( 'getMessagesDirs' )
51 ->willReturn( [ MW_INSTALL_PATH . "/tests/phpunit/data/localisationcache" ] );
52
53 return $lc;
54 }
55 }