Completed
Push — scalar-types/theme ( 71f30c )
by Kamil
21:15
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\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
/**
23
 * @author Mateusz Zalewski <[email protected]>
24
 */
25
final class CompositeMethodsResolverSpec extends ObjectBehavior
26
{
27
    function let(PrioritizedServiceRegistryInterface $resolversRegistry): void
28
    {
29
        $this->beConstructedWith($resolversRegistry);
30
    }
31
32
    function it_implements_methods_resolver_interface(): void
33
    {
34
        $this->shouldImplement(ShippingMethodsResolverInterface::class);
35
    }
36
37
    function it_uses_registry_to_provide_shipping_methods_for_shipping_subject(
38
        ShippingMethodsResolverInterface $firstMethodsResolver,
39
        ShippingMethodsResolverInterface $secondMethodsResolver,
40
        PrioritizedServiceRegistryInterface $resolversRegistry,
41
        ShippingMethodInterface $shippingMethod,
42
        ShippingSubjectInterface $shippingSubject
43
    ): void {
44
        $resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]);
45
46
        $firstMethodsResolver->supports($shippingSubject)->willReturn(false);
47
        $secondMethodsResolver->supports($shippingSubject)->willReturn(true);
48
49
        $secondMethodsResolver->getSupportedMethods($shippingSubject)->willReturn([$shippingMethod]);
50
51
        $this->getSupportedMethods($shippingSubject)->shouldReturn([$shippingMethod]);
52
    }
53
54
    function it_returns_empty_array_if_none_of_registered_resolvers_support_passed_shipping_subject(
55
        ShippingMethodsResolverInterface $firstMethodsResolver,
56
        ShippingMethodsResolverInterface $secondMethodsResolver,
57
        PrioritizedServiceRegistryInterface $resolversRegistry,
58
        ShippingSubjectInterface $shippingSubject
59
    ): void {
60
        $resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]);
61
62
        $firstMethodsResolver->supports($shippingSubject)->willReturn(false);
63
        $secondMethodsResolver->supports($shippingSubject)->willReturn(false);
64
65
        $this->getSupportedMethods($shippingSubject)->shouldReturn([]);
66
    }
67
68
    function it_supports_subject_if_any_resolver_from_registry_supports_it(
69
        ShippingMethodsResolverInterface $firstMethodsResolver,
70
        ShippingMethodsResolverInterface $secondMethodsResolver,
71
        PrioritizedServiceRegistryInterface $resolversRegistry,
72
        ShippingSubjectInterface $shippingSubject
73
    ): void {
74
        $resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]);
75
76
        $firstMethodsResolver->supports($shippingSubject)->willReturn(false);
77
        $firstMethodsResolver->supports($shippingSubject)->willReturn(true);
78
79
        $this->supports($shippingSubject)->shouldReturn(true);
80
    }
81
82
    function it_does_not_support_subject_if_none_of_resolvers_from_registry_supports_it(
83
        ShippingMethodsResolverInterface $firstMethodsResolver,
84
        ShippingMethodsResolverInterface $secondMethodsResolver,
85
        PrioritizedServiceRegistryInterface $resolversRegistry,
86
        ShippingSubjectInterface $shippingSubject
87
    ): void {
88
        $resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]);
89
90
        $firstMethodsResolver->supports($shippingSubject)->willReturn(false);
91
        $secondMethodsResolver->supports($shippingSubject)->willReturn(false);
92
93
        $this->supports($shippingSubject)->shouldReturn(false);
94
    }
95
}
96