/** * test handleException() with a keep all filter */ public function testHandleExceptionWithKeepAllFilter() { // GIVEN $this->filter1->expects($this->once())->method('handle')->will($this->returnValue(true)); $this->renderer1->expects($this->once())->method('render')->will($this->returnValue('renderer response')); $exception = new \Exception(); $block = $this->getMockBlock('block.other_type'); // WHEN $response = $this->manager->handleException($exception, $block); // THEN $this->assertNotNull($response, 'should return something'); $this->assertEquals('renderer response', $response, 'should return the renderer response'); }
/** * Test rendering a block that throws an exception. */ public function testRenderBlockWithException() { // GIVEN // mock a block service that throws an user exception $service = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceInterface'); $service->expects($this->once())->method('load'); $exception = $this->getMock('\\Exception'); $service->expects($this->once())->method('execute')->will($this->returnCallback(function () use($exception) { throw $exception; })); $this->blockServiceManager->expects($this->once())->method('get')->will($this->returnValue($service)); // mock the exception strategy manager to return a response when given the correct exception $response = $this->getMock('Symfony\\Component\\HttpFoundation\\Response'); $this->exceptionStrategyManager->expects($this->once())->method('handleException')->with($this->equalTo($exception))->will($this->returnValue($response)); // mock the logger to ensure a crit message is logged $this->logger->expects($this->once())->method('critical'); // mock a block object $block = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface'); $blockContext = new BlockContext($block); // WHEN $result = $this->renderer->render($blockContext); // THEN $this->assertEquals($response, $result, 'Should return the response provider by the exception manager'); }