public function setupRenderer() { if (!$this->helpers) { $this->setupHelpers(); } $this->renderer = $renderer = new JsonLDRenderer(new ApiProblemRenderer()); $renderer->setHelperPluginManager($this->helpers); }
/** * @param ServiceLocatorInterface $serviceLocator * @return JsonLDRenderer */ public function createService(ServiceLocatorInterface $serviceLocator) { $helpers = $serviceLocator->get('ViewHelperManager'); $apiProblemRenderer = $serviceLocator->get('ZF\\ApiProblem\\ApiProblemRenderer'); $renderer = new JsonLDRenderer($apiProblemRenderer); $renderer->setHelperPluginManager($helpers); return $renderer; }
public function testRenderGivenHalJsonModelReturningApiProblemShouldReturnApiProblemInJsonFormat() { $jsonLDCollection = new Collection([]); $model = new JsonLDModel(['payload' => $jsonLDCollection]); $apiProblem = new ApiProblem(500, 'error'); $helperPluginManager = $this->getHelperPluginManager(); $jsonLDPlugin = $helperPluginManager->get('JsonLD'); $jsonLDPlugin->expects($this->once())->method('renderCollection')->with($jsonLDCollection)->will($this->returnValue($apiProblem)); $this->renderer->setHelperPluginManager($helperPluginManager); $rendered = $this->renderer->render($model); $apiProblemData = ['type' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html', 'title' => 'Internal Server Error', 'status' => 500, 'detail' => 'error']; $this->assertEquals($apiProblemData, json_decode($rendered, true)); }