set('admin_email', 'testy@mctest.face'); } public function testFormatPassesRecordCodeToOutput() { /** @var DebugViewFriendlyErrorFormatter|MockObject $mock */ $mock = $this->getMockBuilder(DebugViewFriendlyErrorFormatter::class) ->setMethods(['output']) ->getMock(); $mock->expects($this->once())->method('output')->with(403)->willReturn('foo'); $this->assertSame('foo', $mock->format(['code' => 403])); } public function testFormatPassesInstanceStatusCodeToOutputWhenNotProvidedByRecord() { /** @var DebugViewFriendlyErrorFormatter|MockObject $mock */ $mock = $this->getMockBuilder(DebugViewFriendlyErrorFormatter::class) ->setMethods(['output']) ->getMock(); $mock->setStatusCode(404); $mock->expects($this->once())->method('output')->with(404)->willReturn('foo'); $this->assertSame('foo', $mock->format(['notacode' => 'bar'])); } public function testFormatBatch() { $records = [ ['message' => 'bar'], ['open' => 'sausage'], ['horse' => 'caballo'], ]; /** @var DebugViewFriendlyErrorFormatter|MockObject $mock */ $mock = $this->getMockBuilder(DebugViewFriendlyErrorFormatter::class) ->setMethods(['format']) ->getMock(); $mock->expects($this->exactly(3)) ->method('format') ->willReturn('foo'); $this->assertSame('foofoofoo', $mock->formatBatch($records)); } public function testOutput() { $formatter = new DebugViewFriendlyErrorFormatter(); $formatter->setTitle("There has been an error"); $formatter->setBody("The website server has not been able to respond to your request"); $expected = <<assertEquals($expected, $formatter->output(404)); } public function testOutputReturnsTitleWhenRequestIsAjax() { // Mock an AJAX request Injector::inst()->registerService(new HTTPRequest('GET', '', ['ajax' => true])); $formatter = new DebugViewFriendlyErrorFormatter(); $formatter->setTitle('The Diary of Anne Frank'); $this->assertSame('The Diary of Anne Frank', $formatter->output(200)); } public function testAdminEmailWithName() { Email::config()->set('admin_email', ['testy@mctest.face' => 'The ad&min']); $formatter = new DebugViewFriendlyErrorFormatter(); $formatter->setTitle("There has been an error"); $formatter->setBody("The website server has not been able to respond to your request"); $expected = <<assertEquals($expected, $formatter->output(404)); } }