Skip to content

Commit 01b1caa

Browse files
Merge branch '5.4' into 6.2
* 5.4: 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 [Validator] Sync IBAN formats with Swift IBAN registry [String] Use same alphabet for ByteString::fromRandom tests Fix phpdocs in components
2 parents 49f4edc + 8762335 commit 01b1caa

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
@@ -215,7 +215,7 @@ protected function denyAccessUnlessGranted(mixed $attribute, mixed $subject = nu
215215
{
216216
if (!$this->isGranted($attribute, $subject)) {
217217
$exception = $this->createAccessDeniedException($message);
218-
$exception->setAttributes($attribute);
218+
$exception->setAttributes([$attribute]);
219219
$exception->setSubject($subject);
220220

221221
throw $exception;

Tests/Controller/AbstractControllerTest.php

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

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

0 commit comments

Comments
 (0)