diff --git a/tests/php/Logging/DebugViewFriendlyErrorFormatterTest.php b/tests/php/Logging/DebugViewFriendlyErrorFormatterTest.php index 04f2c64c1..0b40bcf38 100644 --- a/tests/php/Logging/DebugViewFriendlyErrorFormatterTest.php +++ b/tests/php/Logging/DebugViewFriendlyErrorFormatterTest.php @@ -6,7 +6,6 @@ use PHPUnit_Framework_MockObject_MockObject; use SilverStripe\Control\Email\Email; use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\DebugView; use SilverStripe\Dev\SapphireTest; use SilverStripe\Logging\DebugViewFriendlyErrorFormatter; diff --git a/tests/php/Logging/DetailedErrorFormatterTest.php b/tests/php/Logging/DetailedErrorFormatterTest.php index 40f9b75a7..b36786f81 100644 --- a/tests/php/Logging/DetailedErrorFormatterTest.php +++ b/tests/php/Logging/DetailedErrorFormatterTest.php @@ -8,7 +8,7 @@ use SilverStripe\Logging\Tests\DetailedErrorFormatterTest\ErrorGenerator; class DetailedErrorFormatterTest extends SapphireTest { - public function testFormat() + public function testFormatWithException() { $generator = new ErrorGenerator(); $formatter = new DetailedErrorFormatter(); @@ -27,4 +27,48 @@ class DetailedErrorFormatterTest extends SapphireTest $output ); } + + public function testFormatWithoutException() + { + $record = [ + 'code' => 401, + 'message' => 'Denied', + 'file' => 'index.php', + 'line' => 4, + ]; + + $formatter = new DetailedErrorFormatter(); + $result = $formatter->format($record); + + $this->assertContains('ERRNO 401', $result, 'Status code was not found in trace'); + $this->assertContains('Denied', $result, 'Message was not found in trace'); + $this->assertContains('Line 4 in index.php', $result, 'Line or filename were not found in trace'); + $this->assertContains(self::class, $result, 'Backtrace doesn\'t show current test class'); + } + + public function testFormatBatch() + { + $records = [ + [ + 'code' => 401, + 'message' => 'Denied', + 'file' => 'index.php', + 'line' => 4, + ], + [ + 'code' => 404, + 'message' => 'Not found', + 'file' => 'admin.php', + 'line' => 7, + ], + ]; + + $formatter = new DetailedErrorFormatter(); + $result = $formatter->formatBatch($records); + + $this->assertContains('ERRNO 401', $result, 'First status code was not found in trace'); + $this->assertContains('ERRNO 404', $result, 'Second status code was not found in trace'); + $this->assertContains('Denied', $result, 'First message was not found in trace'); + $this->assertContains('Not found', $result, 'Second message was not found in trace'); + } }