Skip to content

Commit

Permalink
[FrameworkBundle] Improve the DX of TemplateController when using SF 4
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 1, 2017
1 parent 5b360e2 commit 6d15055
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Expand Up @@ -67,4 +67,9 @@ public function templateAction(string $template, int $maxAge = null, int $shared

return $response;
}

public function __invoke(string $template, int $maxAge = null, int $sharedAge = null, bool $private = null): Response
{
return $this->templateAction($template, $maxAge, $sharedAge, $private);
}
}
Expand Up @@ -23,21 +23,23 @@ class TemplateControllerTest extends TestCase
public function testTwig()
{
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->once())->method('render')->willReturn('bar');
$twig->expects($this->exactly(2))->method('render')->willReturn('bar');

$controller = new TemplateController($twig);

$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
$this->assertEquals('bar', $controller('mytemplate')->getContent());
}

public function testTemplating()
{
$templating = $this->getMockBuilder(EngineInterface::class)->getMock();
$templating->expects($this->once())->method('render')->willReturn('bar');
$templating->expects($this->exactly(2))->method('render')->willReturn('bar');

$controller = new TemplateController(null, $templating);

$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
$this->assertEquals('bar', $controller('mytemplate')->getContent());
}

/**
Expand All @@ -49,5 +51,6 @@ public function testNoTwigNorTemplating()
$controller = new TemplateController();

$controller->templateAction('mytemplate')->getContent();
$controller('mytemplate')->getContent();
}
}

0 comments on commit 6d15055

Please sign in to comment.