Skip to content

Commit d8f41fe

Browse files
authored
Remove templating engine (#653)
* Remove templating engine usage * Adapt unit test * Clean configuration * Update composer dependencies * Adapt twig test configuration * Add changelog
1 parent 1387cdb commit d8f41fe

File tree

8 files changed

+43
-82
lines changed

8 files changed

+43
-82
lines changed

CHANGELOG-2.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This changelog references the relevant changes done in 6.0 versions.
1010
* Dropped support for PHP 7.1 [[#651](https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/pull/651)]
1111
* Dropped support for Symfony versions anterior to `4.4` [[#648](https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/pull/648)]
1212
* Fixed form submission/validation [[#643](https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/pull/643)]
13+
* **[BC break]** Changed signature of method `FOS\OAuthServerBundle\Controller\AuthorizeController::renderAuthorize()` [[#653](https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/pull/653)]
14+
* **[BC break]** Removed support for templating engine [[#653](https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/pull/653)]
1315

1416
### 2.0.0-ALPHA0 (2018-05-01)
1517

Controller/AuthorizeController.php

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
2020
use OAuth2\OAuth2;
2121
use OAuth2\OAuth2ServerException;
22-
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
2322
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2423
use Symfony\Component\Form\Form;
2524
use Symfony\Component\HttpFoundation\Request;
@@ -31,6 +30,7 @@
3130
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
3231
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
3332
use Symfony\Component\Security\Core\User\UserInterface;
33+
use Twig\Environment as TwigEnvironment;
3434

3535
/**
3636
* Controller handling basic authorization.
@@ -64,11 +64,6 @@ class AuthorizeController
6464
*/
6565
private $oAuth2Server;
6666

67-
/**
68-
* @var EngineInterface
69-
*/
70-
private $templating;
71-
7267
/**
7368
* @var RequestStack
7469
*/
@@ -79,6 +74,11 @@ class AuthorizeController
7974
*/
8075
private $tokenStorage;
8176

77+
/**
78+
* @var TwigEnvironment
79+
*/
80+
private $twig;
81+
8282
/**
8383
* @var UrlGeneratorInterface
8484
*/
@@ -89,11 +89,6 @@ class AuthorizeController
8989
*/
9090
private $clientManager;
9191

92-
/**
93-
* @var string
94-
*/
95-
private $templateEngineType;
96-
9792
/**
9893
* @var EventDispatcherInterface
9994
*/
@@ -106,32 +101,29 @@ class AuthorizeController
106101
* @todo This controller could be refactored to not rely on so many dependencies
107102
*
108103
* @param SessionInterface $session
109-
* @param string $templateEngineType
110104
*/
111105
public function __construct(
112106
RequestStack $requestStack,
113107
Form $authorizeForm,
114108
AuthorizeFormHandler $authorizeFormHandler,
115109
OAuth2 $oAuth2Server,
116-
EngineInterface $templating,
117110
TokenStorageInterface $tokenStorage,
118111
UrlGeneratorInterface $router,
119112
ClientManagerInterface $clientManager,
120113
EventDispatcherInterface $eventDispatcher,
121-
SessionInterface $session = null,
122-
$templateEngineType = 'twig'
114+
TwigEnvironment $twig,
115+
SessionInterface $session = null
123116
) {
124117
$this->requestStack = $requestStack;
125118
$this->session = $session;
126119
$this->authorizeForm = $authorizeForm;
127120
$this->authorizeFormHandler = $authorizeFormHandler;
128121
$this->oAuth2Server = $oAuth2Server;
129-
$this->templating = $templating;
130122
$this->tokenStorage = $tokenStorage;
131123
$this->router = $router;
132124
$this->clientManager = $clientManager;
133-
$this->templateEngineType = $templateEngineType;
134125
$this->eventDispatcher = $eventDispatcher;
126+
$this->twig = $twig;
135127
}
136128

137129
/**
@@ -169,12 +161,10 @@ public function authorizeAction(Request $request)
169161
return $this->processSuccess($user, $formHandler, $request);
170162
}
171163

172-
$data = [
164+
return $this->renderAuthorize([
173165
'form' => $form->createView(),
174166
'client' => $this->getClient(),
175-
];
176-
177-
return $this->renderAuthorize($data, $this->templating, $this->templateEngineType);
167+
]);
178168
}
179169

180170
/**
@@ -217,7 +207,7 @@ protected function getRedirectionUrl(UserInterface $user)
217207
}
218208

219209
/**
220-
* @return ClientInterface
210+
* @return ClientInterface
221211
*/
222212
protected function getClient()
223213
{
@@ -243,14 +233,10 @@ protected function getClient()
243233
return $this->client;
244234
}
245235

246-
/**
247-
* @throws \RuntimeException
248-
*/
249-
protected function renderAuthorize(array $data, EngineInterface $engine, string $engineType): Response
236+
protected function renderAuthorize(array $context): Response
250237
{
251-
return $engine->renderResponse(
252-
'@FOSOAuthServer/Authorize/authorize.html.'.$engineType,
253-
$data
238+
return new Response(
239+
$this->twig->render('@FOSOAuthServer/Authorize/authorize.html.twig', $context)
254240
);
255241
}
256242

DependencyInjection/Configuration.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public function getConfigTreeBuilder()
7979

8080
$this->addAuthorizeSection($rootNode);
8181
$this->addServiceSection($rootNode);
82-
$this->addTemplateSection($rootNode);
8382

8483
return $treeBuilder;
8584
}
@@ -135,18 +134,4 @@ private function addServiceSection(ArrayNodeDefinition $node)
135134
->end()
136135
;
137136
}
138-
139-
private function addTemplateSection(ArrayNodeDefinition $node)
140-
{
141-
$node
142-
->children()
143-
->arrayNode('template')
144-
->addDefaultsIfNotSet()
145-
->children()
146-
->scalarNode('engine')->defaultValue('twig')->end()
147-
->end()
148-
->end()
149-
->end()
150-
;
151-
}
152137
}

DependencyInjection/FOSOAuthServerExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function load(array $configs, ContainerBuilder $container)
6868
'refresh_token_class' => 'fos_oauth_server.model.refresh_token.class',
6969
'auth_code_class' => 'fos_oauth_server.model.auth_code.class',
7070
],
71-
'template' => 'fos_oauth_server.template.%s',
7271
]);
7372

7473
// Handle the MongoDB document manager name in a specific way as it does not have a registry to make it easy

Resources/config/authorize.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@
2828
<argument type="service" id="fos_oauth_server.authorize.form" />
2929
<argument type="service" id="fos_oauth_server.authorize.form.handler" />
3030
<argument type="service" id="fos_oauth_server.server" />
31-
<argument type="service" id="templating" />
3231
<argument type="service" id="security.token_storage" />
3332
<argument type="service" id="router" />
3433
<argument type="service" id="fos_oauth_server.client_manager" />
3534
<argument type="service" id="event_dispatcher" />
35+
<argument type="service" id="twig" />
3636
<argument type="service" id="session" on-invalid="null" />
37-
<argument>%fos_oauth_server.template.engine%</argument>
3837
</service>
3938
</services>
4039

Tests/Controller/AuthorizeControllerTest.php

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use FOS\OAuthServerBundle\Model\ClientInterface;
2020
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
2121
use OAuth2\OAuth2;
22-
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
2322
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2423
use Symfony\Component\Form\Form;
2524
use Symfony\Component\Form\FormView;
@@ -33,6 +32,7 @@
3332
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
3433
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
3534
use Symfony\Component\Security\Core\User\UserInterface;
35+
use Twig\Environment as TwigEnvironment;
3636

3737
class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase
3838
{
@@ -62,14 +62,14 @@ class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase
6262
protected $oAuth2Server;
6363

6464
/**
65-
* @var \PHPUnit_Framework_MockObject_MockObject|EngineInterface
65+
* @var \PHPUnit_Framework_MockObject_MockObject|TokenStorageInterface
6666
*/
67-
protected $templateEngine;
67+
protected $tokenStorage;
6868

6969
/**
70-
* @var \PHPUnit_Framework_MockObject_MockObject|TokenStorageInterface
70+
* @var \PHPUnit_Framework_MockObject_MockObject|TwigEnvironment
7171
*/
72-
protected $tokenStorage;
72+
protected $twig;
7373

7474
/**
7575
* @var \PHPUnit_Framework_MockObject_MockObject|UrlGeneratorInterface
@@ -86,11 +86,6 @@ class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase
8686
*/
8787
protected $eventDispatcher;
8888

89-
/**
90-
* @var string
91-
*/
92-
protected $templateEngineType;
93-
9489
/**
9590
* @var AuthorizeController
9691
*/
@@ -149,11 +144,11 @@ public function setUp()
149144
->disableOriginalConstructor()
150145
->getMock()
151146
;
152-
$this->templateEngine = $this->getMockBuilder(EngineInterface::class)
147+
$this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)
153148
->disableOriginalConstructor()
154149
->getMock()
155150
;
156-
$this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)
151+
$this->twig = $this->getMockBuilder(TwigEnvironment::class)
157152
->disableOriginalConstructor()
158153
->getMock()
159154
;
@@ -173,20 +168,18 @@ public function setUp()
173168
->disableOriginalConstructor()
174169
->getMock()
175170
;
176-
$this->templateEngineType = 'twig';
177171

178172
$this->instance = new AuthorizeController(
179173
$this->requestStack,
180174
$this->form,
181175
$this->authorizeFormHandler,
182176
$this->oAuth2Server,
183-
$this->templateEngine,
184177
$this->tokenStorage,
185178
$this->router,
186179
$this->clientManager,
187180
$this->eventDispatcher,
188-
$this->session,
189-
$this->templateEngineType
181+
$this->twig,
182+
$this->session
190183
);
191184

192185
/** @var \PHPUnit_Framework_MockObject_MockObject&Request $request */
@@ -307,22 +300,20 @@ public function testAuthorizeActionWillRenderTemplate()
307300
->willReturn($this->formView)
308301
;
309302

310-
$response = new Response();
311-
312-
$this->templateEngine
313-
->expects($this->at(0))
314-
->method('renderResponse')
303+
$this->twig
304+
->expects($this->once())
305+
->method('render')
315306
->with(
316307
'@FOSOAuthServer/Authorize/authorize.html.twig',
317308
[
318309
'form' => $this->formView,
319310
'client' => $this->client,
320311
]
321312
)
322-
->willReturn($response)
313+
->willReturn($responseBody = 'response')
323314
;
324315

325-
$this->assertSame($response, $this->instance->authorizeAction($this->request));
316+
$this->assertSame($responseBody, $this->instance->authorizeAction($this->request)->getContent());
326317
}
327318

328319
public function testAuthorizeActionWillFinishClientAuthorization()
@@ -466,22 +457,20 @@ public function testAuthorizeActionWillEnsureLogout()
466457
->willReturn($this->formView)
467458
;
468459

469-
$response = new Response();
470-
471-
$this->templateEngine
472-
->expects($this->at(0))
473-
->method('renderResponse')
460+
$this->twig
461+
->expects($this->once())
462+
->method('render')
474463
->with(
475464
'@FOSOAuthServer/Authorize/authorize.html.twig',
476465
[
477466
'form' => $this->formView,
478467
'client' => $this->client,
479468
]
480469
)
481-
->willReturn($response)
470+
->willReturn($responseBody = 'response')
482471
;
483472

484-
$this->assertSame($response, $this->instance->authorizeAction($this->request));
473+
$this->assertSame($responseBody, $this->instance->authorizeAction($this->request)->getContent());
485474
}
486475

487476
public function testAuthorizeActionWillProcessAuthorizationForm()

Tests/Functional/config/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
framework:
2-
templating:
3-
engines: ["twig"]
42
form: ~
53
secret: test
64
router:
75
resource: "%kernel.root_dir%/config/routing.yml"
86

7+
twig:
8+
exception_controller: null
9+
strict_variables: '%kernel.debug%'
10+
911
fos_oauth_server:
1012

1113
security:

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"friendsofsymfony/oauth2-php": "~1.1",
2525
"symfony/dependency-injection": "^4.4",
2626
"symfony/framework-bundle": "^4.4",
27-
"symfony/security-bundle": "^4.4"
27+
"symfony/security-bundle": "^4.4",
28+
"symfony/twig-bundle": "^4.4"
2829
},
2930
"conflict": {
3031
"twig/twig": "<1.40 || >=2.0,<2.9"
@@ -43,8 +44,6 @@
4344
"symfony/console": "~3.0 || ~4.0",
4445
"symfony/form": "~3.0 || ~4.0",
4546
"symfony/phpunit-bridge": "~3.0 || ~4.0",
46-
"symfony/templating": "~3.0 || ~4.0",
47-
"symfony/twig-bundle": "~3.0 || ^4.0",
4847
"symfony/yaml": "~3.0 || ~4.0",
4948
"willdurand/propel-typehintable-behavior": "~1.0"
5049
},

0 commit comments

Comments
 (0)