The default will remain PHPUnit 4.x due to PHP 5.5 support. But, we should allow developers to run tests with newer PHPUnit versions which are noticably faster (especially for code coverage reports). * <https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0> PHPUnit 5 deprecates the getMock() shortcut for getMockBuilder()->getMock(). It instead introduces the shortcut createMock() which has better defaults than getMockBuilder(). For example, it sets 'disableArgumentCloning' and other things by default. Going forward, code should either use getMockBuilder directly and configure it using the setter methods (instead of the confusing variadic arguments of getMock) or simply use the new minimalistic createMock method. This patch backports the createMock method to MediaWikiTestCase so that we can start using it. Change-Id: I091c0289b21d2b1c876adba89529dc3e72b99af2
82 lines
2 KiB
PHP
82 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
|
use MediaWiki\Linker\LinkRendererFactory;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* @covers MediaWiki\Linker\LinkRendererFactory
|
|
*/
|
|
class LinkRendererFactoryTest extends MediaWikiLangTestCase {
|
|
|
|
/**
|
|
* @var TitleFormatter
|
|
*/
|
|
private $titleFormatter;
|
|
|
|
/**
|
|
* @var LinkCache
|
|
*/
|
|
private $linkCache;
|
|
|
|
public function setUp() {
|
|
parent::setUp();
|
|
$this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
|
|
$this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
|
|
}
|
|
|
|
public static function provideCreateFromLegacyOptions() {
|
|
return [
|
|
[
|
|
[ 'forcearticlepath' ],
|
|
'getForceArticlePath',
|
|
true
|
|
],
|
|
[
|
|
[ 'http' ],
|
|
'getExpandURLs',
|
|
PROTO_HTTP
|
|
],
|
|
[
|
|
[ 'https' ],
|
|
'getExpandURLs',
|
|
PROTO_HTTPS
|
|
],
|
|
[
|
|
[ 'stubThreshold' => 150 ],
|
|
'getStubThreshold',
|
|
150
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideCreateFromLegacyOptions
|
|
*/
|
|
public function testCreateFromLegacyOptions( $options, $func, $val ) {
|
|
$factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
|
|
$linkRenderer = $factory->createFromLegacyOptions(
|
|
$options
|
|
);
|
|
$this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
|
|
$this->assertEquals( $val, $linkRenderer->$func(), $func );
|
|
}
|
|
|
|
public function testCreate() {
|
|
$factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
|
|
$this->assertInstanceOf( LinkRenderer::class, $factory->create() );
|
|
}
|
|
|
|
public function testCreateForUser() {
|
|
/** @var PHPUnit_Framework_MockObject_MockObject|User $user */
|
|
$user = $this->getMockBuilder( User::class )
|
|
->setMethods( [ 'getStubThreshold' ] )->getMock();
|
|
$user->expects( $this->once() )
|
|
->method( 'getStubThreshold' )
|
|
->willReturn( 15 );
|
|
$factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
|
|
$linkRenderer = $factory->createForUser( $user );
|
|
$this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
|
|
$this->assertEquals( 15, $linkRenderer->getStubThreshold() );
|
|
}
|
|
}
|