Type hint against LinkTarget in WatchedItemStore
[lhc/web/wiklou.git] / tests / phpunit / includes / debug / logger / monolog / LineFormatterTest.php
index f12cf5b..bdd5c81 100644 (file)
 
 namespace MediaWiki\Logger\Monolog;
 
+use AssertionError;
 use InvalidArgumentException;
 use LengthException;
 use LogicException;
 use MediaWikiTestCase;
-use TestingAccessWrapper;
+use Wikimedia\TestingAccessWrapper;
 
 class LineFormatterTest extends MediaWikiTestCase {
 
-       public function setUp() {
+       protected function setUp() {
                if ( !class_exists( 'Monolog\Formatter\LineFormatter' ) ) {
                        $this->markTestSkipped( 'This test requires monolog to be installed' );
                }
@@ -36,7 +37,7 @@ class LineFormatterTest extends MediaWikiTestCase {
        }
 
        /**
-        * @covers LineFormatter::normalizeException
+        * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
         */
        public function testNormalizeExceptionNoTrace() {
                $fixture = new LineFormatter();
@@ -48,14 +49,14 @@ class LineFormatterTest extends MediaWikiTestCase {
                        )
                );
                $out = $fixture->normalizeException( $boom );
-               $this->assertContains( '[Exception InvalidArgumentException]', $out );
-               $this->assertContains( ', [Exception LengthException]', $out );
-               $this->assertContains( ', [Exception LogicException]', $out );
-               $this->assertNotContains( '[stacktrace]', $out );
+               $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
+               $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
+               $this->assertContains( "\nCaused by: [Exception LogicException]", $out );
+               $this->assertNotContains( "\n  #0", $out );
        }
 
        /**
-        * @covers LineFormatter::normalizeException
+        * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
         */
        public function testNormalizeExceptionTrace() {
                $fixture = new LineFormatter();
@@ -67,9 +68,55 @@ class LineFormatterTest extends MediaWikiTestCase {
                        )
                );
                $out = $fixture->normalizeException( $boom );
-               $this->assertContains( '[Exception InvalidArgumentException', $out );
-               $this->assertContains( ', [Exception LengthException]', $out );
-               $this->assertContains( ', [Exception LogicException]', $out );
-               $this->assertContains( '[stacktrace]', $out );
+               $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
+               $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
+               $this->assertContains( "\nCaused by: [Exception LogicException]", $out );
+               $this->assertContains( "\n  #0", $out );
+       }
+
+       /**
+        * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
+        */
+       public function testNormalizeExceptionErrorNoTrace() {
+               if ( !class_exists( AssertionError::class ) ) {
+                       $this->markTestSkipped( 'AssertionError class does not exist' );
+               }
+
+               $fixture = new LineFormatter();
+               $fixture->includeStacktraces( false );
+               $fixture = TestingAccessWrapper::newFromObject( $fixture );
+               $boom = new InvalidArgumentException( 'boom', 0,
+                       new LengthException( 'too long', 0,
+                               new AssertionError( 'Spock wuz here' )
+                       )
+               );
+               $out = $fixture->normalizeException( $boom );
+               $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
+               $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
+               $this->assertContains( "\nCaused by: [Error AssertionError]", $out );
+               $this->assertNotContains( "\n  #0", $out );
+       }
+
+       /**
+        * @covers MediaWiki\Logger\Monolog\LineFormatter::normalizeException
+        */
+       public function testNormalizeExceptionErrorTrace() {
+               if ( !class_exists( AssertionError::class ) ) {
+                       $this->markTestSkipped( 'AssertionError class does not exist' );
+               }
+
+               $fixture = new LineFormatter();
+               $fixture->includeStacktraces( true );
+               $fixture = TestingAccessWrapper::newFromObject( $fixture );
+               $boom = new InvalidArgumentException( 'boom', 0,
+                       new LengthException( 'too long', 0,
+                               new AssertionError( 'Spock wuz here' )
+                       )
+               );
+               $out = $fixture->normalizeException( $boom );
+               $this->assertContains( "\n[Exception InvalidArgumentException]", $out );
+               $this->assertContains( "\nCaused by: [Exception LengthException]", $out );
+               $this->assertContains( "\nCaused by: [Error AssertionError]", $out );
+               $this->assertContains( "\n  #0", $out );
        }
 }