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.
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.
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
21 namespace MediaWiki\Logger\Monolog
;
24 use InvalidArgumentException
;
27 use Wikimedia\TestingAccessWrapper
;
29 class LineFormatterTest
extends \MediaWikiUnitTestCase
{
31 protected function setUp() {
32 if ( !class_exists( 'Monolog\Formatter\LineFormatter' ) ) {
33 $this->markTestSkipped( 'This test requires monolog to be installed' );
39 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
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' )
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 );
58 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
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' )
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 );
77 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
79 public function testNormalizeExceptionErrorNoTrace() {
80 if ( !class_exists( AssertionError
::class ) ) {
81 $this->markTestSkipped( 'AssertionError class does not exist' );
84 $fixture = new LineFormatter();
85 $fixture->includeStacktraces( false );
86 $fixture = TestingAccessWrapper
::newFromObject( $fixture );
87 $boom = new InvalidArgumentException( 'boom', 0,
88 new LengthException( 'too long', 0,
89 new AssertionError( 'Spock wuz here' )
92 $out = $fixture->normalizeException( $boom );
93 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
94 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
95 $this->assertContains( "\nCaused by: [Error AssertionError]", $out );
96 $this->assertNotContains( "\n #0", $out );
100 * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
102 public function testNormalizeExceptionErrorTrace() {
103 if ( !class_exists( AssertionError
::class ) ) {
104 $this->markTestSkipped( 'AssertionError class does not exist' );
107 $fixture = new LineFormatter();
108 $fixture->includeStacktraces( true );
109 $fixture = TestingAccessWrapper
::newFromObject( $fixture );
110 $boom = new InvalidArgumentException( 'boom', 0,
111 new LengthException( 'too long', 0,
112 new AssertionError( 'Spock wuz here' )
115 $out = $fixture->normalizeException( $boom );
116 $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
117 $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
118 $this->assertContains( "\nCaused by: [Error AssertionError]", $out );
119 $this->assertContains( "\n #0", $out );