Merge "Add tests for WikiMap and WikiReference"
[lhc/web/wiklou.git] / tests / phpunit / includes / debug / logger / monolog / LineFormatterTest.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\Monolog;
22
23 use InvalidArgumentException;
24 use LengthException;
25 use LogicException;
26 use MediaWikiTestCase;
27 use TestingAccessWrapper;
28
29 class LineFormatterTest extends MediaWikiTestCase {
30
31 public function setUp() {
32 if ( !class_exists( 'Monolog\Formatter\LineFormatter' ) ) {
33 $this->markTestSkipped( 'This test requires monolog to be installed' );
34 }
35 parent::setUp();
36 }
37
38 /**
39 * @covers LineFormatter::normalizeException
40 */
41 public function testNormalizeExceptionNoTrace() {
42 $fixture = new LineFormatter();
43 $fixture->includeStacktraces( false );
44 $fixture = TestingAccessWrapper::newFromObject( $fixture );
45 $boom = new InvalidArgumentException( 'boom', 0,
46 new LengthException( 'too long', 0,
47 new LogicException( 'Spock wuz here' )
48 )
49 );
50 $out = $fixture->normalizeException( $boom );
51 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
52 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
53 $this->assertContains( "\nCaused by: [Exception LogicException]", $out );
54 $this->assertNotContains( "\n #0", $out );
55 }
56
57 /**
58 * @covers LineFormatter::normalizeException
59 */
60 public function testNormalizeExceptionTrace() {
61 $fixture = new LineFormatter();
62 $fixture->includeStacktraces( true );
63 $fixture = TestingAccessWrapper::newFromObject( $fixture );
64 $boom = new InvalidArgumentException( 'boom', 0,
65 new LengthException( 'too long', 0,
66 new LogicException( 'Spock wuz here' )
67 )
68 );
69 $out = $fixture->normalizeException( $boom );
70 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
71 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
72 $this->assertContains( "\nCaused by: [Exception LogicException]", $out );
73 $this->assertContains( "\n #0", $out );
74 }
75 }