Use varargs for MessageLocalizer::msg and similar
[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 ...$params
34 * @return Message
35 */
36 public function msg( $key, ...$params ) {
37 $message = wfMessage( $key, ...$params );
38
39 if ( $this->languageCode !== null ) {
40 $message->inLanguage( $this->languageCode );
41 }
42
43 return $message;
44 }
45
46 }