Debian Codegraph @

tests/phpunit/unit/includes/parser/ParserObserverTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Parser;
4
5 use DummyContentForTesting;
6 use MediaWiki\Parser\ParserObserver;
7 use MediaWiki\Parser\ParserOptions;
8 use MediaWiki\Parser\ParserOutput;
9 use MediaWiki\Title\Title;
10 use MediaWikiUnitTestCase;
11 use TestLogger;
12
13 /**
14 * @covers \MediaWiki\Parser\ParserObserver
15 */
16 class ParserObserverTest extends MediaWikiUnitTestCase {
17 /**
18 * @param string $hashOne
19 * @param string $hashTwo
20 * @param array $expects
21 *
22 * @dataProvider provideDuplicateParse
23 */
24 public function testDuplicateParse( string $hashOne, string $hashTwo, array $expects ) {
25 $logger = new TestLogger( true );
26
27 // ::makeTitle allows us to create a title without needing any services
28 $title = Title::makeTitle(
29 NS_PROJECT,
30 'Duplicate Parse Test'
31 );
32
33 $options = $this->createNoOpMock( ParserOptions::class, [ 'optionsHash' ] );
34 $options->method( 'optionsHash' )->willReturnOnConsecutiveCalls( $hashOne, $hashTwo );
35
36 $content = new DummyContentForTesting( "hello world" );
37
38 $output = new ParserOutput();
39 $observer = new ParserObserver( $logger );
40 $observer->notifyParse( $title, null, $options, $content, $output );
41 $observer->notifyParse( $title, null, $options, $content, $output );
42
43 $this->assertArrayEquals( $expects, $logger->getBuffer() );
44 }
45
46 public static function provideDuplicateParse() {
47 yield [
48 'foo',
49 'bar',
50 []
51 ];
52 yield [
53 'foo',
54 'foo',
55 [
56 [
57 'debug',
58 'MediaWiki\Parser\ParserObserver::notifyParse: Possibly redundant parse!'
59 ]
60 ]
61 ];
62 }
63 }