4 * @covers Parser::__construct
6 class ParserTest
extends MediaWikiTestCase
{
7 public function provideConstructorArguments() {
8 // Create a mock Config object that will satisfy ServiceOptions::__construct
9 $mockConfig = $this->createMock( 'Config' );
10 $mockConfig->method( 'has' )->willReturn( true );
11 $mockConfig->method( 'get' )->willReturn( 'I like otters.' );
14 $this->createMock( 'MediaWiki\Config\ServiceOptions' ),
15 $this->createMock( 'MagicWordFactory' ),
16 $this->createMock( 'Language' ),
17 $this->createMock( 'ParserFactory' ),
18 'a snail can sleep for three years',
19 $this->createMock( 'MediaWiki\Special\SpecialPageFactory' ),
20 $this->createMock( 'MediaWiki\Linker\LinkRendererFactory' ),
21 $this->createMock( 'NamespaceInfo' )
26 $this->createMock( 'MagicWordFactory' ),
27 $this->createMock( 'Language' ),
28 $this->createMock( 'ParserFactory' ),
29 'a snail can sleep for three years',
30 $this->createMock( 'MediaWiki\Special\SpecialPageFactory' )
33 yield
'current_args_without_namespace_info' => [
37 yield
'backward_compatible_args_minimal' => [
38 array_merge( $oldArgs ),
41 yield
'backward_compatible_args_with_config' => [
42 array_merge( $oldArgs, [ $mockConfig ] ),
45 yield
'backward_compatible_args_with_link_renderer' => [
46 array_merge( $oldArgs, [
48 $this->createMock( 'MediaWiki\Linker\LinkRendererFactory' )
52 yield
'backward_compatible_args_with_ns_info' => [
53 array_merge( $oldArgs, [
55 $this->createMock( 'MediaWiki\Linker\LinkRendererFactory' ),
56 $this->createMock( 'NamespaceInfo' )
62 * @dataProvider provideConstructorArguments
63 * @covers Parser::__construct
65 public function testBackwardsCompatibleConstructorArguments( $args ) {
66 $parser = new Parser( ...$args );
68 $refObject = new ReflectionObject( $parser );
70 // If testing backwards compatibility, test service options separately
71 if ( is_array( $args[0] ) ) {
72 $svcOptionsProp = $refObject->getProperty( 'svcOptions' );
73 $svcOptionsProp->setAccessible( true );
74 $this->assertType( 'MediaWiki\Config\ServiceOptions',
75 $svcOptionsProp->getValue( $parser )
79 // If a Config is passed, the fact that we were able to create a ServiceOptions
80 // instance without error from it proves that this argument works.
81 if ( isset( $args[6] ) ) {
86 foreach ( $refObject->getProperties() as $prop ) {
87 $prop->setAccessible( true );
88 foreach ( $args as $idx => $mockTest ) {
89 if ( $prop->getValue( $parser ) === $mockTest ) {
95 $this->assertCount( 0, $args, 'Not all arguments to the Parser constructor were ' .
96 'found on the Parser object' );