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\Shipping\Resolver; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\Registry\PrioritizedServiceRegistryInterface; |
18
|
|
|
use Sylius\Component\Shipping\Model\ShippingMethodInterface; |
19
|
|
|
use Sylius\Component\Shipping\Model\ShippingSubjectInterface; |
20
|
|
|
use Sylius\Component\Shipping\Resolver\ShippingMethodsResolverInterface; |
21
|
|
|
|
22
|
|
|
final class CompositeMethodsResolverSpec extends ObjectBehavior |
23
|
|
|
{ |
24
|
|
|
function let(PrioritizedServiceRegistryInterface $resolversRegistry): void |
25
|
|
|
{ |
26
|
|
|
$this->beConstructedWith($resolversRegistry); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function it_implements_methods_resolver_interface(): void |
30
|
|
|
{ |
31
|
|
|
$this->shouldImplement(ShippingMethodsResolverInterface::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_uses_registry_to_provide_shipping_methods_for_shipping_subject( |
35
|
|
|
ShippingMethodsResolverInterface $firstMethodsResolver, |
36
|
|
|
ShippingMethodsResolverInterface $secondMethodsResolver, |
37
|
|
|
PrioritizedServiceRegistryInterface $resolversRegistry, |
38
|
|
|
ShippingMethodInterface $shippingMethod, |
39
|
|
|
ShippingSubjectInterface $shippingSubject |
40
|
|
|
): void { |
41
|
|
|
$resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]); |
42
|
|
|
|
43
|
|
|
$firstMethodsResolver->supports($shippingSubject)->willReturn(false); |
44
|
|
|
$secondMethodsResolver->supports($shippingSubject)->willReturn(true); |
45
|
|
|
|
46
|
|
|
$secondMethodsResolver->getSupportedMethods($shippingSubject)->willReturn([$shippingMethod]); |
47
|
|
|
|
48
|
|
|
$this->getSupportedMethods($shippingSubject)->shouldReturn([$shippingMethod]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_returns_empty_array_if_none_of_registered_resolvers_support_passed_shipping_subject( |
52
|
|
|
ShippingMethodsResolverInterface $firstMethodsResolver, |
53
|
|
|
ShippingMethodsResolverInterface $secondMethodsResolver, |
54
|
|
|
PrioritizedServiceRegistryInterface $resolversRegistry, |
55
|
|
|
ShippingSubjectInterface $shippingSubject |
56
|
|
|
): void { |
57
|
|
|
$resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]); |
58
|
|
|
|
59
|
|
|
$firstMethodsResolver->supports($shippingSubject)->willReturn(false); |
60
|
|
|
$secondMethodsResolver->supports($shippingSubject)->willReturn(false); |
61
|
|
|
|
62
|
|
|
$this->getSupportedMethods($shippingSubject)->shouldReturn([]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function it_supports_subject_if_any_resolver_from_registry_supports_it( |
66
|
|
|
ShippingMethodsResolverInterface $firstMethodsResolver, |
67
|
|
|
ShippingMethodsResolverInterface $secondMethodsResolver, |
68
|
|
|
PrioritizedServiceRegistryInterface $resolversRegistry, |
69
|
|
|
ShippingSubjectInterface $shippingSubject |
70
|
|
|
): void { |
71
|
|
|
$resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]); |
72
|
|
|
|
73
|
|
|
$firstMethodsResolver->supports($shippingSubject)->willReturn(false); |
74
|
|
|
$firstMethodsResolver->supports($shippingSubject)->willReturn(true); |
75
|
|
|
|
76
|
|
|
$this->supports($shippingSubject)->shouldReturn(true); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function it_does_not_support_subject_if_none_of_resolvers_from_registry_supports_it( |
80
|
|
|
ShippingMethodsResolverInterface $firstMethodsResolver, |
81
|
|
|
ShippingMethodsResolverInterface $secondMethodsResolver, |
82
|
|
|
PrioritizedServiceRegistryInterface $resolversRegistry, |
83
|
|
|
ShippingSubjectInterface $shippingSubject |
84
|
|
|
): void { |
85
|
|
|
$resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]); |
86
|
|
|
|
87
|
|
|
$firstMethodsResolver->supports($shippingSubject)->willReturn(false); |
88
|
|
|
$secondMethodsResolver->supports($shippingSubject)->willReturn(false); |
89
|
|
|
|
90
|
|
|
$this->supports($shippingSubject)->shouldReturn(false); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|