Merge "Mostly revert "Verify parameter for MapCacheLRU::has() can be passed to array_...
[lhc/web/wiklou.git] / tests / phpunit / includes / debug / logging / LegacyLoggerTest.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Logger;
22
23 use MediaWikiTestCase;
24 use Psr\Log\LogLevel;
25
26 class LegacyLoggerTest extends MediaWikiTestCase {
27
28 /**
29 * @covers LegacyLogger::interpolate
30 * @dataProvider provideInterpolate
31 */
32 public function testInterpolate( $message, $context, $expect ) {
33 $this->assertEquals(
34 $expect, LegacyLogger::interpolate( $message, $context ) );
35 }
36
37 public function provideInterpolate() {
38 return array(
39 array(
40 'no-op',
41 array(),
42 'no-op',
43 ),
44 array(
45 'Hello {world}!',
46 array(
47 'world' => 'World',
48 ),
49 'Hello World!',
50 ),
51 array(
52 '{greeting} {user}',
53 array(
54 'greeting' => 'Goodnight',
55 'user' => 'Moon',
56 ),
57 'Goodnight Moon',
58 ),
59 array(
60 'Oops {key_not_set}',
61 array(),
62 'Oops {key_not_set}',
63 ),
64 array(
65 '{ not interpolated }',
66 array(
67 'not interpolated' => 'This should NOT show up in the message',
68 ),
69 '{ not interpolated }',
70 ),
71 );
72 }
73
74 /**
75 * @covers LegacyLogger::shouldEmit
76 * @dataProvider provideShouldEmit
77 */
78 public function testShouldEmit( $level, $config, $expected ) {
79 $this->setMwGlobals( 'wgDebugLogGroups', array( 'fakechannel' => $config ) );
80 $this->assertEquals(
81 $expected,
82 LegacyLogger::shouldEmit( 'fakechannel', 'some message', $level, array() )
83 );
84 }
85
86 public static function provideShouldEmit() {
87 $dest = array( 'destination' => 'foobar' );
88 $tests = array(
89 array(
90 LogLevel::DEBUG,
91 $dest,
92 true
93 ),
94 array(
95 LogLevel::WARNING,
96 $dest + array( 'level' => LogLevel::INFO ),
97 true,
98 ),
99 array(
100 LogLevel::INFO,
101 $dest + array( 'level' => LogLevel::CRITICAL ),
102 false,
103 ),
104 );
105
106 if ( class_exists( '\Monolog\Logger' ) ) {
107 $tests[] = array(
108 \Monolog\Logger::INFO,
109 $dest + array( 'level' => LogLevel::INFO ),
110 true,
111 );
112 $tests[] = array(
113 \Monolog\Logger::WARNING,
114 $dest + array( 'level' => LogLevel::EMERGENCY ),
115 false,
116 );
117 }
118
119 return $tests;
120 }
121
122 }