Merge "Add getMockMessage to MediaWikiTestCaseTrait"
This commit is contained in:
commit
ff10f4e79d
4 changed files with 34 additions and 59 deletions
|
|
@ -196,4 +196,37 @@ trait MediaWikiTestCaseTrait {
|
|||
$this->fail( $message );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @param array $params
|
||||
* @return Message|MockObject
|
||||
* @since 1.35
|
||||
*/
|
||||
protected function getMockMessage( $text = '', $params = [] ) {
|
||||
/** @var MockObject $msg */
|
||||
$msg = $this->getMockBuilder( Message::class )
|
||||
->disableOriginalConstructor()
|
||||
->setMethods( [] )
|
||||
->getMock();
|
||||
$msg->method( 'toString' )->willReturn( $text );
|
||||
$msg->method( '__toString' )->willReturn( $text );
|
||||
$msg->method( 'text' )->willReturn( $text );
|
||||
$msg->method( 'parse' )->willReturn( $text );
|
||||
$msg->method( 'plain' )->willReturn( $text );
|
||||
$msg->method( 'parseAsBlock' )->willReturn( $text );
|
||||
$msg->method( 'escaped' )->willReturn( $text );
|
||||
$msg->method( 'title' )->willReturn( $msg );
|
||||
$msg->method( 'getKey' )->willReturn( $text );
|
||||
$msg->method( 'params' )->willReturn( $msg );
|
||||
$msg->method( 'getParams' )->willReturn( $params );
|
||||
$msg->method( 'rawParams' )->willReturn( $msg );
|
||||
$msg->method( 'inLanguage' )->willReturn( $msg );
|
||||
$msg->method( 'inContentLanguage' )->willReturn( $msg );
|
||||
$msg->method( 'useDatabase' )->willReturn( $msg );
|
||||
$msg->method( 'setContext' )->willReturn( $msg );
|
||||
$msg->method( 'exists' )->willReturn( true );
|
||||
$msg->method( 'content' )->willReturn( new MessageContent( $msg ) );
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,33 +163,4 @@ abstract class MediaWikiUnitTestCase extends TestCase {
|
|||
self::$temporaryHooks[] = $hookToRemove;
|
||||
}
|
||||
|
||||
protected function getMockMessage( $text, ...$params ) {
|
||||
if ( isset( $params[0] ) && is_array( $params[0] ) ) {
|
||||
$params = $params[0];
|
||||
}
|
||||
|
||||
$msg = $this->getMockBuilder( Message::class )
|
||||
->disableOriginalConstructor()
|
||||
->setMethods( [] )
|
||||
->getMock();
|
||||
|
||||
$msg->method( 'toString' )->willReturn( $text );
|
||||
$msg->method( '__toString' )->willReturn( $text );
|
||||
$msg->method( 'text' )->willReturn( $text );
|
||||
$msg->method( 'parse' )->willReturn( $text );
|
||||
$msg->method( 'plain' )->willReturn( $text );
|
||||
$msg->method( 'parseAsBlock' )->willReturn( $text );
|
||||
$msg->method( 'escaped' )->willReturn( $text );
|
||||
|
||||
$msg->method( 'title' )->willReturn( $msg );
|
||||
$msg->method( 'inLanguage' )->willReturn( $msg );
|
||||
$msg->method( 'inContentLanguage' )->willReturn( $msg );
|
||||
$msg->method( 'useDatabase' )->willReturn( $msg );
|
||||
$msg->method( 'setContext' )->willReturn( $msg );
|
||||
|
||||
$msg->method( 'exists' )->willReturn( true );
|
||||
$msg->method( 'content' )->willReturn( new MessageContent( $msg ) );
|
||||
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,7 @@ class StatusTest extends MediaWikiLangTestCase {
|
|||
* @covers Status::newFatal
|
||||
*/
|
||||
public function testNewFatalWithMessage() {
|
||||
$message = $this->getMockBuilder( Message::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$message = $this->getMockMessage();
|
||||
$status = Status::newFatal( $message );
|
||||
$this->assertFalse( $status->isGood() );
|
||||
$this->assertFalse( $status->isOK() );
|
||||
|
|
@ -223,19 +220,6 @@ class StatusTest extends MediaWikiLangTestCase {
|
|||
$this->assertFalse( $status->isOK() );
|
||||
}
|
||||
|
||||
protected function getMockMessage( $key = 'key', $params = [] ) {
|
||||
$message = $this->getMockBuilder( Message::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->expects( $this->atLeastOnce() )
|
||||
->method( 'getKey' )
|
||||
->will( $this->returnValue( $key ) );
|
||||
$message->expects( $this->atLeastOnce() )
|
||||
->method( 'getParams' )
|
||||
->will( $this->returnValue( $params ) );
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $messageDetails E.g. [ 'KEY' => [ /PARAMS/ ] ]
|
||||
* @return Message[]
|
||||
|
|
|
|||
|
|
@ -6,19 +6,6 @@
|
|||
*/
|
||||
class ErrorPageErrorTest extends MediaWikiTestCase {
|
||||
|
||||
private function getMockMessage() {
|
||||
$mockMessage = $this->getMockBuilder( Message::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$mockMessage->expects( $this->once() )
|
||||
->method( 'inLanguage' )
|
||||
->will( $this->returnValue( $mockMessage ) );
|
||||
$mockMessage->expects( $this->once() )
|
||||
->method( 'useDatabase' )
|
||||
->will( $this->returnValue( $mockMessage ) );
|
||||
return $mockMessage;
|
||||
}
|
||||
|
||||
public function testConstruction() {
|
||||
$mockMessage = $this->getMockMessage();
|
||||
$title = 'Foo';
|
||||
|
|
|
|||
Loading…
Reference in a new issue