Completed
Pull Request — develop (#41)
by Vinicius
03:09
created

xmlSerializeMustAppendFormattedCustomerData()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
namespace PHPSC\PagSeguro\Customer;
3
4
class CustomerTest extends \PHPUnit_Framework_TestCase
5
{
6
    /**
7
     * @test
8
     */
9
    public function constructShouldConfigureTheAttributes()
10
    {
11
        $phone = new Phone(11, 999999999);
12
        $address = new Address('aa', 'aa', '2123', 'aa', 'asdad', 12312);
13
        $customer = new Customer('[email protected]', 'aa', $phone, $address);
14
15
        $this->assertAttributeEquals('[email protected]', 'email', $customer);
16
        $this->assertAttributeEquals('aa', 'name', $customer);
17
        $this->assertAttributeSame($phone, 'phone', $customer);
18
        $this->assertAttributeSame($address, 'address', $customer);
19
20
        return $customer;
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function gettersShouldRetrieveConfiguredData()
27
    {
28
        $phone = new Phone(11, 999999999);
29
        $address = new Address('aa', 'aa', '2123', 'aa', 'asdad', 12312);
30
        $customer = new Customer('[email protected]', 'aa', $phone, $address);
31
32
        $this->assertEquals('[email protected]', $customer->getEmail());
33
        $this->assertEquals('aa', $customer->getName());
34
        $this->assertSame($phone, $customer->getPhone());
35
        $this->assertSame($address, $customer->getAddress());
36
    }
37
38
    /**
39
     * @test
40
     */
41
    public function xmlSerializeMustAppendFormattedCustomerData()
42
    {
43
        $name = str_repeat('a', 55);
44
        $data = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />');
45
46
        $phone = new Phone(12, 999999989);
47
        $address = new Address('DF', 'Brasília', '70999-999', 'Plano Piloto', 'SQWN 17', 12, 'Apto 507');
48
        $customer = new Customer($name . '@test.com', $name, $phone, $address);
49
50
        $xml = $customer->xmlSerialize($data);
51
52
        $this->assertEquals($name . '@test.com', (string) $xml->sender->email);
53
        $this->assertEquals(str_repeat('a', 55), (string) $xml->sender->name);
54
55
        $this->assertEquals('BRA', (string) $xml->sender->address->country);
56
        $this->assertEquals('DF', (string) $xml->sender->address->state);
57
        $this->assertEquals('Brasília', (string) $xml->sender->address->city);
58
        $this->assertEquals('70999999', (string) $xml->sender->address->postalCode);
59
        $this->assertEquals('Plano Piloto', (string) $xml->sender->address->district);
60
        $this->assertEquals('SQWN 17', (string) $xml->sender->address->street);
61
        $this->assertEquals('12', (string) $xml->sender->address->number);
62
        $this->assertEquals('Apto 507', (string) $xml->sender->address->complement);
63
64
        $this->assertEquals(12, (string) $xml->sender->phone->areaCode);
65
        $this->assertEquals(999999989, (string) $xml->sender->phone->number);
66
    }
67
68
    /**
69
     * @test
70
     */
71
    public function xmlSerializeShouldNotAppendAddressIfItWasntInformed()
72
    {
73
        $name = str_repeat('a', 55);
74
        $data = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />');
75
76
        $phone = new Phone(12, 999999989);
77
        $customer = new Customer($name . '@test.com', $name, $phone);
78
79
        $xml = $customer->xmlSerialize($data);
80
81
        $this->assertEquals($name . '@test.com', (string) $xml->sender->email);
82
        $this->assertEquals(str_repeat('a', 55), (string) $xml->sender->name);
83
84
        $this->assertEquals(12, (string) $xml->sender->phone->areaCode);
85
        $this->assertEquals(999999989, (string) $xml->sender->phone->number);
86
87
        $this->assertEmpty($xml->xpath('//sender/address'));
88
    }
89
90
    /**
91
     * @test
92
     */
93
    public function xmlSerializeShouldNotAppendPhoneIfItWasntInformed()
94
    {
95
        $name = str_repeat('a', 55);
96
        $data = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />');
97
98
        $address = new Address('DF', 'Brasília', '70999-999', 'Plano Piloto', 'SQWN 17', 12, 'Apto 507');
99
        $customer = new Customer($name . '@test.com', $name, null, $address);
100
101
        $xml = $customer->xmlSerialize($data);
102
103
        $this->assertEquals($name . '@test.com', (string) $xml->sender->email);
104
        $this->assertEquals(str_repeat('a', 55), (string) $xml->sender->name);
105
106
        $this->assertEquals('BRA', (string) $xml->sender->address->country);
107
        $this->assertEquals('DF', (string) $xml->sender->address->state);
108
        $this->assertEquals('Brasília', (string) $xml->sender->address->city);
109
        $this->assertEquals('70999999', (string) $xml->sender->address->postalCode);
110
        $this->assertEquals('Plano Piloto', (string) $xml->sender->address->district);
111
        $this->assertEquals('SQWN 17', (string) $xml->sender->address->street);
112
        $this->assertEquals('12', (string) $xml->sender->address->number);
113
        $this->assertEquals('Apto 507', (string) $xml->sender->address->complement);
114
115
        $this->assertEmpty($xml->xpath('//sender/phone'));
116
    }
117
}
118