` parse clears the original parser state. * @see https://phabricator.wikimedia.org/T240248 * @covers \Cite\ReferenceStack::pushRef */ public function testReferenceStackError() { $this->insertPage( 'Cite-tracking-category-cite-error', '{{PAGENAME}}', NS_MEDIAWIKI ); $services = MediaWikiServices::getInstance(); // Reset the MessageCache in order to force it to clone a new parser. $services->resetServiceForTesting( 'MessageCache' ); $services->getMessageCache()->enable(); $parserOutput = $services->getParser()->parse( ' text #1 text #2 text #3 ', Title::makeTitle( NS_MAIN, mt_rand() ), ParserOptions::newFromAnon() ); $this->assertStringContainsString( 'cite_ref-2', $parserOutput->getText(), 'Internal counter should not reset to 1 for text #3' ); } private function newCite(): Cite { $mockOptions = $this->createMock( ParserOptions::class ); $mockOptions->method( 'getIsPreview' )->willReturn( false ); $mockOptions->method( 'getIsSectionPreview' )->willReturn( false ); $mockOptions->method( 'getUserLangObj' )->willReturn( $this->createMock( Language::class ) ); $mockParser = $this->createMock( Parser::class ); $mockParser->method( 'getOptions' )->willReturn( $mockOptions ); $mockParser->method( 'getContentLanguage' )->willReturn( $this->createMock( Language::class ) ); return new Cite( $mockParser ); } }