Completed
Push — scalar-types/resource ( 4814fd )
by Kamil
23:02
created

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
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\Component\Payment\Resolver;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Payment\Exception\UnresolvedDefaultPaymentMethodException;
18
use Sylius\Component\Payment\Model\PaymentInterface;
19
use Sylius\Component\Payment\Model\PaymentMethodInterface;
20
use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface;
21
use Sylius\Component\Payment\Resolver\DefaultPaymentMethodResolverInterface;
22
23
/**
24
 * @author Anna Walasek <[email protected]>
25
 */
26
final class DefaultPaymentMethodResolverSpec extends ObjectBehavior
27
{
28
    function let(PaymentMethodRepositoryInterface $paymentMethodRepository): void
29
    {
30
        $this->beConstructedWith($paymentMethodRepository);
31
    }
32
33
    function it_implements_default_payment_method_resolver_interface(): void
34
    {
35
        $this->shouldImplement(DefaultPaymentMethodResolverInterface::class);
36
    }
37
38
    function it_returns_first_enabled_payment_method_as_default(
39
        PaymentMethodInterface $firstPaymentMethod,
40
        PaymentMethodInterface $secondPaymentMethod,
41
        PaymentMethodRepositoryInterface $paymentMethodRepository,
42
        PaymentInterface $payment
43
    ): void {
44
        $paymentMethodRepository->findBy(['enabled' => true])->willReturn([$firstPaymentMethod, $secondPaymentMethod]);
45
46
        $this->getDefaultPaymentMethod($payment)->shouldReturn($firstPaymentMethod);
47
    }
48
49
    function it_throws_exception_if_there_are_no_enabled_payment_methods(
50
        PaymentMethodRepositoryInterface $paymentMethodRepository,
51
        PaymentInterface $payment
52
    ): void {
53
        $paymentMethodRepository->findBy(['enabled' => true])->willReturn([]);
54
55
        $this
56
            ->shouldThrow(UnresolvedDefaultPaymentMethodException::class)
57
            ->during('getDefaultPaymentMethod', [$payment])
58
        ;
59
    }
60
}
61