Skip to content

Commit 6d15055

Browse files
committed
[FrameworkBundle] Improve the DX of TemplateController when using SF 4
1 parent 5b360e2 commit 6d15055

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ public function templateAction(string $template, int $maxAge = null, int $shared
6767

6868
return $response;
6969
}
70+
71+
public function __invoke(string $template, int $maxAge = null, int $sharedAge = null, bool $private = null): Response
72+
{
73+
return $this->templateAction($template, $maxAge, $sharedAge, $private);
74+
}
7075
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ class TemplateControllerTest extends TestCase
2323
public function testTwig()
2424
{
2525
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
26-
$twig->expects($this->once())->method('render')->willReturn('bar');
26+
$twig->expects($this->exactly(2))->method('render')->willReturn('bar');
2727

2828
$controller = new TemplateController($twig);
2929

3030
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
31+
$this->assertEquals('bar', $controller('mytemplate')->getContent());
3132
}
3233

3334
public function testTemplating()
3435
{
3536
$templating = $this->getMockBuilder(EngineInterface::class)->getMock();
36-
$templating->expects($this->once())->method('render')->willReturn('bar');
37+
$templating->expects($this->exactly(2))->method('render')->willReturn('bar');
3738

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

4041
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
42+
$this->assertEquals('bar', $controller('mytemplate')->getContent());
4143
}
4244

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

5153
$controller->templateAction('mytemplate')->getContent();
54+
$controller('mytemplate')->getContent();
5255
}
5356
}

0 commit comments

Comments
 (0)