Skip to content

Commit a5b189e

Browse files
Merge branch '6.2' into 6.3
* 6.2: fix style of label containing new lines in PUML dump [TwigBridge] Allow floats in html5 input type number field [Translation] Handle the translation of empty strings [VarDumper] Fix error when reflected class has default Enum parameter in constructor [FrameworkBundle] Fix denyAccessUnlessGranted for mixed attributes [Validator] Fix translation of AtLeastOneOf constraint message do not drop embed label classes [Validator] Sync IBAN formats with Swift IBAN registry Update Infobip API transport to use the API V3 [String] Use same alphabet for ByteString::fromRandom tests Fix phpdocs in components Fix the rendering of query explanation with Postgresql
2 parents 89ad097 + 1c60151 commit a5b189e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Controller/AbstractController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected function denyAccessUnlessGranted(mixed $attribute, mixed $subject = nu
212212
{
213213
if (!$this->isGranted($attribute, $subject)) {
214214
$exception = $this->createAccessDeniedException($message);
215-
$exception->setAttributes($attribute);
215+
$exception->setAttributes([$attribute]);
216216
$exception->setSubject($subject);
217217

218218
throw $exception;

Tests/Controller/AbstractControllerTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,40 @@ public function testdenyAccessUnlessGranted()
362362
$controller->denyAccessUnlessGranted('foo');
363363
}
364364

365+
/**
366+
* @dataProvider provideDenyAccessUnlessGrantedSetsAttributesAsArray
367+
*/
368+
public function testdenyAccessUnlessGrantedSetsAttributesAsArray($attribute, $exceptionAttributes)
369+
{
370+
$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
371+
$authorizationChecker->method('isGranted')->willReturn(false);
372+
373+
$container = new Container();
374+
$container->set('security.authorization_checker', $authorizationChecker);
375+
376+
$controller = $this->createController();
377+
$controller->setContainer($container);
378+
379+
try {
380+
$controller->denyAccessUnlessGranted($attribute);
381+
$this->fail('there was no exception to check');
382+
} catch (AccessDeniedException $e) {
383+
$this->assertSame($exceptionAttributes, $e->getAttributes());
384+
}
385+
}
386+
387+
public static function provideDenyAccessUnlessGrantedSetsAttributesAsArray()
388+
{
389+
$obj = new \stdClass();
390+
$obj->foo = 'bar';
391+
392+
return [
393+
'string attribute' => ['foo', ['foo']],
394+
'array attribute' => [[1, 3, 3, 7], [[1, 3, 3, 7]]],
395+
'object attribute' => [$obj, [$obj]],
396+
];
397+
}
398+
365399
public function testRenderViewTwig()
366400
{
367401
$twig = $this->createMock(Environment::class);

0 commit comments

Comments
 (0)