rdbms: make LBFactory "cliMode" check for phpdbg
[lhc/web/wiklou.git] / tests / phpunit / mocks / MockMessageLocalizer.php
1 <?php
2
3 use Message;
4 use MessageLocalizer;
5 use MessageSpecifier;
6
7 /**
8 * A simple {@link MessageLocalizer} implementation for use in tests.
9 * By default, it sets the message language to 'qqx',
10 * to make the tests independent of the wiki configuration.
11 *
12 * @author Lucas Werkmeister
13 * @license GPL-2.0-or-later
14 */
15 class MockMessageLocalizer implements MessageLocalizer {
16
17 /**
18 * @var string|null
19 */
20 private $languageCode;
21
22 /**
23 * @param string|null $languageCode The language code to use for messages by default.
24 * You can specify null to use the user language,
25 * but this is not recommended as it may make your tests depend on the wiki configuration.
26 */
27 public function __construct( $languageCode = 'qqx' ) {
28 $this->languageCode = $languageCode;
29 }
30
31 /**
32 * Get a Message object.
33 * Parameters are the same as {@link wfMessage()}.
34 *
35 * @param string|string[]|MessageSpecifier $key Message key, or array of keys,
36 * or a MessageSpecifier.
37 * @param mixed $args,...
38 * @return Message
39 */
40 public function msg( $key ) {
41 $args = func_get_args();
42
43 /** @var Message $message */
44 $message = call_user_func_array( 'wfMessage', $args );
45
46 if ( $this->languageCode !== null ) {
47 $message->inLanguage( $this->languageCode );
48 }
49
50 return $message;
51 }
52
53 }