MediaWiki  1.32.5
ParserFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
12  public function testConstructorArgNum() {
13  $factoryConstructor = new ReflectionMethod( 'ParserFactory', '__construct' );
14  $instanceConstructor = new ReflectionMethod( 'Parser', '__construct' );
15  // Subtract one for the ParserFactory itself
16  $this->assertSame( $instanceConstructor->getNumberOfParameters() - 1,
17  $factoryConstructor->getNumberOfParameters(),
18  'Parser and ParserFactory constructors have an inconsistent number of parameters. ' .
19  'Did you add a parameter to one and not the other?' );
20  }
21 
22  public function testAllArgumentsWerePassed() {
23  $factoryConstructor = new ReflectionMethod( 'ParserFactory', '__construct' );
24  $mocks = [];
25  foreach ( $factoryConstructor->getParameters() as $param ) {
26  $type = (string)$param->getType();
27  if ( $type === 'array' ) {
28  $val = [ 'porcupines will tell me your secrets' . count( $mocks ) ];
29  } elseif ( class_exists( $type ) || interface_exists( $type ) ) {
30  $val = $this->createMock( $type );
31  } elseif ( $type === '' ) {
32  // Optimistically assume a string is okay
33  $val = 'I will de-quill them first' . count( $mocks );
34  } else {
35  $this->fail( "Unrecognized parameter type $type in ParserFactory constructor" );
36  }
37  $mocks[] = $val;
38  }
39 
40  $factory = new ParserFactory( ...$mocks );
41  $parser = $factory->create();
42 
43  foreach ( ( new ReflectionObject( $parser ) )->getProperties() as $prop ) {
44  $prop->setAccessible( true );
45  foreach ( $mocks as $idx => $mock ) {
46  if ( $prop->getValue( $parser ) === $mock ) {
47  unset( $mocks[$idx] );
48  }
49  }
50  }
51 
52  $this->assertCount( 0, $mocks, 'Not all arguments to the ParserFactory constructor were ' .
53  'found in Parser member variables' );
54  }
55 }
captcha-old.count
count
Definition: captcha-old.py:249
ParserFactoryTest\testConstructorArgNum
testConstructorArgNum()
For backwards compatibility, all parameters to the parser constructor are optional and default to the...
Definition: ParserFactoryTest.php:12
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ParserFactoryTest\testAllArgumentsWerePassed
testAllArgumentsWerePassed()
Definition: ParserFactoryTest.php:22
ParserFactoryTest
ParserFactory.
Definition: ParserFactoryTest.php:6
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
$parser
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1841
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
ParserFactory
Definition: ParserFactory.php:27
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$type
$type
Definition: testCompression.php:48