Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / mocks / FakeQqxMessageLocalizer.php
blobc08a58024085b2bfb3783bce9aa34e665a4decdd
1 <?php
3 declare( strict_types = 1 );
5 namespace MediaWiki\Tests\Unit;
7 use LanguageQqx;
8 use MediaWiki\Language\Language;
9 use MediaWiki\Message\Message;
10 use MessageLocalizer;
11 use Wikimedia\Message\MessageSpecifier;
13 /**
14 * A MessageLocalizer that does not make database/service calls, for use in unit tests
16 * To be used in a phpunit unit test like so:
18 * ```php
19 * $output = $this->createMock( OutputPage::class );
20 * $output->method( 'msg' )
21 * ->willReturnCallback( [ new FakeQqxMessageLocalizer(), 'msg' ] );
22 * ```
24 * @since 1.40 (backported in 1.39.4)
25 * @license GPL-2.0-or-later
27 class FakeQqxMessageLocalizer implements MessageLocalizer {
29 public function msg( $key, ...$params ): Message {
30 $message = new class( $key ) extends Message {
32 protected function fetchMessage(): string {
33 return "($this->key$*)";
36 public static function newFromSpecifier( $value ) {
37 if ( $value instanceof MessageSpecifier ) {
38 return new self( $value );
40 return parent::newFromSpecifier( $value );
43 public function getLanguage(): Language {
44 return new class() extends LanguageQqx {
46 public function __construct() {
49 public function getCode(): string {
50 return 'qqx';
53 // Support using Message::numParam()
54 public function formatNum( $number ): string {
55 return (string)$number;
60 public function inContentLanguage(): Message {
61 return $this;
64 protected function transformText( $string ): string {
65 return $string;
69 if ( $params ) {
70 // we use ->params() instead of the $params constructor parameter
71 // because ->params() supports some additional calling conventions,
72 // which our callers might also have used
73 $message->params( ...$params );
76 return $message;