Skip to content

Commit 28194dd

Browse files
committed
removes security dependency from IsGranted function constructor
1 parent 666113a commit 28194dd

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/ExpressionLanguage/ExpressionFunction/Security/IsGranted.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
namespace Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\Security;
66

77
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction;
8-
use Overblog\GraphQLBundle\Security\Security;
98

109
final class IsGranted extends ExpressionFunction
1110
{
12-
public function __construct(Security $security)
11+
public function __construct()
1312
{
1413
parent::__construct(
1514
'isGranted',
1615
static function ($attributes, $object = 'null'): string {
1716
return \sprintf('$globalVariable->get(\'security\')->isGranted(%s, %s)', $attributes, $object);
1817
},
19-
static function ($_, $attributes, $object = null) use ($security): bool {
20-
return $security->isGranted($attributes, $object);
18+
static function ($arguments, $attributes, $object = null): bool {
19+
return $arguments['globalVariable']->get('security')->isGranted($attributes, $object);
2120
}
2221
);
2322
}

tests/ExpressionLanguage/ExpressionFunction/Security/IsGrantedTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44

55
namespace Overblog\GraphQLBundle\Tests\ExpressionLanguage\ExpressionFunction\Security;
66

7+
use Overblog\GraphQLBundle\Definition\GlobalVariables;
78
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\Security\IsGranted;
89
use Overblog\GraphQLBundle\Tests\ExpressionLanguage\TestCase;
910

1011
class IsGrantedTest extends TestCase
1112
{
1213
protected function getFunctions()
1314
{
14-
$security = $this->getSecurityIsGrantedWithExpectation(
15-
$this->matchesRegularExpression('/^ROLE_(USER|ADMIN)$/'),
16-
$this->any()
17-
);
18-
19-
return [new IsGranted($security)];
15+
return [new IsGranted()];
2016
}
2117

2218
public function testEvaluator(): void
2319
{
24-
$this->assertTrue($this->expressionLanguage->evaluate('isGranted("ROLE_USER")'));
20+
$security = $this->getSecurityIsGrantedWithExpectation(
21+
$this->matchesRegularExpression('/^ROLE_(USER|ADMIN)$/'),
22+
$this->any()
23+
);
24+
$globalVariable = new GlobalVariables(['security' => $security]);
25+
26+
$this->assertTrue(
27+
$this->expressionLanguage->evaluate('isGranted("ROLE_USER")', ['globalVariable' => $globalVariable])
28+
);
2529
}
2630

2731
public function testIsGranted(): void

0 commit comments

Comments
 (0)