debug: Improve docs, fix ingroup tags, clean up tests
* Remove redundant file-level description and ensure the class desc and ingroup tag are on the class block instead. Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+message:ingroup * Widen `@covers` annotations in unit tests. Ref https://gerrit.wikimedia.org/r/q/owner:krinkle+is:merged+message:covers * Create "Debug" documentation group, covering the debug/ directory. This will show up on doc.wikimedia.org under "Modules", where each class is listed, and the class page will also link back to the group as part of its breadcrumb navigation. Test with `php maintenance/mwdocgen.php --file docs/,includes/debug/` and then view /w/docs/html/ * Improve docs of various classes and explain relationships better. In particular, reformat to ensure each class has a oneline description that captures its essential function. Change-Id: I5d1143a9244b7fd888e1dc31f0fd7965272aa900
This commit is contained in:
parent
2d46dce02a
commit
9cb8bb611b
23 changed files with 171 additions and 117 deletions
|
|
@ -1,3 +1,6 @@
|
|||
Logger {#debuglogger}
|
||||
=======
|
||||
|
||||
MediaWiki.Logger.LoggerFactory implements a [PSR-3] compatible message logging
|
||||
system.
|
||||
|
||||
|
|
@ -40,7 +43,8 @@ configuration of this provider. The default configuration installs a null
|
|||
handler that will silently discard all logging events. The documentation
|
||||
provided by the class describes a more feature rich logging configuration.
|
||||
|
||||
# Classes
|
||||
## Classes
|
||||
|
||||
* MediaWiki.Logger.LoggerFactory: Factory for Psr.Log.LoggerInterface loggers
|
||||
* MediaWiki.Logger.Spi: Service provider interface for
|
||||
MediaWiki.Logger.LoggerFactory
|
||||
|
|
@ -57,9 +61,10 @@ provided by the class describes a more feature rich logging configuration.
|
|||
* MediaWiki.Logger.Monolog.WikiProcessor: Monolog log processor that adds host:
|
||||
wfHostname() and wiki: WikiMap::getCurrentWikiId() to all records
|
||||
|
||||
# Globals
|
||||
* $wgMWLoggerDefaultSpi: Specification for creating the default service provider
|
||||
interface to use with LoggerFactory
|
||||
## Globals
|
||||
|
||||
[PSR-3]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
|
||||
* $wgMWLoggerDefaultSpi: Configure which service provider LoggerFactory will
|
||||
use for creating logger objects.
|
||||
|
||||
[PSR-3]: https://www.php-fig.org/psr/psr-3/
|
||||
[Monolog]: https://github.com/Seldaek/monolog
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ namespace MediaWiki\Debug;
|
|||
use ArrayAccess;
|
||||
|
||||
/**
|
||||
* ArrayAccess implementation that supports deprecating access to certain properties.
|
||||
* ArrayAccess with support for deprecating access to certain offsets.
|
||||
*
|
||||
* It behaves mostly as a normal array, however in order to avoid instantiating
|
||||
* deprecated properties by default, a callable initializer can be set to the property.
|
||||
* It will be executed upon 'get'.
|
||||
* @note setting properties does not emit deprecation warnings.
|
||||
* @note Setting properties does not emit deprecation warnings.
|
||||
*
|
||||
* @newable
|
||||
* @since 1.35
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
* Trait for issuing warnings on deprecated access.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
|
|
@ -21,6 +19,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Trait for issuing warnings on deprecated access.
|
||||
*
|
||||
* Use this trait in classes which have properties for which public access
|
||||
* is deprecated or implementation has been moved to another class.
|
||||
* Set the list of properties in $deprecatedPublicProperties
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
* Debug toolbar related code.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
|
|
@ -30,12 +28,15 @@ use Wikimedia\WrappedString;
|
|||
use Wikimedia\WrappedStringList;
|
||||
|
||||
/**
|
||||
* New debugger system that outputs a toolbar on page view.
|
||||
* Debug toolbar.
|
||||
*
|
||||
* By default, most methods do nothing ( self::$enabled = false ). You have
|
||||
* to explicitly call MWDebug::init() to enabled them.
|
||||
* By default most of these methods do nothing, as enforced by self::$enabled = false.
|
||||
*
|
||||
* To enable the debug toolbar, use $wgDebugToolbar = true in LocalSettings.php.
|
||||
* That ensures MWDebug::init() is called from Setup.php.
|
||||
*
|
||||
* @since 1.19
|
||||
* @ingroup Debug
|
||||
*/
|
||||
class MWDebug {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,9 +8,16 @@ use Psr\Log\LogLevel;
|
|||
use Wikimedia\Assert\Assert;
|
||||
|
||||
/**
|
||||
* A logger which writes to the terminal. The output is supposed to be
|
||||
* human-readable, and should be changed as necessary to better achieve that
|
||||
* goal.
|
||||
* Write logs to command-line output (STDERR).
|
||||
*
|
||||
* The output is supposed to be human-readable, and should be changed as necessary
|
||||
* to better achieve that goal.
|
||||
*
|
||||
* This is developed for use in maintenance/eval.php.
|
||||
*
|
||||
* @internal For use in MediaWiki core only
|
||||
* @since 1.30
|
||||
* @ingroup Debug
|
||||
*/
|
||||
class ConsoleLogger extends AbstractLogger {
|
||||
private const LEVELS = [
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@ namespace MediaWiki\Logger;
|
|||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
* Simple logger SPI for logging to STDERR.
|
||||
* ConsoleLogger service provider for MediaWiki\Logger\LoggerFactory.
|
||||
*
|
||||
* This is developed for use in maintenance/eval.php.
|
||||
*
|
||||
* @internal For use in MediaWiki core only
|
||||
* @since 1.30
|
||||
* @ingroup Debug
|
||||
*/
|
||||
class ConsoleSpi implements Spi {
|
||||
|
||||
|
|
@ -19,7 +25,7 @@ class ConsoleSpi implements Spi {
|
|||
* - channels: (string[]) List of channels to log: channel name => minimum level.
|
||||
* Omit to log everything.
|
||||
* - forwardTo: (Spi) Forward all log messages to this SPI (regardless of whether
|
||||
* ConsoleSPI logs them).
|
||||
* ConsoleSpi logs them).
|
||||
*/
|
||||
public function __construct( array $config = [] ) {
|
||||
$this->channels = $config['channels'] ?? null;
|
||||
|
|
|
|||
|
|
@ -42,10 +42,11 @@ use Wikimedia\AtEase\AtEase;
|
|||
* - `$wgDBerrorLog`
|
||||
* - `$wgDBerrorLogTZ`
|
||||
*
|
||||
* See docs/Configuration.ms for detailed explanations of these settings.
|
||||
* See docs/Configuration.md for detailed explanations of these settings.
|
||||
*
|
||||
* @see \MediaWiki\Logger\LoggerFactory
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2014 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class LegacyLogger extends AbstractLogger {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ namespace MediaWiki\Logger;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* LoggerFactory service provider that creates LegacyLogger instances.
|
||||
* The default service provider for MediaWiki\Logger\LoggerFactory, which creates
|
||||
* LegacyLogger objects.
|
||||
*
|
||||
* Usage:
|
||||
* @code
|
||||
|
|
@ -32,8 +33,8 @@ use Psr\Log\LoggerInterface;
|
|||
* ];
|
||||
* @endcode
|
||||
*
|
||||
* @see \MediaWiki\Logger\LoggerFactory
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2014 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class LegacySpi implements Spi {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,13 @@ use Psr\Log\AbstractLogger;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Wraps another spi to capture all logs generated. This can be
|
||||
* used, for example, to collect all logs generated during a
|
||||
* unit test and report them when the test fails.
|
||||
* Wrap another Spi and keep a copy of all log messages.
|
||||
*
|
||||
* This is developed for use by PHPUnit bootstrapping, to collect logs
|
||||
* generated during a given unit test, and print them after a failing test.
|
||||
*
|
||||
* @internal For use in MediaWiki core only
|
||||
* @ingroup Debug
|
||||
*/
|
||||
class LogCapturingSpi implements Spi {
|
||||
/** @var LoggerInterface[] */
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace MediaWiki\Logger;
|
|||
use Wikimedia\ObjectFactory\ObjectFactory;
|
||||
|
||||
/**
|
||||
* PSR-3 logger instance factory.
|
||||
* Create PSR-3 logger objects.
|
||||
*
|
||||
* Creation of \Psr\Log\LoggerInterface instances is managed via the
|
||||
* LoggerFactory::getInstance() static method which in turn delegates to the
|
||||
|
|
@ -38,8 +38,8 @@ use Wikimedia\ObjectFactory\ObjectFactory;
|
|||
* $wgMWLoggerDefaultSpi is expected to be an array usable by
|
||||
* ObjectFactory::getObjectFromSpec() to create a class.
|
||||
*
|
||||
* @see \MediaWiki\Logger\Spi
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2014 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class LoggerFactory {
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ use Wikimedia\ObjectFactory\ObjectFactory;
|
|||
*
|
||||
* @see https://github.com/Seldaek/monolog
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2014 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class MonologSpi implements Spi {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ use Psr\Log\NullLogger;
|
|||
*
|
||||
* @see \MediaWiki\Logger\LoggerFactory
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2014 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class NullSpi implements Spi {
|
||||
|
|
|
|||
|
|
@ -21,18 +21,44 @@
|
|||
namespace MediaWiki\Logger;
|
||||
|
||||
/**
|
||||
* Service provider interface for \Psr\Log\LoggerInterface implementation
|
||||
* libraries.
|
||||
* @defgroup Debug Debug logging
|
||||
*
|
||||
* MediaWiki can be configured to use a class implementing this interface to
|
||||
* create new \Psr\Log\LoggerInterface instances via either the
|
||||
* $wgMWLoggerDefaultSpi global variable or code that constructs an instance
|
||||
* and registers it via the LoggerFactory::registerProvider() static method.
|
||||
* To primary APIs for this feature, and the classes where their documentation
|
||||
* starts, are:
|
||||
*
|
||||
* - MediaWiki\Logger\LoggerFactory, this is creates all logger objects at
|
||||
* run time.
|
||||
*
|
||||
* - MediaWiki\Logger\Spi, to develop or configure the service classes
|
||||
* that internally create logger objects. For example, MediaWiki\Logger\LegacyLogger
|
||||
* is the default Spi that backs features like $wgDebugLogFile.
|
||||
* MediaWiki\Logger\MonologSpi is an Spi you can opt-in to via $wgMWLoggerDefaultSpi
|
||||
* to enable structured logging with destionations like Syslog and Logstash,
|
||||
* and "processor" and "formatter" features to augment messages with metadata,
|
||||
* as powered by the Monolog library.
|
||||
*
|
||||
* - MWDebug, the logic behind $wgDebugToolbar.
|
||||
*
|
||||
* @see [Logger documentation](@ref debuglogger) in docs/Logger.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* Service provider interface to create \Psr\Log\LoggerInterface objects.
|
||||
*
|
||||
* MediaWiki can be configured to use a class implementing this interface
|
||||
* via the $wgMWLoggerDefaultSpi configuration variable.
|
||||
*
|
||||
* This configuration is consumed by MediaWiki\Logger\LoggerFactory, which is
|
||||
* where we create logger objects.
|
||||
*
|
||||
* While not recommended in production code, you can construct and install
|
||||
* an Spi class at runtime via MediaWiki\Logger\LoggerFactory::registerProvider
|
||||
* (e.g. to power debug features in PHPUnit bootstrapping, or Maintenance
|
||||
* scripts).
|
||||
*
|
||||
* @see \MediaWiki\Logger\LoggerFactory
|
||||
* @stable to implement
|
||||
*
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2014 Wikimedia Foundation and contributors
|
||||
*/
|
||||
interface Spi {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper class for the index.php entry point.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
|
|
@ -26,11 +24,18 @@ use DeferredUpdates;
|
|||
use Monolog\Handler\BufferHandler as BaseBufferHandler;
|
||||
|
||||
/**
|
||||
* Helper class for the index.php entry point.
|
||||
*
|
||||
* Updates \Monolog\Handler\BufferHandler to use DeferredUpdates rather
|
||||
* than register_shutdown_function. On supported platforms this will
|
||||
* use register_postsend_function or fastcgi_finish_request() to delay
|
||||
* until after the request has shutdown and we are no longer delaying
|
||||
* the web request.
|
||||
*
|
||||
* TODO: shutdown is later than postsend. Is this class still useful?
|
||||
*
|
||||
* @since 1.26
|
||||
* @ingroup Debug
|
||||
*/
|
||||
class BufferHandler extends BaseBufferHandler {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@
|
|||
namespace MediaWiki\Logger\Monolog;
|
||||
|
||||
/**
|
||||
* CeeFormatter extends LogstashFormatter to prefix records with a "cee cookie".
|
||||
* The cookie is used to tell JSON and non-JSON messages apart when logging to syslog.
|
||||
* Prefixed version of LogstashFormatter that adds a "cee cookie" for Rsyslog.
|
||||
*
|
||||
* The prefix lets Ryslog differentiate between JSON and non-JSON messages.
|
||||
*
|
||||
* See also: https://www.rsyslog.com/doc/v8-stable/configuration/modules/mmjsonparse.html
|
||||
*
|
||||
* @since 1.33
|
||||
* @ingroup Debug
|
||||
*/
|
||||
class CeeFormatter extends LogstashFormatter {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ use Monolog\Formatter\NormalizerFormatter;
|
|||
*
|
||||
* @deprecated since 1.32
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2013 Wikimedia Foundation and contributors
|
||||
* @see \MediaWiki\Logger\LegacyLogger
|
||||
*/
|
||||
class LegacyFormatter extends NormalizerFormatter {
|
||||
|
||||
|
|
|
|||
|
|
@ -28,23 +28,33 @@ use Socket;
|
|||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* Log handler that replicates the behavior of MediaWiki's former wfErrorLog()
|
||||
* logging service. Log output can be directed to a local file, a PHP stream,
|
||||
* or a udp2log server.
|
||||
* Monolog imitation of MediaWiki\Logger\LegacyLogger
|
||||
*
|
||||
* This replicates the behavior of LegacyLogger, which in turn replicates
|
||||
* MediaWiki's former wfErrorLog() function.
|
||||
*
|
||||
* The main use case of the LegacyHandler is to enable adoption of Monolog
|
||||
* features (such as alternate formatters, extra processors, and enabling multiple
|
||||
* destinations/handlers at the same time), where one of the handlers (this one)
|
||||
* essentiallly does what the LegacySpi would do if you hadn't enabled
|
||||
* MonologSpi. In particular: writing to a file like $wgDebugLogFile,
|
||||
* and sending messages to a PHP stream or udp2log server.
|
||||
*
|
||||
* For udp2log output, the stream specification must have the form:
|
||||
* "udp://HOST:PORT[/PREFIX]"
|
||||
* where:
|
||||
*
|
||||
* - HOST: IPv4, IPv6 or hostname
|
||||
* - PORT: server port
|
||||
* - PREFIX: optional (but recommended) prefix telling udp2log how to route
|
||||
* the log event. The special prefix "{channel}" will use the log event's
|
||||
* channel as the prefix value.
|
||||
* the log event. The special prefix "{channel}" will use the log event's
|
||||
* channel as the prefix value.
|
||||
*
|
||||
* When not targeting a udp2log stream this class will act as a drop-in
|
||||
* When not targeting a udp2log server, this class will act as a drop-in
|
||||
* replacement for \Monolog\Handler\StreamHandler.
|
||||
*
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2013 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class LegacyHandler extends AbstractProcessingHandler {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ use Throwable;
|
|||
* will be used to redact the trace information.
|
||||
*
|
||||
* @since 1.26
|
||||
* @ingroup Debug
|
||||
* @copyright © 2015 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class LineFormatter extends MonologLineFormatter {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
namespace MediaWiki\Logger\Monolog;
|
||||
|
||||
/**
|
||||
* LogstashFormatter squashes the base message array and the context and extras subarrays into one.
|
||||
* This can result in unfortunately named context fields overwriting other data (T145133).
|
||||
* This class modifies the standard LogstashFormatter to rename such fields and flag the message.
|
||||
* Also changes exception JSON-ification which is done poorly by the standard class.
|
||||
* Modified version of Monolog\Formatter\LogstashFormatter
|
||||
*
|
||||
* - Squash the base message array, the context and extra subarrays into one.
|
||||
* This can result in unfortunately named context fields overwriting other data (T145133).
|
||||
* - Improve exception JSON-ification, which is done poorly by the standard class.
|
||||
*
|
||||
* @since 1.29
|
||||
* @ingroup Debug
|
||||
*/
|
||||
class LogstashFormatter extends \Monolog\Formatter\LogstashFormatter {
|
||||
|
||||
|
|
|
|||
|
|
@ -24,14 +24,24 @@ use Monolog\Handler\SyslogUdpHandler;
|
|||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Log handler that will append the record's channel to a fixed 'application
|
||||
* prefix' given at construction time.
|
||||
* Write logs to syslog with the channel appended to the application name.
|
||||
*
|
||||
* The use case for this handler is to deprecate udp2log with a localhost
|
||||
* syslog endpoint. The application name is then used to reconstruct the
|
||||
* message's channel.
|
||||
* This use case for this handler is to emulate Wikimedia Foundation's
|
||||
* udp2log system by leveraging syslog (and e.g. Rsyslog/Kafka) and
|
||||
* allow an unstructured string to pass through mostly as-is, with the
|
||||
* exception of the channel name, which is encoded in transit as part
|
||||
* of the syslog "application name". It is intended that the syslog
|
||||
* consumer "wildcard" subscribes to all messages with the app prefix,
|
||||
* and then * strips it off at some point before writing the messages
|
||||
* to a log file named after the channel.
|
||||
*
|
||||
* Transition plan (2016):
|
||||
* - https://phabricator.wikimedia.org/T205856#4957430
|
||||
* - https://phabricator.wikimedia.org/T126989
|
||||
*
|
||||
* @unstable
|
||||
* @since 1.32
|
||||
* @ingroup Debug
|
||||
* @copyright © 2019 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class MwlogHandler extends SyslogUdpHandler {
|
||||
|
|
|
|||
|
|
@ -25,18 +25,19 @@ use Monolog\Handler\SyslogUdpHandler;
|
|||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Log handler that supports sending log events to a syslog server using RFC
|
||||
* 3164 formatted UDP packets.
|
||||
* Write logs to a syslog server, using RFC 3164 formatted UDP packets.
|
||||
*
|
||||
* Monolog's SyslogUdpHandler creates a partial RFC 5424 header (PRI and
|
||||
* VERSION) and relies on the associated formatter to complete the header and
|
||||
* message payload. This makes using it with a fixed format formatter like
|
||||
* \Monolog\Formatter\LogstashFormatter impossible. Additionally, the
|
||||
* direct syslog input for Logstash only handles RFC 3164 syslog packets.
|
||||
* This builds on Monolog's SyslogUdpHandler, which creates only a partial
|
||||
* RFC 5424 header (PRI and VERSION), with rest intending to come
|
||||
* from a specifically configured LineFormatter.
|
||||
*
|
||||
* This Handler should work with any Formatter. The formatted message will be
|
||||
* prepended with an RFC 3164 message header and a partial message body. The
|
||||
* resulting packet will looks something like:
|
||||
* This makes use of SyslogUdpHandler it impossible with a formatter like
|
||||
* \Monolog\Formatter\LogstashFormatter. Additionally, the direct syslog
|
||||
* input for Logstash requires and accepts only RFC 3164 formatted packets.
|
||||
*
|
||||
* This is a complete syslog handler and should work with any formatter. The
|
||||
* formatted message will be prepended with a complete RFC 3164 message
|
||||
* header and a partial message body. The resulting packet looks like:
|
||||
*
|
||||
* <PRI>DATETIME HOSTNAME PROGRAM: MESSAGE
|
||||
*
|
||||
|
|
@ -44,19 +45,13 @@ use Monolog\Logger;
|
|||
* default Logstash syslog input handler.
|
||||
*
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2015 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class SyslogHandler extends SyslogUdpHandler {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $appname;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $hostname;
|
||||
private string $appname;
|
||||
private string $hostname;
|
||||
|
||||
/**
|
||||
* @param string $appname Application name to report to syslog
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use MediaWiki\WikiMap\WikiMap;
|
|||
* wiki / request ID, and MediaWiki version.
|
||||
*
|
||||
* @since 1.25
|
||||
* @ingroup Debug
|
||||
* @copyright © 2013 Wikimedia Foundation and contributors
|
||||
*/
|
||||
class WikiProcessor {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
use MediaWiki\Request\FauxRequest;
|
||||
use MediaWiki\Title\TitleValue;
|
||||
use Wikimedia\AtEase\AtEase;
|
||||
|
||||
/**
|
||||
* @covers MWDebug
|
||||
*/
|
||||
class MWDebugTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
@ -15,20 +17,15 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
|
|||
public static function setUpBeforeClass(): void {
|
||||
parent::setUpBeforeClass();
|
||||
MWDebug::init();
|
||||
AtEase::suppressWarnings();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void {
|
||||
MWDebug::deinit();
|
||||
AtEase::restoreWarnings();
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MWDebug::log
|
||||
*/
|
||||
public function testAddLog() {
|
||||
MWDebug::log( 'logging a string' );
|
||||
@MWDebug::log( 'logging a string' );
|
||||
$this->assertEquals(
|
||||
[ [
|
||||
'msg' => 'logging a string',
|
||||
|
|
@ -39,11 +36,8 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MWDebug::warning
|
||||
*/
|
||||
public function testAddWarning() {
|
||||
MWDebug::warning( 'Warning message' );
|
||||
@MWDebug::warning( 'Warning message' );
|
||||
$this->assertEquals(
|
||||
[ [
|
||||
'msg' => 'Warning message',
|
||||
|
|
@ -54,9 +48,6 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MWDebug::detectDeprecatedOverride
|
||||
*/
|
||||
public function testDetectDeprecatedOverride() {
|
||||
$baseclassInstance = new TitleValue( NS_MAIN, 'Test' );
|
||||
|
||||
|
|
@ -78,7 +69,7 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
|
|||
};
|
||||
|
||||
$this->assertTrue(
|
||||
MWDebug::detectDeprecatedOverride(
|
||||
@MWDebug::detectDeprecatedOverride(
|
||||
$subclassInstance,
|
||||
TitleValue::class,
|
||||
'getNamespace',
|
||||
|
|
@ -90,36 +81,27 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertCount( 1, MWDebug::getLog() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MWDebug::deprecated
|
||||
*/
|
||||
public function testAvoidDuplicateDeprecations() {
|
||||
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
@MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
@MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
|
||||
$this->assertCount( 1, MWDebug::getLog(),
|
||||
"Only one deprecated warning per function should be kept"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MWDebug::deprecated
|
||||
*/
|
||||
public function testAvoidNonConsecutivesDuplicateDeprecations() {
|
||||
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
MWDebug::warning( 'some warning' );
|
||||
MWDebug::log( 'we could have logged something too' );
|
||||
@MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
@MWDebug::warning( 'some warning' );
|
||||
@MWDebug::log( 'we could have logged something too' );
|
||||
// Another deprecation
|
||||
MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
@MWDebug::deprecated( 'wfOldFunction', '1.0', 'component' );
|
||||
|
||||
$this->assertCount( 3, MWDebug::getLog(),
|
||||
"Only one deprecated warning per function should be kept"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MWDebug::appendDebugInfoToApiResult
|
||||
*/
|
||||
public function testAppendDebugInfoToApiResultXmlFormat() {
|
||||
$request = $this->newApiRequest(
|
||||
[ 'action' => 'help', 'format' => 'xml' ],
|
||||
|
|
@ -153,21 +135,11 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
|
|||
/**
|
||||
* @param string[] $params
|
||||
* @param string $requestUrl
|
||||
*
|
||||
* @return FauxRequest
|
||||
*/
|
||||
private function newApiRequest( array $params, $requestUrl ) {
|
||||
$request = $this->getMockBuilder( FauxRequest::class )
|
||||
->onlyMethods( [ 'getRequestURL' ] )
|
||||
->setConstructorArgs( [
|
||||
$params
|
||||
] )
|
||||
->getMock();
|
||||
|
||||
$request->method( 'getRequestURL' )
|
||||
->willReturn( $requestUrl );
|
||||
|
||||
return $request;
|
||||
$req = new FauxRequest( $params );
|
||||
$req->setRequestURL( $requestUrl );
|
||||
return $req;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue