wiki.techinc.nl/tests/phpunit/unit/includes/parser/ParserFactoryTest.php
DannyS712 94169ee873 Whitespace cleanup: Use tabs for indentation, avoid double spaces
Change-Id: I346073b59d283029bd6666356c62c81e687ea5e6
2020-06-27 07:53:07 +00:00

86 lines
2.7 KiB
PHP

<?php
use MediaWiki\BadFileLookup;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Languages\LanguageConverterFactory;
use MediaWiki\Linker\LinkRendererFactory;
use MediaWiki\SpecialPage\SpecialPageFactory;
use Psr\Log\LoggerInterface;
use Wikimedia\TestingAccessWrapper;
/**
* @covers ParserFactory
*/
class ParserFactoryTest extends MediaWikiUnitTestCase {
private function createFactory() {
$options = $this->getMockBuilder( ServiceOptions::class )
->disableOriginalConstructor()
->setMethods( [ 'assertRequiredOptions', 'get' ] )->getMock();
$options->expects( $this->never() )
->method( $this->anythingBut( 'assertRequiredOptions', 'get' ) );
$this->assertInstanceOf( ServiceOptions::class, $options );
// Stub out a MagicWordFactory so the Parser can initialize its
// function hooks when it is created.
$mwFactory = $this->getMockBuilder( MagicWordFactory::class )
->disableOriginalConstructor()
->setMethods( [ 'get', 'getVariableIDs' ] )
->getMock();
$mwFactory
->method( 'get' )->will( $this->returnCallback( function ( $arg ) {
$mw = $this->getMockBuilder( MagicWord::class )
->disableOriginalConstructor()
->setMethods( [ 'getSynonyms' ] )
->getMock();
$mw->method( 'getSynonyms' )->willReturn( [] );
return $mw;
} ) );
$mwFactory
->method( 'getVariableIDs' )->willReturn( [] );
$factory = new ParserFactory(
$options,
$mwFactory,
$this->createNoOpMock( Language::class ),
"",
$this->createNoOpMock( SpecialPageFactory::class ),
$this->createNoOpMock( LinkRendererFactory::class ),
$this->createNoOpMock( NamespaceInfo::class ),
$this->createNoOpMock( LoggerInterface::class ),
$this->createNoOpMock( BadFileLookup::class ),
$this->createNoOpMock( LanguageConverterFactory::class ),
$this->createHookContainer()
);
return $factory;
}
/**
* @covers ParserFactory::__construct
*/
public function testConstructor() {
$factory = $this->createFactory();
$this->assertNotNull( $factory, "Factory should be created correctly" );
}
/**
* @covers ParserFactory::create
*/
public function testCreate() {
$factory = $this->createFactory();
$parser = $factory->create();
$this->assertNotNull( $factory, "Factory should be created correctly" );
$this->assertNotNull( $parser, "Factory should create parser correctly" );
$this->assertInstanceOf( Parser::class, $parser );
$parserWrapper = TestingAccessWrapper::newFromObject( $parser );
$factoryWrapper = TestingAccessWrapper::newFromObject( $factory );
$this->assertSame(
$factoryWrapper->languageConverterFactory, $parserWrapper->languageConverterFactory
);
$this->assertSame(
$factory, $parserWrapper->factory
);
}
}