diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/tests/phpunit/includes/debug/logger/LegacyLoggerTest.php |
first commit
Diffstat (limited to 'www/wiki/tests/phpunit/includes/debug/logger/LegacyLoggerTest.php')
-rw-r--r-- | www/wiki/tests/phpunit/includes/debug/logger/LegacyLoggerTest.php | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/debug/logger/LegacyLoggerTest.php b/www/wiki/tests/phpunit/includes/debug/logger/LegacyLoggerTest.php new file mode 100644 index 00000000..37a28c36 --- /dev/null +++ b/www/wiki/tests/phpunit/includes/debug/logger/LegacyLoggerTest.php @@ -0,0 +1,175 @@ +<?php +/** + * 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + */ + +namespace MediaWiki\Logger; + +use MediaWikiTestCase; +use Psr\Log\LogLevel; + +class LegacyLoggerTest extends MediaWikiTestCase { + + /** + * @covers MediaWiki\Logger\LegacyLogger::interpolate + * @dataProvider provideInterpolate + */ + public function testInterpolate( $message, $context, $expect ) { + $this->assertEquals( + $expect, LegacyLogger::interpolate( $message, $context ) ); + } + + public function provideInterpolate() { + $e = new \Exception( 'boom!' ); + $d = new \DateTime(); + return [ + [ + 'no-op', + [], + 'no-op', + ], + [ + 'Hello {world}!', + [ + 'world' => 'World', + ], + 'Hello World!', + ], + [ + '{greeting} {user}', + [ + 'greeting' => 'Goodnight', + 'user' => 'Moon', + ], + 'Goodnight Moon', + ], + [ + 'Oops {key_not_set}', + [], + 'Oops {key_not_set}', + ], + [ + '{ not interpolated }', + [ + 'not interpolated' => 'This should NOT show up in the message', + ], + '{ not interpolated }', + ], + [ + '{null}', + [ + 'null' => null, + ], + '[Null]', + ], + [ + '{bool}', + [ + 'bool' => true, + ], + 'true', + ], + [ + '{float}', + [ + 'float' => 1.23, + ], + '1.23', + ], + [ + '{array}', + [ + 'array' => [ 1, 2, 3 ], + ], + '[Array(3)]', + ], + [ + '{exception}', + [ + 'exception' => $e, + ], + '[Exception ' . get_class( $e ) . '( ' . + $e->getFile() . ':' . $e->getLine() . ') ' . + $e->getMessage() . ']', + ], + [ + '{datetime}', + [ + 'datetime' => $d, + ], + $d->format( 'c' ), + ], + [ + '{object}', + [ + 'object' => new \stdClass, + ], + '[Object stdClass]', + ], + ]; + } + + /** + * @covers MediaWiki\Logger\LegacyLogger::shouldEmit + * @dataProvider provideShouldEmit + */ + public function testShouldEmit( $level, $config, $expected ) { + $this->setMwGlobals( 'wgDebugLogGroups', [ 'fakechannel' => $config ] ); + $this->assertEquals( + $expected, + LegacyLogger::shouldEmit( 'fakechannel', 'some message', $level, [] ) + ); + } + + public static function provideShouldEmit() { + $dest = [ 'destination' => 'foobar' ]; + $tests = [ + [ + LogLevel::DEBUG, + $dest, + true + ], + [ + LogLevel::WARNING, + $dest + [ 'level' => LogLevel::INFO ], + true, + ], + [ + LogLevel::INFO, + $dest + [ 'level' => LogLevel::CRITICAL ], + false, + ], + ]; + + if ( class_exists( '\Monolog\Logger' ) ) { + $tests[] = [ + \Monolog\Logger::INFO, + $dest + [ 'level' => LogLevel::INFO ], + true, + ]; + $tests[] = [ + \Monolog\Logger::WARNING, + $dest + [ 'level' => LogLevel::EMERGENCY ], + false, + ]; + } + + return $tests; + } + +} |