aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/parser/ParserTest.php
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2021-02-19 12:26:39 -0500
committerC. Scott Ananian <cananian@wikimedia.org>2021-03-16 22:37:40 +0000
commit4497f99796bedda1162c9b3140fbda010d807b68 (patch)
tree5a24583150a0104ea83d405ce0fb461fab96d610 /tests/phpunit/includes/parser/ParserTest.php
parente95b42eda65c4e022ebba1b70739dca9f4893210 (diff)
downloadmediawikicore-4497f99796bedda1162c9b3140fbda010d807b68.tar.gz
mediawikicore-4497f99796bedda1162c9b3140fbda010d807b68.zip
Parser: initialize preprocessor in constructor
Initializing the preprocessor in the constructor allows better dependency injection, and removes code complexity caused by lazy initialization. Any use of the parser is going to end up creating the preprocessor in any case, so deferring the initialization doesn't save any performance. (Best performance is given by not creating the Parser in the first place if it is not needed, which is what DI allows.) Old code tried to unbreak cyclic dependencies by setting the preprocessor to null. This is somewhat of a lost cause, since there are a number of other cyclic dependencies involving the parser, including StripState, LinkHolders, etc. The code complexity is not worth it, given how ineffective it is in any case. This is part of T275160 in so far as it allows Parser::getPreprocessor() to be a simple getter, and thus (once this patch is merged) we can safely replace any direct access to Parser::$mPreprocessor with a call to Parser::getPreprocessor(). Bug: T275160 Change-Id: I38c6fe7d5a97badffdbf34d8b9d725756ed86514
Diffstat (limited to 'tests/phpunit/includes/parser/ParserTest.php')
-rw-r--r--tests/phpunit/includes/parser/ParserTest.php13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/phpunit/includes/parser/ParserTest.php b/tests/phpunit/includes/parser/ParserTest.php
index abc65b02ab4d..d03c93a7d7a6 100644
--- a/tests/phpunit/includes/parser/ParserTest.php
+++ b/tests/phpunit/includes/parser/ParserTest.php
@@ -50,6 +50,7 @@ class ParserTest extends MediaWikiIntegrationTestCase {
$this->createMock( MediaWiki\Languages\LanguageConverterFactory::class ),
$this->createMock( MediaWiki\HookContainer\HookContainer::class ),
$this->createMock( MediaWiki\Tidy\TidyDriverBase::class ),
+ $this->createMock( WANObjectCache::class ),
];
}
@@ -76,6 +77,18 @@ class ParserTest extends MediaWikiIntegrationTestCase {
}
}
}
+ // The WANObjectCache gets set on the Preprocessor, not the
+ // Parser.
+ $preproc = $parser->getPreprocessor();
+ $refObject = new ReflectionObject( $preproc );
+ foreach ( $refObject->getProperties() as $prop ) {
+ $prop->setAccessible( true );
+ foreach ( $args as $idx => $mockTest ) {
+ if ( $prop->getValue( $preproc ) === $mockTest ) {
+ unset( $args[$idx] );
+ }
+ }
+ }
$this->assertSame( [], $args, 'Not all arguments to the Parser constructor were ' .
'found on the Parser object' );