Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e12ef2

Browse filesBrowse files
committed
Mark experimental and remove Templating support
1 parent 7f6c063 commit 9e12ef2
Copy full SHA for 9e12ef2

File tree

2 files changed

+27
-84
lines changed
Filter options

2 files changed

+27
-84
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
+12-32Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@
3434
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
3535
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
3636
use Symfony\Component\Serializer\SerializerInterface;
37-
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
3837

3938
/**
4039
* Common features needed in controllers.
4140
*
42-
* Supports both autowiring trough setters and accessing services using a container.
41+
* The recommended way of injecting dependencies is trough getter injection.
4342
*
4443
* @author Kévin Dunglas <dunglas@gmail.com>
44+
*
45+
* @experimental in version 3.3
4546
*/
4647
trait ControllerTrait
4748
{
@@ -81,11 +82,6 @@ protected function getAuthorizationChecker(): AuthorizationCheckerInterface
8182
throw new \LogicException(sprintf('An instance of "%s" must be provided.', AuthorizationCheckerInterface::class));
8283
}
8384

84-
protected function getTemplating(): EngineInterface
85-
{
86-
throw new \LogicException(sprintf('An instance of "%s" must be provided.', EngineInterface::class));
87-
}
88-
8985
protected function getTwig(): \Twig_Environment
9086
{
9187
throw new \LogicException(sprintf('An instance of "%s" must be provided.', \Twig_Environment::class));
@@ -271,11 +267,7 @@ protected function denyAccessUnlessGranted($attributes, $object = null, string $
271267
*/
272268
protected function renderView(string $view, array $parameters = array()): string
273269
{
274-
try {
275-
return $this->getTemplating()->render($view, $parameters);
276-
} catch (\LogicException $e) {
277-
return $this->getTwig()->render($view, $parameters);
278-
}
270+
return $this->getTwig()->render($view, $parameters);
279271
}
280272

281273
/**
@@ -289,15 +281,11 @@ protected function renderView(string $view, array $parameters = array()): string
289281
*/
290282
protected function render(string $view, array $parameters = array(), Response $response = null): Response
291283
{
292-
try {
293-
return $this->getTemplating()->renderResponse($view, $parameters, $response);
294-
} catch (\LogicException $e) {
295-
if (null === $response) {
296-
$response = new Response();
297-
}
298-
299-
return $response->setContent($this->getTwig()->render($view, $parameters));
284+
if (null === $response) {
285+
$response = new Response();
300286
}
287+
288+
return $response->setContent($this->getTwig()->render($view, $parameters));
301289
}
302290

303291
/**
@@ -311,19 +299,11 @@ protected function render(string $view, array $parameters = array(), Response $r
311299
*/
312300
protected function stream(string $view, array $parameters = array(), StreamedResponse $response = null): StreamedResponse
313301
{
314-
try {
315-
$templating = $this->getTemplating();
316-
317-
$callback = function () use ($templating, $view, $parameters) {
318-
$templating->stream($view, $parameters);
319-
};
320-
} catch (\LogicException $e) {
321-
$twig = $this->getTwig();
302+
$twig = $this->getTwig();
322303

323-
$callback = function () use ($twig, $view, $parameters) {
324-
$twig->display($view, $parameters);
325-
};
326-
}
304+
$callback = function () use ($twig, $view, $parameters) {
305+
$twig->display($view, $parameters);
306+
};
327307

328308
if (null === $response) {
329309
return new StreamedResponse($callback);

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php
+15-52Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,28 @@
3535
use Symfony\Component\Security\Core\User\User;
3636
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
3737
use Symfony\Component\Serializer\SerializerInterface;
38-
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
3938

4039
/**
4140
* @author Kévin Dunglas <dunglas@gmail.com>
41+
*
42+
* @requires PHP 7
4243
*/
4344
class ControllerTraitTest extends \PHPUnit_Framework_TestCase
4445
{
4546
use ControllerTrait {
4647
getSerializer as traitGetSerializer;
47-
getTemplating as traitGetTemplating;
4848
}
4949

5050
private $token;
5151
private $serializer;
5252
private $flashBag;
5353
private $isGranted;
54-
private $templating;
5554
private $twig;
5655
private $formFactory;
5756

5857
protected function getRouter()
5958
{
60-
$router = $this->getMock(RouterInterface::class);
59+
$router = $this->getMockBuilder(RouterInterface::class)->getMock();
6160
$router->expects($this->once())->method('generate')->willReturn('/foo');
6261

6362
return $router;
@@ -77,7 +76,7 @@ protected function getRequestStack()
7776

7877
protected function getHttpKernel()
7978
{
80-
$kernel = $this->getMock(HttpKernelInterface::class);
79+
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
8180
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
8281
return new Response($request->getRequestFormat().'--'.$request->getLocale());
8382
}));
@@ -96,37 +95,28 @@ protected function getSerializer()
9695

9796
protected function getSession()
9897
{
99-
$session = $this->getMock(Session::class);
98+
$session = $this->getMockBuilder(Session::class)->getMock();
10099
$session->expects($this->once())->method('getFlashBag')->willReturn($this->flashBag);
101100

102101
return $session;
103102
}
104103

105104
protected function getAuthorizationChecker()
106105
{
107-
$authorizationChecker = $this->getMock(AuthorizationCheckerInterface::class);
106+
$authorizationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
108107
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn($this->isGranted);
109108

110109
return $authorizationChecker;
111110
}
112111

113-
protected function getTemplating()
114-
{
115-
if ($this->templating) {
116-
return $this->templating;
117-
}
118-
119-
return $this->traitGetTemplating();
120-
}
121-
122112
protected function getTwig()
123113
{
124114
return $this->twig;
125115
}
126116

127117
protected function getDoctrine()
128118
{
129-
return $this->getMock(ManagerRegistry::class);
119+
return $this->getMockBuilder(ManagerRegistry::class)->getMock();
130120
}
131121

132122
protected function getFormFactory()
@@ -136,7 +126,7 @@ protected function getFormFactory()
136126

137127
protected function getTokenStorage()
138128
{
139-
$tokenStorage = $this->getMock(TokenStorageInterface::class);
129+
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
140130
$tokenStorage
141131
->expects($this->once())
142132
->method('getToken')
@@ -147,7 +137,7 @@ protected function getTokenStorage()
147137

148138
protected function getCsrfTokenManager()
149139
{
150-
$tokenManager = $this->getMock(CsrfTokenManagerInterface::class);
140+
$tokenManager = $this->getMockBuilder(CsrfTokenManagerInterface::class)->getMock();
151141
$tokenManager->expects($this->once())->method('isTokenValid')->willReturn(true);
152142

153143
return $tokenManager;
@@ -213,7 +203,7 @@ public function testJson()
213203

214204
public function testJsonWithSerializer()
215205
{
216-
$this->serializer = $this->getMock(SerializerInterface::class);
206+
$this->serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
217207
$this->serializer
218208
->expects($this->once())
219209
->method('serialize')
@@ -227,7 +217,7 @@ public function testJsonWithSerializer()
227217

228218
public function testJsonWithSerializerContextOverride()
229219
{
230-
$this->serializer = $this->getMock(SerializerInterface::class);
220+
$this->serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
231221
$this->serializer
232222
->expects($this->once())
233223
->method('serialize')
@@ -244,7 +234,6 @@ public function testJsonWithSerializerContextOverride()
244234
public function testAddFlash()
245235
{
246236
$this->flashBag = new FlashBag();
247-
248237
$this->addFlash('foo', 'bar');
249238

250239
$this->assertSame(array('bar'), $this->flashBag->get('foo'));
@@ -267,50 +256,24 @@ public function testDenyAccessUnlessGranted()
267256
$this->denyAccessUnlessGranted('foo');
268257
}
269258

270-
public function testRenderViewTemplating()
271-
{
272-
$this->templating = $this->getMock(EngineInterface::class);
273-
$this->templating->expects($this->once())->method('render')->willReturn('bar');
274-
275-
$this->assertEquals('bar', $this->renderView('foo'));
276-
}
277-
278259
public function testRenderViewTwig()
279260
{
280-
$this->templating = false;
281261
$this->twig = $this->getMockBuilder(\Twig_Environment::class)->disableOriginalConstructor()->getMock();
282262
$this->twig->expects($this->once())->method('render')->willReturn('bar');
283263

284264
$this->assertEquals('bar', $this->renderView('foo'));
285265
}
286266

287-
public function testRenderTemplating()
288-
{
289-
$this->templating = $this->getMock(EngineInterface::class);
290-
$this->templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
291-
292-
$this->assertEquals('bar', $this->render('foo')->getContent());
293-
}
294-
295267
public function testRenderTwig()
296268
{
297-
$this->templating = false;
298269
$this->twig = $this->getMockBuilder(\Twig_Environment::class)->disableOriginalConstructor()->getMock();
299270
$this->twig->expects($this->once())->method('render')->willReturn('bar');
300271

301272
$this->assertEquals('bar', $this->render('foo')->getContent());
302273
}
303274

304-
public function testStreamTemplating()
305-
{
306-
$this->templating = $this->getMock(EngineInterface::class);
307-
308-
$this->assertInstanceOf(StreamedResponse::class, $this->stream('foo'));
309-
}
310-
311275
public function testStreamTwig()
312276
{
313-
$this->templating = false;
314277
$this->twig = $this->getMockBuilder(\Twig_Environment::class)->disableOriginalConstructor()->getMock();
315278

316279
$this->assertInstanceOf(StreamedResponse::class, $this->stream('foo'));
@@ -328,19 +291,19 @@ public function testCreateAccessDeniedException()
328291

329292
public function testCreateForm()
330293
{
331-
$form = $this->getMock(FormInterface::class);
294+
$form = $this->getMockBuilder(FormInterface::class)->getMock();
332295

333-
$this->formFactory = $this->getMock(FormFactoryInterface::class);
296+
$this->formFactory = $this->getMockBuilder(FormFactoryInterface::class)->getMock();
334297
$this->formFactory->expects($this->once())->method('create')->willReturn($form);
335298

336299
$this->assertEquals($form, $this->createForm('foo'));
337300
}
338301

339302
public function testCreateFormBuilder()
340303
{
341-
$formBuilder = $this->getMock(FormBuilderInterface::class);
304+
$formBuilder = $this->getMockBuilder(FormBuilderInterface::class)->getMock();
342305

343-
$this->formFactory = $this->getMock(FormFactoryInterface::class);
306+
$this->formFactory = $this->getMockBuilder(FormFactoryInterface::class)->getMock();
344307
$this->formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
345308

346309
$this->assertEquals($formBuilder, $this->createFormBuilder('foo'));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.