• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 16414261225

21 Jul 2025 10:14AM UTC coverage: 21.806% (-0.2%) from 22.039%
16414261225

Pull #7307

github

web-flow
Merge 92df6bf50 into d3b4b7b40
Pull Request #7307: Use class-string param type for Metadata::getClass

0 of 191 new or added lines in 19 files covered. (0.0%)

44 existing lines in 2 files now uncovered.

11408 of 52317 relevant lines covered (21.81%)

11.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/State/Tests/Provider/SecurityParameterProviderTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\State\Tests\Provider;
15

16
use ApiPlatform\Metadata\GetCollection;
17
use ApiPlatform\Metadata\Link;
18
use ApiPlatform\Metadata\ResourceAccessCheckerInterface;
19
use ApiPlatform\State\Provider\SecurityParameterProvider;
20
use ApiPlatform\State\ProviderInterface;
21
use PHPUnit\Framework\TestCase;
22
use Symfony\Component\HttpFoundation\ParameterBag;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
25

26
final class SecurityParameterProviderTest extends TestCase
27
{
28
    public function testIsGrantedLink(): void
29
    {
30
        $obj = new \stdClass();
×
31
        $barObj = new \stdClass();
×
32
        $operation = new GetCollection(uriVariables: [
×
33
            'barId' => new Link(toProperty: 'bar', fromClass: 'Bar', security: 'is_granted("some_voter", "bar")'),
×
NEW
34
        ], class: \stdClass::class);
×
35
        $decorated = $this->createMock(ProviderInterface::class);
×
36
        $decorated->method('provide')->willReturn($obj);
×
37
        $request = $this->createMock(Request::class);
×
38
        $parameterBag = new ParameterBag();
×
39
        $request->attributes = $parameterBag;
×
40
        $request->attributes->set('bar', $barObj);
×
41
        $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class);
×
42
        $resourceAccessChecker->expects($this->once())->method('isGranted')->with('Bar', 'is_granted("some_voter", "bar")', ['object' => $obj, 'previous_object' => null, 'request' => $request, 'bar' => $barObj, 'barId' => 1, 'operation' => $operation])->willReturn(true);
×
43
        $accessChecker = new SecurityParameterProvider($decorated, $resourceAccessChecker);
×
44
        $accessChecker->provide($operation, ['barId' => 1], ['request' => $request]);
×
45
    }
46

47
    public function testIsNotGrantedLink(): void
48
    {
49
        $this->expectException(AccessDeniedHttpException::class);
×
50

51
        $obj = new \stdClass();
×
52
        $barObj = new \stdClass();
×
53
        $operation = new GetCollection(uriVariables: [
×
54
            'barId' => new Link(toProperty: 'bar', fromClass: 'Bar', security: 'is_granted("some_voter", "bar")'),
×
NEW
55
        ], class: \stdClass::class);
×
56
        $decorated = $this->createMock(ProviderInterface::class);
×
57
        $decorated->method('provide')->willReturn($obj);
×
58
        $request = $this->createMock(Request::class);
×
59
        $parameterBag = new ParameterBag();
×
60
        $request->attributes = $parameterBag;
×
61
        $request->attributes->set('bar', $barObj);
×
62
        $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class);
×
63
        $resourceAccessChecker->expects($this->once())->method('isGranted')->with('Bar', 'is_granted("some_voter", "bar")', ['object' => $obj, 'previous_object' => null, 'request' => $request, 'bar' => $barObj, 'barId' => 1, 'operation' => $operation])->willReturn(false);
×
64
        $accessChecker = new SecurityParameterProvider($decorated, $resourceAccessChecker);
×
65
        $accessChecker->provide($operation, ['barId' => 1], ['request' => $request]);
×
66
    }
67

68
    public function testSecurityMessageLink(): void
69
    {
70
        $this->expectException(AccessDeniedHttpException::class);
×
71
        $this->expectExceptionMessage('You are not admin.');
×
72

73
        $obj = new \stdClass();
×
74
        $barObj = new \stdClass();
×
75
        $operation = new GetCollection(uriVariables: [
×
76
            'barId' => new Link(toProperty: 'bar', fromClass: 'Bar', security: 'is_granted("some_voter", "bar")', securityMessage: 'You are not admin.'),
×
NEW
77
        ], class: \stdClass::class);
×
78
        $decorated = $this->createMock(ProviderInterface::class);
×
79
        $decorated->method('provide')->willReturn($obj);
×
80
        $request = $this->createMock(Request::class);
×
81
        $parameterBag = new ParameterBag();
×
82
        $request->attributes = $parameterBag;
×
83
        $request->attributes->set('bar', $barObj);
×
84
        $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class);
×
85
        $resourceAccessChecker->expects($this->once())->method('isGranted')->with('Bar', 'is_granted("some_voter", "bar")', ['object' => $obj, 'previous_object' => null, 'request' => $request, 'bar' => $barObj, 'barId' => 1, 'operation' => $operation])->willReturn(false);
×
86
        $accessChecker = new SecurityParameterProvider($decorated, $resourceAccessChecker);
×
87
        $accessChecker->provide($operation, ['barId' => 1], ['request' => $request]);
×
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc