wiki.techinc.nl/tests/phpunit/unit/includes/parser/ParserObserverTest.php
Tim Starling 5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00

56 lines
1.3 KiB
PHP

<?php
use MediaWiki\Parser\ParserObserver;
use MediaWiki\Title\Title;
/**
* @covers \MediaWiki\Parser\ParserObserver
*/
class ParserObserverTest extends MediaWikiUnitTestCase {
/**
* @param string $hashOne
* @param string $hashTwo
* @param array $expects
*
* @dataProvider provideDuplicateParse
*/
public function testDuplicateParse( string $hashOne, string $hashTwo, array $expects ) {
$logger = new TestLogger( true );
// ::makeTitle allows us to create a title without needing any services
$title = Title::makeTitle(
NS_PROJECT,
'Duplicate Parse Test'
);
$options = $this->createNoOpMock( ParserOptions::class, [ 'optionsHash' ] );
$options->method( 'optionsHash' )->willReturnOnConsecutiveCalls( $hashOne, $hashTwo );
$content = new DummyContentForTesting( "hello world" );
$output = new ParserOutput();
$observer = new ParserObserver( $logger );
$observer->notifyParse( $title, null, $options, $content, $output );
$observer->notifyParse( $title, null, $options, $content, $output );
$this->assertArrayEquals( $expects, $logger->getBuffer() );
}
public static function provideDuplicateParse() {
yield [
'foo',
'bar',
[]
];
yield [
'foo',
'foo',
[
[
'debug',
'MediaWiki\Parser\ParserObserver::notifyParse: Possibly redundant parse!'
]
]
];
}
}