Completed
Push — 1.0 ( c870d0...b8a2ba )
by Kamil
56:03 queued 23:55
created

ChannelBasedPaymentMethodsResolverSpec   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 4
dl 0
loc 81
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_a_payment_methods_resolver_interface() 0 4 1
A it_returns_payment_methods_matched_for_order_channel() 0 18 1
A it_returns_an_empty_collection_if_there_is_no_enabled_payment_methods_for_order_channel() 0 16 1
A it_supports_shipments_with_order_and_its_shipping_address_defined() 0 10 1
A it_does_not_support_payments_for_order_with_not_assigned_channel() 0 9 1
A it_does_not_support_payment_if_payment_is_not_instance_of_core_payment_interface() 0 4 1
A it_does_not_support_payments_which_has_no_order_defined() 0 6 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
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Core\Resolver;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Core\Model\ChannelInterface;
18
use Sylius\Component\Core\Model\OrderInterface;
19
use Sylius\Component\Core\Model\PaymentInterface;
20
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
21
use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface;
22
use Sylius\Component\Payment\Model\PaymentMethodInterface;
23
use Sylius\Component\Payment\Resolver\PaymentMethodsResolverInterface;
24
25
final class ChannelBasedPaymentMethodsResolverSpec extends ObjectBehavior
26
{
27
    function let(PaymentMethodRepositoryInterface $paymentMethodRepository): void
28
    {
29
        $this->beConstructedWith($paymentMethodRepository);
30
    }
31
32
    function it_implements_a_payment_methods_resolver_interface(): void
33
    {
34
        $this->shouldImplement(PaymentMethodsResolverInterface::class);
35
    }
36
37
    function it_returns_payment_methods_matched_for_order_channel(
38
        PaymentInterface $payment,
39
        OrderInterface $order,
40
        ChannelInterface $channel,
41
        PaymentMethodRepositoryInterface $paymentMethodRepository,
42
        PaymentMethodInterface $firstPaymentMethod,
43
        PaymentMethodInterface $secondPaymentMethod
44
    ): void {
45
        $payment->getOrder()->willReturn($order);
46
        $order->getChannel()->willReturn($channel);
47
48
        $paymentMethodRepository
49
            ->findEnabledForChannel($channel)
50
            ->willReturn([$firstPaymentMethod, $secondPaymentMethod])
51
        ;
52
53
        $this->getSupportedMethods($payment)->shouldReturn([$firstPaymentMethod, $secondPaymentMethod]);
54
    }
55
56
    function it_returns_an_empty_collection_if_there_is_no_enabled_payment_methods_for_order_channel(
57
        PaymentInterface $payment,
58
        OrderInterface $order,
59
        ChannelInterface $channel,
60
        PaymentMethodRepositoryInterface $paymentMethodRepository
61
    ): void {
62
        $payment->getOrder()->willReturn($order);
63
        $order->getChannel()->willReturn($channel);
64
65
        $paymentMethodRepository
66
            ->findEnabledForChannel($channel)
67
            ->willReturn([])
68
        ;
69
70
        $this->getSupportedMethods($payment)->shouldReturn([]);
71
    }
72
73
    function it_supports_shipments_with_order_and_its_shipping_address_defined(
74
        PaymentInterface $payment,
75
        OrderInterface $order,
76
        ChannelInterface $channel
77
    ): void {
78
        $payment->getOrder()->willReturn($order);
79
        $order->getChannel()->willReturn($channel);
80
81
        $this->supports($payment)->shouldReturn(true);
82
    }
83
84
    function it_does_not_support_payments_for_order_with_not_assigned_channel(
85
        PaymentInterface $payment,
86
        OrderInterface $order
87
    ): void {
88
        $payment->getOrder()->willReturn($order);
89
        $order->getChannel()->willReturn(null);
90
91
        $this->supports($payment)->shouldReturn(false);
92
    }
93
94
    function it_does_not_support_payment_if_payment_is_not_instance_of_core_payment_interface(BasePaymentInterface $payment): void
95
    {
96
        $this->supports($payment)->shouldReturn(false);
97
    }
98
99
    function it_does_not_support_payments_which_has_no_order_defined(PaymentInterface $payment): void
100
    {
101
        $payment->getOrder()->willReturn(null);
102
103
        $this->supports($payment)->shouldReturn(false);
104
    }
105
}
106