Add more tests for DetailedErrorFormatter

This commit is contained in:
Robbie Averill 2018-10-20 14:41:45 +02:00
parent 73df3166b7
commit 2694a47c45
2 changed files with 45 additions and 2 deletions

View File

@ -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;

View File

@ -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');
}
}