RefundSpec::it_is_initializable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace spec\BitBag\SyliusMolliePlugin\Controller\Action\Admin;
14
15
use BitBag\SyliusMolliePlugin\Controller\Action\Admin\Refund;
16
use Doctrine\ORM\EntityManagerInterface;
17
use Payum\Core\Payum;
18
use PhpSpec\ObjectBehavior;
19
use SM\Factory\FactoryInterface;
20
use SM\StateMachine\StateMachineInterface;
21
use Sylius\Bundle\PayumBundle\Model\GatewayConfig;
22
use Sylius\Component\Core\Model\PaymentInterface;
23
use Sylius\Component\Core\Model\PaymentMethodInterface;
24
use Sylius\Component\Core\Repository\PaymentRepositoryInterface;
25
use Sylius\Component\Payment\PaymentTransitions;
26
use Symfony\Component\HttpFoundation\HeaderBag;
27
use Symfony\Component\HttpFoundation\Request;
28
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
29
use Symfony\Component\HttpFoundation\Session\Session;
30
31
final class RefundSpec extends ObjectBehavior
32
{
33
    function let(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
        PaymentRepositoryInterface $paymentRepository,
35
        Payum $payum,
36
        Session $session,
37
        FactoryInterface $stateMachineFactory,
38
        EntityManagerInterface $paymentEntityManager
39
    ): void {
40
        $this->beConstructedWith(
41
            $paymentRepository,
42
            $payum,
43
            $session,
44
            $stateMachineFactory,
45
            $paymentEntityManager
46
        );
47
    }
48
49
    function it_is_initializable(): void
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
    {
51
        $this->shouldHaveType(Refund::class);
52
    }
53
54
    function it_refunds(
55
        Request $request,
56
        PaymentRepositoryInterface $paymentRepository,
57
        PaymentInterface $payment,
58
        PaymentMethodInterface $paymentMethod,
59
        GatewayConfig $gatewayConfig,
60
        FactoryInterface $stateMachineFactory,
61
        StateMachineInterface $stateMachine,
62
        Session $session,
63
        FlashBagInterface $flashBag,
64
        HeaderBag $headerBag
65
    ): void {
66
        $request->get('id')->willReturn(1);
67
        $headerBag->get('referer', null, true)->willReturn('wwww.example.com');
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Component\HttpFoundation\HeaderBag::get() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        $headerBag->/** @scrutinizer ignore-call */ 
68
                    get('referer', null, true)->willReturn('wwww.example.com');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
68
        $request->headers = $headerBag;
69
        $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Payum\Core\Model\GatewayConfigInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        $paymentMethod->getGatewayConfig()->/** @scrutinizer ignore-call */ willReturn($gatewayConfig);

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...
70
        $payment->getMethod()->willReturn($paymentMethod);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Payment...\PaymentMethodInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
        $payment->getMethod()->/** @scrutinizer ignore-call */ willReturn($paymentMethod);

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...
71
        $paymentRepository->find(1)->willReturn($payment);
72
        $stateMachine->can(PaymentTransitions::TRANSITION_REFUND)->willReturn(true);
73
        $session->getFlashBag()->willReturn($flashBag);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Symfony\Component\HttpFo...Flash\FlashBagInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $session->getFlashBag()->/** @scrutinizer ignore-call */ willReturn($flashBag);

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...
74
        $stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->willReturn($stateMachine);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on SM\StateMachine\StateMachineInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        $stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->/** @scrutinizer ignore-call */ willReturn($stateMachine);

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...
75
76
        $stateMachine->apply(PaymentTransitions::TRANSITION_REFUND)->shouldBeCalled();
77
78
        $this->__invoke($request);
79
    }
80
}
81