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
|
|
|
|