Completed
Push — master ( d81c19...f57266 )
by Kamil
20s
created

SharedSecurityServiceSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
declare(strict_types=1);
13
14
namespace spec\Sylius\Behat\Service;
15
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use Sylius\Behat\Service\SecurityServiceInterface;
19
use Sylius\Behat\Service\SharedSecurityService;
20
use Sylius\Behat\Service\SharedSecurityServiceInterface;
21
use Sylius\Component\Core\Model\AdminUserInterface;
22
use Sylius\Component\Order\Model\OrderInterface;
23
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
24
use Symfony\Component\Security\Core\Exception\TokenNotFoundException;
25
26
final class SharedSecurityServiceSpec extends ObjectBehavior
27
{
28
    function let(SecurityServiceInterface $adminSecurityService)
29
    {
30
        $this->beConstructedWith($adminSecurityService);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType(SharedSecurityService::class);
36
    }
37
38
    function it_implements_shared_security_service()
39
    {
40
        $this->shouldImplement(SharedSecurityServiceInterface::class);
41
    }
42
43
    function it_performs_action_as_given_admin_user_and_restore_previous_token(
44
        SecurityServiceInterface $adminSecurityService,
45
        TokenInterface $token,
46
        OrderInterface $order,
47
        AdminUserInterface $adminUser
48
    ) {
49
        $adminSecurityService->getCurrentToken()->willReturn($token);
50
        $adminSecurityService->logIn($adminUser)->shouldBeCalled();
51
        $order->completeCheckout()->shouldBeCalled();
52
        $adminSecurityService->restoreToken($token)->shouldBeCalled();
53
        $adminSecurityService->logOut()->shouldNotBeCalled();
54
55
        $wrappedOrder = $order->getWrappedObject();
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...r\Model\OrderInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
        $this->performActionAsAdminUser(
57
            $adminUser,
58
            function () use ($wrappedOrder) {
59
                $wrappedOrder->completeCheckout();
60
            }
61
        );
62
    }
63
64
    function it_performs_action_as_given_admin_user_and_logout(
65
        SecurityServiceInterface $adminSecurityService,
66
        OrderInterface $order,
67
        AdminUserInterface $adminUser
68
    ) {
69
        $adminSecurityService->getCurrentToken()->willThrow(TokenNotFoundException::class);
70
        $adminSecurityService->logIn($adminUser)->shouldBeCalled();
71
        $order->completeCheckout()->shouldBeCalled();
72
        $adminSecurityService->restoreToken(Argument::any())->shouldNotBeCalled();
73
        $adminSecurityService->logOut()->shouldBeCalled();
74
75
        $wrappedOrder = $order->getWrappedObject();
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...r\Model\OrderInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
        $this->performActionAsAdminUser(
77
            $adminUser,
78
            function () use ($wrappedOrder) {
79
                $wrappedOrder->completeCheckout();
80
            }
81
        );
82
    }
83
}
84