Completed
Push — master ( 85508a...fbb5f8 )
by Kamil
24:40
created

AddressComparatorSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 82
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_address_comparator_interface() 0 4 1
B it_returns_false_if_addresses_differ() 0 26 1
A it_returns_true_when_addresses_are_the_same() 0 15 1
B it_ignores_leading_and_trailing_spaces_or_letter_cases() 0 26 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
namespace spec\Sylius\Component\Addressing\Comparator;
13
14
use Sylius\Component\Addressing\Comparator\AddressComparator;
15
use PhpSpec\ObjectBehavior;
16
use Sylius\Component\Addressing\Comparator\AddressComparatorInterface;
17
use Sylius\Component\Addressing\Model\AddressInterface;
18
19
/**
20
 * @author Jan Góralski <[email protected]>
21
 */
22
final class AddressComparatorSpec extends ObjectBehavior
23
{
24
    function it_is_initializable()
25
    {
26
        $this->shouldHaveType(AddressComparator::class);
27
    }
28
29
    function it_implements_address_comparator_interface()
30
    {
31
        $this->shouldImplement(AddressComparatorInterface::class);
32
    }
33
34
    function it_returns_false_if_addresses_differ(AddressInterface $firstAddress, AddressInterface $secondAddress)
35
    {
36
        $firstAddress->getCity()->willReturn('Stoke-On-Trent');
37
        $firstAddress->getStreet()->willReturn('Villiers St');
38
        $firstAddress->getCompany()->willReturn('Pizzeria');
39
        $firstAddress->getPostcode()->willReturn('ST3 4HB');
40
        $firstAddress->getLastName()->willReturn('Johnson');
41
        $firstAddress->getFirstName()->willReturn('Gerald');
42
        $firstAddress->getPhoneNumber()->willReturn('000');
43
        $firstAddress->getCountryCode()->willReturn('UK');
44
        $firstAddress->getProvinceCode()->willReturn('UK-WestMidlands');
45
        $firstAddress->getProvinceName()->willReturn(null);
46
47
        $secondAddress->getCity()->willReturn('Toowoomba');
48
        $secondAddress->getStreet()->willReturn('Ryans Dr');
49
        $secondAddress->getCompany()->willReturn('Burger');
50
        $secondAddress->getPostcode()->willReturn('4350');
51
        $secondAddress->getLastName()->willReturn('Jones');
52
        $secondAddress->getFirstName()->willReturn('Mia');
53
        $secondAddress->getPhoneNumber()->willReturn('999');
54
        $secondAddress->getCountryCode()->willReturn('AU');
55
        $secondAddress->getProvinceCode()->willReturn(null);
56
        $secondAddress->getProvinceName()->willReturn('Queensland');
57
58
        $this->same($firstAddress, $secondAddress)->shouldReturn(false);
59
    }
60
61
    function it_returns_true_when_addresses_are_the_same(AddressInterface $address)
62
    {
63
        $address->getCity()->willReturn('Toowoomba');
64
        $address->getStreet()->willReturn('Ryans Dr');
65
        $address->getCompany()->willReturn('Burger');
66
        $address->getPostcode()->willReturn('4350');
67
        $address->getLastName()->willReturn('Jones');
68
        $address->getFirstName()->willReturn('Mia');
69
        $address->getPhoneNumber()->willReturn('999');
70
        $address->getCountryCode()->willReturn('AU');
71
        $address->getProvinceCode()->willReturn(null);
72
        $address->getProvinceName()->willReturn('Queensland');
73
74
        $this->same($address, $address)->shouldReturn(true);
75
    }
76
77
    function it_ignores_leading_and_trailing_spaces_or_letter_cases(AddressInterface $firstAddress, AddressInterface $secondAddress)
78
    {
79
        $firstAddress->getCity()->willReturn('TOOWOOMBA');
80
        $firstAddress->getStreet()->willReturn('Ryans Dr     ');
81
        $firstAddress->getCompany()->willReturn('   Burger');
82
        $firstAddress->getPostcode()->willReturn(' 4350 ');
83
        $firstAddress->getLastName()->willReturn('jones ');
84
        $firstAddress->getFirstName()->willReturn('mIa');
85
        $firstAddress->getPhoneNumber()->willReturn(' 999');
86
        $firstAddress->getCountryCode()->willReturn('au');
87
        $firstAddress->getProvinceCode()->willReturn(null);
88
        $firstAddress->getProvinceName()->willReturn('qUEENSLAND');
89
90
        $secondAddress->getCity()->willReturn('Toowoomba');
91
        $secondAddress->getStreet()->willReturn('Ryans Dr');
92
        $secondAddress->getCompany()->willReturn('Burger');
93
        $secondAddress->getPostcode()->willReturn('4350');
94
        $secondAddress->getLastName()->willReturn('Jones');
95
        $secondAddress->getFirstName()->willReturn('Mia');
96
        $secondAddress->getPhoneNumber()->willReturn('999');
97
        $secondAddress->getCountryCode()->willReturn('AU');
98
        $secondAddress->getProvinceCode()->willReturn(null);
99
        $secondAddress->getProvinceName()->willReturn('Queensland');
100
101
        $this->same($firstAddress, $secondAddress)->shouldReturn(true);
102
    }
103
}
104