wiki.techinc.nl/tests/phpunit/mocks/MockMessageLocalizer.php
Umherirrender 8752df6592 Use varargs for MessageLocalizer::msg and similar
Bug: T191666
Change-Id: I59f2ae1a96af392026fc106e57d23553003c16b8
2019-10-05 17:47:49 +00:00

46 lines
1.1 KiB
PHP

<?php
/**
* A simple {@link MessageLocalizer} implementation for use in tests.
* By default, it sets the message language to 'qqx',
* to make the tests independent of the wiki configuration.
*
* @author Lucas Werkmeister
* @license GPL-2.0-or-later
*/
class MockMessageLocalizer implements MessageLocalizer {
/**
* @var string|null
*/
private $languageCode;
/**
* @param string|null $languageCode The language code to use for messages by default.
* You can specify null to use the user language,
* but this is not recommended as it may make your tests depend on the wiki configuration.
*/
public function __construct( $languageCode = 'qqx' ) {
$this->languageCode = $languageCode;
}
/**
* Get a Message object.
* Parameters are the same as {@link wfMessage()}.
*
* @param string|string[]|MessageSpecifier $key Message key, or array of keys,
* or a MessageSpecifier.
* @param mixed ...$params
* @return Message
*/
public function msg( $key, ...$params ) {
$message = wfMessage( $key, ...$params );
if ( $this->languageCode !== null ) {
$message->inLanguage( $this->languageCode );
}
return $message;
}
}