2012-01-13 23:07:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\RequestContext;
|
2024-05-03 19:28:04 +00:00
|
|
|
use MediaWiki\Debug\MWDebug;
|
2023-02-27 08:26:07 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
|
|
|
use MediaWiki\MainConfigNames;
|
2022-10-28 10:04:25 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2023-09-18 13:56:39 +00:00
|
|
|
use MediaWiki\Title\TitleValue;
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2022-01-05 01:41:28 +00:00
|
|
|
|
2023-10-05 04:55:31 +00:00
|
|
|
/**
|
2024-05-03 19:28:04 +00:00
|
|
|
* @covers \MediaWiki\Debug\MWDebug
|
2023-10-05 04:55:31 +00:00
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class MWDebugTest extends MediaWikiIntegrationTestCase {
|
2012-01-13 23:07:52 +00:00
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2024-07-09 15:36:08 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::DevelopmentWarnings, false );
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
2012-01-13 23:07:52 +00:00
|
|
|
/** Clear log before each test */
|
|
|
|
|
MWDebug::clearLog();
|
2016-05-15 05:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
public static function setUpBeforeClass(): void {
|
2016-05-18 19:17:34 +00:00
|
|
|
parent::setUpBeforeClass();
|
2016-05-15 05:09:13 +00:00
|
|
|
MWDebug::init();
|
2012-08-25 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
public static function tearDownAfterClass(): void {
|
2016-05-15 05:09:13 +00:00
|
|
|
MWDebug::deinit();
|
2020-12-23 10:03:34 +00:00
|
|
|
parent::tearDownAfterClass();
|
2012-01-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
public function testLog() {
|
2023-10-05 04:55:31 +00:00
|
|
|
@MWDebug::log( 'logging a string' );
|
2013-02-14 13:10:38 +00:00
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [
|
2013-02-14 13:10:38 +00:00
|
|
|
'msg' => 'logging a string',
|
|
|
|
|
'type' => 'log',
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
'caller' => 'MWDebugTest->testLog',
|
2016-02-17 09:09:32 +00:00
|
|
|
] ],
|
2012-01-13 23:07:52 +00:00
|
|
|
MWDebug::getLog()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
public function testWarningProduction() {
|
|
|
|
|
$logger = $this->createMock( LoggerInterface::class );
|
|
|
|
|
$logger->expects( $this->once() )->method( 'info' );
|
|
|
|
|
$this->setLogger( 'warning', $logger );
|
|
|
|
|
|
|
|
|
|
@MWDebug::warning( 'Ohnosecond!' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testWarningDevelopment() {
|
2024-07-09 15:36:08 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::DevelopmentWarnings, true );
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
|
2024-02-23 19:15:11 +00:00
|
|
|
$this->expectPHPError(
|
|
|
|
|
E_USER_NOTICE,
|
|
|
|
|
static function () {
|
|
|
|
|
MWDebug::warning( 'Ohnosecond!' );
|
|
|
|
|
},
|
|
|
|
|
'Ohnosecond!'
|
|
|
|
|
);
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Message from the error channel are copied to the debug toolbar "Console" log.
|
|
|
|
|
*
|
|
|
|
|
* This normally happens via wfDeprecated -> MWDebug::deprecated -> trigger_error
|
|
|
|
|
* -> MWExceptionHandler -> LoggerFactory -> LegacyLogger -> MWDebug::debugMsg.
|
|
|
|
|
*
|
|
|
|
|
* The above test asserts up until trigger_error.
|
|
|
|
|
* This test asserts from LegacyLogger down.
|
|
|
|
|
*/
|
|
|
|
|
public function testMessagesFromErrorChannel() {
|
|
|
|
|
// Turn off to keep mw-error.log file empty in CI (and thus avoid build failure)
|
2024-07-09 15:36:08 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::DebugLogGroups, [] );
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
|
|
|
|
|
MWExceptionHandler::handleError( E_USER_DEPRECATED, 'Warning message' );
|
2013-02-14 13:10:38 +00:00
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
'msg' => 'PHP Deprecated: Warning message',
|
2013-02-14 13:10:38 +00:00
|
|
|
'type' => 'warn',
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
'caller' => 'MWDebugTest::testMessagesFromErrorChannel',
|
2016-02-17 09:09:32 +00:00
|
|
|
] ],
|
2012-01-13 23:07:52 +00:00
|
|
|
MWDebug::getLog()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 21:49:22 +00:00
|
|
|
public function testDetectDeprecatedOverride() {
|
|
|
|
|
$baseclassInstance = new TitleValue( NS_MAIN, 'Test' );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
MWDebug::detectDeprecatedOverride(
|
|
|
|
|
$baseclassInstance,
|
|
|
|
|
TitleValue::class,
|
|
|
|
|
'getNamespace',
|
|
|
|
|
MW_VERSION
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// create a dummy subclass that overrides a method
|
|
|
|
|
$subclassInstance = new class ( NS_MAIN, 'Test' ) extends TitleValue {
|
2021-09-12 23:44:59 +00:00
|
|
|
public function getNamespace(): int {
|
2020-12-02 21:49:22 +00:00
|
|
|
// never called
|
|
|
|
|
return -100;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-23 19:15:11 +00:00
|
|
|
$this->expectPHPError(
|
|
|
|
|
E_USER_DEPRECATED,
|
|
|
|
|
static function () use ( $subclassInstance ) {
|
|
|
|
|
MWDebug::detectDeprecatedOverride(
|
|
|
|
|
$subclassInstance,
|
|
|
|
|
TitleValue::class,
|
|
|
|
|
'getNamespace',
|
|
|
|
|
MW_VERSION
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
'@anonymous'
|
2020-12-02 21:49:22 +00:00
|
|
|
);
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeprecated() {
|
2024-02-23 19:15:11 +00:00
|
|
|
$this->expectPHPError(
|
|
|
|
|
E_USER_DEPRECATED,
|
|
|
|
|
static function () {
|
|
|
|
|
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
|
|
|
|
},
|
|
|
|
|
'wfOldFunction'
|
|
|
|
|
);
|
2020-12-02 21:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
/**
|
|
|
|
|
* @doesNotPerformAssertions
|
|
|
|
|
*/
|
|
|
|
|
public function testDeprecatedIgnoreDuplicate() {
|
2023-10-05 04:55:31 +00:00
|
|
|
@MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
2012-01-13 23:07:52 +00:00
|
|
|
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
// If we reach here, than the second one did not throw any deprecation warning.
|
|
|
|
|
// The first one was silenced to seed the ignore logic.
|
2012-01-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
/**
|
|
|
|
|
* @doesNotPerformAssertions
|
|
|
|
|
*/
|
|
|
|
|
public function testDeprecatedIgnoreNonConsecutivesDuplicate() {
|
2023-10-05 04:55:31 +00:00
|
|
|
@MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
|
|
|
|
@MWDebug::warning( 'some warning' );
|
|
|
|
|
@MWDebug::log( 'we could have logged something too' );
|
MWDebug: Add support for native PHP warnings to "Console"
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
2023-10-03 04:30:44 +00:00
|
|
|
// Another deprecation (not silenced)
|
|
|
|
|
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
2012-01-13 23:07:52 +00:00
|
|
|
}
|
2014-06-28 18:35:52 +00:00
|
|
|
|
2023-02-27 08:26:07 +00:00
|
|
|
public function testDebugMsg() {
|
|
|
|
|
$this->overrideConfigValue( MainConfigNames::ShowDebug, true );
|
|
|
|
|
|
|
|
|
|
// Generate a log to be sure there is at least one
|
|
|
|
|
$logger = LoggerFactory::getInstance( 'test-debug-channel' );
|
|
|
|
|
$logger->debug( 'My message', [] );
|
|
|
|
|
$debugLog = (string)MWDebug::getHTMLDebugLog();
|
|
|
|
|
|
|
|
|
|
$this->assertNotSame( '', $debugLog, 'MWDebug::getHTMLDebugLog() should not be an empty string' );
|
|
|
|
|
$this->assertStringNotContainsString( "<ul id=\"mw-debug-html\">\n</ul>", $debugLog,
|
|
|
|
|
'MWDebug::getHTMLDebugLog() should contain a non-empty debug log'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 18:35:52 +00:00
|
|
|
public function testAppendDebugInfoToApiResultXmlFormat() {
|
|
|
|
|
$request = $this->newApiRequest(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'action' => 'help', 'format' => 'xml' ],
|
2014-06-28 18:35:52 +00:00
|
|
|
'/api.php?action=help&format=xml'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$context = new RequestContext();
|
|
|
|
|
$context->setRequest( $request );
|
|
|
|
|
|
2020-03-08 17:17:46 +00:00
|
|
|
$result = new ApiResult( false );
|
2014-06-28 18:35:52 +00:00
|
|
|
|
|
|
|
|
MWDebug::appendDebugInfoToApiResult( $context, $result );
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( ApiResult::class, $result );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$data = $result->getResultData();
|
2014-06-28 18:35:52 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$expectedKeys = [ 'mwVersion', 'phpEngine', 'phpVersion', 'gitRevision', 'gitBranch',
|
2014-06-28 18:35:52 +00:00
|
|
|
'gitViewUrl', 'time', 'log', 'debugLog', 'queries', 'request', 'memory',
|
2016-02-17 09:09:32 +00:00
|
|
|
'memoryPeak', 'includes', '_element' ];
|
2014-06-28 18:35:52 +00:00
|
|
|
|
2014-07-19 21:12:10 +00:00
|
|
|
foreach ( $expectedKeys as $expectedKey ) {
|
2014-06-28 18:35:52 +00:00
|
|
|
$this->assertArrayHasKey( $expectedKey, $data['debuginfo'], "debuginfo has $expectedKey" );
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-08 16:55:52 +00:00
|
|
|
$xml = ApiFormatXml::recXmlPrint( 'help', $data, null );
|
2014-06-28 18:35:52 +00:00
|
|
|
|
|
|
|
|
// exception not thrown
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsString( $xml );
|
2014-06-28 18:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string[] $params
|
|
|
|
|
* @param string $requestUrl
|
|
|
|
|
* @return FauxRequest
|
|
|
|
|
*/
|
|
|
|
|
private function newApiRequest( array $params, $requestUrl ) {
|
2023-10-05 04:55:31 +00:00
|
|
|
$req = new FauxRequest( $params );
|
|
|
|
|
$req->setRequestURL( $requestUrl );
|
|
|
|
|
return $req;
|
2014-06-28 18:35:52 +00:00
|
|
|
}
|
2012-01-13 23:07:52 +00:00
|
|
|
}
|