wiki.techinc.nl/tests/phpunit/mocks/MockMessageLocalizer.php
Max Semenik 1e680456b4 Get rid of call_user_func(_array)(), part 3
Also cleaned up nearby code in a couple places.

Change-Id: Ibf44ee7c0ceb739d7e79406e4ff39303c316e285
2018-06-10 02:21:24 +00:00

49 lines
1.2 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 $args,...
* @return Message
*/
public function msg( $key ) {
$args = func_get_args();
/** @var Message $message */
$message = wfMessage( ...$args );
if ( $this->languageCode !== null ) {
$message->inLanguage( $this->languageCode );
}
return $message;
}
}