Type hint against LinkTarget in WatchedItemStore
[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 AssertionError;
24 use InvalidArgumentException;
25 use LengthException;
26 use LogicException;
27 use MediaWikiTestCase;
28 use Wikimedia\TestingAccessWrapper;
29
30 class LineFormatterTest extends MediaWikiTestCase {
31
32 protected function setUp() {
33 if ( !class_exists( 'Monolog\Formatter\LineFormatter' ) ) {
34 $this->markTestSkipped( 'This test requires monolog to be installed' );
35 }
36 parent::setUp();
37 }
38
39 /**
40 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
41 */
42 public function testNormalizeExceptionNoTrace() {
43 $fixture = new LineFormatter();
44 $fixture->includeStacktraces( false );
45 $fixture = TestingAccessWrapper::newFromObject( $fixture );
46 $boom = new InvalidArgumentException( 'boom', 0,
47 new LengthException( 'too long', 0,
48 new LogicException( 'Spock wuz here' )
49 )
50 );
51 $out = $fixture->normalizeException( $boom );
52 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
53 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
54 $this->assertContains( "\nCaused by: [Exception LogicException]", $out );
55 $this->assertNotContains( "\n #0", $out );
56 }
57
58 /**
59 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
60 */
61 public function testNormalizeExceptionTrace() {
62 $fixture = new LineFormatter();
63 $fixture->includeStacktraces( true );
64 $fixture = TestingAccessWrapper::newFromObject( $fixture );
65 $boom = new InvalidArgumentException( 'boom', 0,
66 new LengthException( 'too long', 0,
67 new LogicException( 'Spock wuz here' )
68 )
69 );
70 $out = $fixture->normalizeException( $boom );
71 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
72 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
73 $this->assertContains( "\nCaused by: [Exception LogicException]", $out );
74 $this->assertContains( "\n #0", $out );
75 }
76
77 /**
78 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
79 */
80 public function testNormalizeExceptionErrorNoTrace() {
81 if ( !class_exists( AssertionError::class ) ) {
82 $this->markTestSkipped( 'AssertionError class does not exist' );
83 }
84
85 $fixture = new LineFormatter();
86 $fixture->includeStacktraces( false );
87 $fixture = TestingAccessWrapper::newFromObject( $fixture );
88 $boom = new InvalidArgumentException( 'boom', 0,
89 new LengthException( 'too long', 0,
90 new AssertionError( 'Spock wuz here' )
91 )
92 );
93 $out = $fixture->normalizeException( $boom );
94 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
95 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
96 $this->assertContains( "\nCaused by: [Error AssertionError]", $out );
97 $this->assertNotContains( "\n #0", $out );
98 }
99
100 /**
101 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
102 */
103 public function testNormalizeExceptionErrorTrace() {
104 if ( !class_exists( AssertionError::class ) ) {
105 $this->markTestSkipped( 'AssertionError class does not exist' );
106 }
107
108 $fixture = new LineFormatter();
109 $fixture->includeStacktraces( true );
110 $fixture = TestingAccessWrapper::newFromObject( $fixture );
111 $boom = new InvalidArgumentException( 'boom', 0,
112 new LengthException( 'too long', 0,
113 new AssertionError( 'Spock wuz here' )
114 )
115 );
116 $out = $fixture->normalizeException( $boom );
117 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
118 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
119 $this->assertContains( "\nCaused by: [Error AssertionError]", $out );
120 $this->assertContains( "\n #0", $out );
121 }
122 }