MediaWiki REL1_31
MWDebugTest.php
Go to the documentation of this file.
1<?php
2
4
5 protected function setUp() {
6 parent::setUp();
8 MWDebug::clearLog();
9 }
10
11 public static function setUpBeforeClass() {
12 parent::setUpBeforeClass();
13 MWDebug::init();
14 Wikimedia\suppressWarnings();
15 }
16
17 public static function tearDownAfterClass() {
18 parent::tearDownAfterClass();
19 MWDebug::deinit();
20 Wikimedia\restoreWarnings();
21 }
22
26 public function testAddLog() {
27 MWDebug::log( 'logging a string' );
28 $this->assertEquals(
29 [ [
30 'msg' => 'logging a string',
31 'type' => 'log',
32 'caller' => 'MWDebugTest->testAddLog',
33 ] ],
34 MWDebug::getLog()
35 );
36 }
37
41 public function testAddWarning() {
42 MWDebug::warning( 'Warning message' );
43 $this->assertEquals(
44 [ [
45 'msg' => 'Warning message',
46 'type' => 'warn',
47 'caller' => 'MWDebugTest::testAddWarning',
48 ] ],
49 MWDebug::getLog()
50 );
51 }
52
57 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
58 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
59
60 // assertCount() not available on WMF integration server
61 $this->assertEquals( 1,
62 count( MWDebug::getLog() ),
63 "Only one deprecated warning per function should be kept"
64 );
65 }
66
71 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
72 MWDebug::warning( 'some warning' );
73 MWDebug::log( 'we could have logged something too' );
74 // Another deprecation
75 MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
76
77 // assertCount() not available on WMF integration server
78 $this->assertEquals( 3,
79 count( MWDebug::getLog() ),
80 "Only one deprecated warning per function should be kept"
81 );
82 }
83
88 $request = $this->newApiRequest(
89 [ 'action' => 'help', 'format' => 'xml' ],
90 '/api.php?action=help&format=xml'
91 );
92
94 $context->setRequest( $request );
95
96 $apiMain = new ApiMain( $context );
97
98 $result = new ApiResult( $apiMain );
99
100 MWDebug::appendDebugInfoToApiResult( $context, $result );
101
102 $this->assertInstanceOf( ApiResult::class, $result );
103 $data = $result->getResultData();
104
105 $expectedKeys = [ 'mwVersion', 'phpEngine', 'phpVersion', 'gitRevision', 'gitBranch',
106 'gitViewUrl', 'time', 'log', 'debugLog', 'queries', 'request', 'memory',
107 'memoryPeak', 'includes', '_element' ];
108
109 foreach ( $expectedKeys as $expectedKey ) {
110 $this->assertArrayHasKey( $expectedKey, $data['debuginfo'], "debuginfo has $expectedKey" );
111 }
112
113 $xml = ApiFormatXml::recXmlPrint( 'help', $data, null );
114
115 // exception not thrown
116 $this->assertInternalType( 'string', $xml );
117 }
118
125 private function newApiRequest( array $params, $requestUrl ) {
126 $request = $this->getMockBuilder( FauxRequest::class )
127 ->setMethods( [ 'getRequestURL' ] )
128 ->setConstructorArgs( [
129 $params
130 ] )
131 ->getMock();
132
133 $request->expects( $this->any() )
134 ->method( 'getRequestURL' )
135 ->will( $this->returnValue( $requestUrl ) );
136
137 return $request;
138 }
139
140}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
static recXmlPrint( $name, $value, $indent, $attributes=[])
This method takes an array and converts it to XML.
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:43
This class represents the result of the API operations.
Definition ApiResult.php:33
testAvoidDuplicateDeprecations()
MWDebug::deprecated.
static tearDownAfterClass()
static setUpBeforeClass()
testAvoidNonConsecutivesDuplicateDeprecations()
MWDebug::deprecated.
testAppendDebugInfoToApiResultXmlFormat()
MWDebug::appendDebugInfoToApiResult.
testAddWarning()
MWDebug::warning.
testAddLog()
MWDebug::log.
newApiRequest(array $params, $requestUrl)
Group all the pieces relevant to the context of a request into one instance.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2806
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2811
$params