Completed
Push — master ( d27170...133b57 )
by Kamil
17:22
created

RbacAuthorizationCheckerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 36
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_resource_controller_authorization_checker_interface() 0 4 1
A it_grants_access_if_permission_is_not_required() 0 5 1
A it_uses_rbac_authorization_checker() 0 12 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
namespace spec\Sylius\Bundle\RbacBundle\Authorization;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\ResourceBundle\Controller\AuthorizationCheckerInterface as ResourceBundleAuthorizationCheckerInterface;
16
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
17
use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface;
18
19
/**
20
 * @author Paweł Jędrzejewski <[email protected]>
21
 */
22
class RbacAuthorizationCheckerSpec extends ObjectBehavior
23
{
24
    function let(AuthorizationCheckerInterface $rbacAuthorizationChecker)
25
    {
26
        $this->beConstructedWith($rbacAuthorizationChecker);
27
    }
28
29
    function it_is_initializable()
30
    {
31
        $this->shouldHaveType('Sylius\Bundle\RbacBundle\Authorization\RbacAuthorizationChecker');
32
    }
33
34
    function it_implements_resource_controller_authorization_checker_interface()
35
    {
36
        $this->shouldImplement(ResourceBundleAuthorizationCheckerInterface::class);
37
    }
38
39
    function it_grants_access_if_permission_is_not_required(RequestConfiguration $requestConfiguration)
40
    {
41
        $requestConfiguration->hasPermission()->willReturn(false);
42
        $this->isGranted($requestConfiguration, 'sylius.product.foo')->shouldReturn(true);
43
    }
44
45
    function it_uses_rbac_authorization_checker(
46
        RequestConfiguration $requestConfiguration,
47
        AuthorizationCheckerInterface $rbacAuthorizationChecker
48
    ) {
49
        $requestConfiguration->hasPermission()->willReturn(true);
50
        $requestConfiguration->getPermission('sylius.product.foo')->willReturn('sylius.product.foo');
51
        $rbacAuthorizationChecker->isGranted('sylius.product.foo')->willReturn(false);
52
        $this->isGranted($requestConfiguration, 'sylius.product.foo')->shouldReturn(false);
53
54
        $rbacAuthorizationChecker->isGranted('sylius.product.foo')->willReturn(true);
55
        $this->isGranted($requestConfiguration, 'sylius.product.foo')->shouldReturn(true);
56
    }
57
}
58