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