/** * Render the template with context data and automatically add to response * * @param array $context * * @return string */ public function render(array $context = []) { $rendered = parent::render($context); if ($this->response) { $this->response->setBody($rendered); } return $rendered; }
public function testContextIsMergedOnRenderIfProvided() { $realTwig = Mockery::mock('Twig_Template', ['render' => null]); $env = Mockery::mock('Twig_Environment', ['loadTemplate' => $realTwig]); $context = new Context(); $twig = new LazyTwig($env, $context, 'path/to/template/file'); $twig->render(['goobypls' => 'test']); $this->assertSame('test', $context->get('goobypls')); }