Skip to content

Commit 2f7322c

Browse files
committed
removes security dependency from IsAuthenticated function constructor
1 parent fc9517a commit 2f7322c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/ExpressionLanguage/ExpressionFunction/Security/IsAuthenticated.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 IsAuthenticated extends ExpressionFunction
1110
{
12-
public function __construct(Security $security)
11+
public function __construct()
1312
{
1413
parent::__construct(
1514
'isAuthenticated',
1615
static function (): string {
1716
return '$globalVariable->get(\'security\')->isAuthenticated()';
1817
},
19-
static function () use ($security): bool {
20-
return $security->isAuthenticated();
18+
static function ($arguments): bool {
19+
return $arguments['globalVariable']->get('security')->isAuthenticated();
2120
}
2221
);
2322
}

tests/ExpressionLanguage/ExpressionFunction/Security/IsAuthenticatedTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,37 @@
44

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

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

1011
class IsAuthenticatedTest extends TestCase
1112
{
1213
protected function getFunctions()
1314
{
14-
$Security = $this->getSecurityIsGrantedWithExpectation(
15-
$this->matchesRegularExpression('/^IS_AUTHENTICATED_(REMEMBERED|FULLY)$/'),
16-
$this->any()
17-
);
18-
19-
return [new IsAuthenticated($Security)];
15+
return [new IsAuthenticated()];
2016
}
2117

2218
public function testEvaluator(): void
2319
{
24-
$isAuthenticated = $this->expressionLanguage->evaluate('isAuthenticated()');
20+
$security = $this->getSecurityIsGrantedWithExpectation(
21+
$this->matchesRegularExpression('/^IS_AUTHENTICATED_(REMEMBERED|FULLY)$/'),
22+
$this->any()
23+
);
24+
$globalVariable = new GlobalVariables(['security' => $security]);
25+
26+
$isAuthenticated = $this->expressionLanguage->evaluate(
27+
'isAuthenticated()',
28+
['globalVariable' => $globalVariable]
29+
);
2530
$this->assertTrue($isAuthenticated);
2631
}
2732

2833
public function testIsAuthenticated(): void
2934
{
30-
$this->assertExpressionCompile('isAuthenticated()', $this->matchesRegularExpression('/^IS_AUTHENTICATED_(REMEMBERED|FULLY)$/'));
35+
$this->assertExpressionCompile(
36+
'isAuthenticated()',
37+
$this->matchesRegularExpression('/^IS_AUTHENTICATED_(REMEMBERED|FULLY)$/')
38+
);
3139
}
3240
}

0 commit comments

Comments
 (0)