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

xmlSerializeMustAppendFormattedShippingData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3143
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
namespace PHPSC\PagSeguro\Shipping;
3
4
use PHPSC\PagSeguro\Customer\Address;
5
6
class ShippingTest extends \PHPUnit_Framework_TestCase
7
{
8
    /**
9
     * @test
10
     * @expectedException \InvalidArgumentException
11
     */
12
    public function constructorMustRaiseExceptionWhenTypeIsInvalid()
13
    {
14
        new Shipping(-10);
15
    }
16
17
    /**
18
     * @test
19
     */
20 View Code Duplication
    public function constructorMustBeAbleToReceiveTypeOnly()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $shipping = new Shipping(Type::TYPE_PAC);
23
24
        $this->assertAttributeEquals(Type::TYPE_PAC, 'type', $shipping);
25
        $this->assertAttributeEquals(null, 'address', $shipping);
26
        $this->assertAttributeEquals(null, 'cost', $shipping);
27
    }
28
29
    /**
30
     * @test
31
     */
32 View Code Duplication
    public function constructorMustBeAbleToReceiveTypeAndCost()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $shipping = new Shipping(Type::TYPE_PAC, null, '10.31');
35
36
        $this->assertAttributeEquals(Type::TYPE_PAC, 'type', $shipping);
37
        $this->assertAttributeEquals(null, 'address', $shipping);
38
        $this->assertAttributeEquals(10.31, 'cost', $shipping);
39
    }
40
41
    /**
42
     * @test
43
     */
44 View Code Duplication
    public function constructorMustBeAbleToReceiveTypeAndAddress()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $address = $this->getMock(Address::class, [], [], '', false);
47
        $shipping = new Shipping(Type::TYPE_PAC, $address);
48
49
        $this->assertAttributeEquals(Type::TYPE_PAC, 'type', $shipping);
50
        $this->assertAttributeSame($address, 'address', $shipping);
51
        $this->assertAttributeEquals(null, 'cost', $shipping);
52
    }
53
54
    /**
55
     * @test
56
     */
57 View Code Duplication
    public function constructorMustBeAbleToReceiveAllArguments()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $address = $this->getMock(Address::class, [], [], '', false);
60
        $shipping = new Shipping(Type::TYPE_PAC, $address, '10.31');
61
62
        $this->assertAttributeEquals(Type::TYPE_PAC, 'type', $shipping);
63
        $this->assertAttributeSame($address, 'address', $shipping);
64
        $this->assertAttributeEquals(10.31, 'cost', $shipping);
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function getterShouldReturnConfiguredData()
71
    {
72
        $address = $this->getMock(Address::class, [], [], '', false);
73
        $shipping = new Shipping(Type::TYPE_PAC, $address, '10.31');
74
75
        $this->assertEquals(Type::TYPE_PAC, $shipping->getType());
76
        $this->assertSame($address, $shipping->getAddress());
77
        $this->assertEquals(10.31, $shipping->getCost());
78
    }
79
80
    /**
81
     * @test
82
     */
83
    public function xmlSerializeMustAppendFormattedShippingData()
84
    {
85
        $data = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />');
86
87
        $address = new Address('BA', 'Salvador', '40999-999', 'Red River', 'Beco Sem Nome', 25, 'Buteco do França');
88
        $shipping = new Shipping(Type::TYPE_PAC, $address, '10.31');
89
90
        $xml = $shipping->xmlSerialize($data);
91
92
        $this->assertEquals(1, (string) $xml->shipping->type);
93
        $this->assertEquals(10.31, (string) $xml->shipping->cost);
94
95
        $this->assertEquals('BRA', (string) $xml->shipping->address->country);
96
        $this->assertEquals('BA', (string) $xml->shipping->address->state);
97
        $this->assertEquals('Salvador', (string) $xml->shipping->address->city);
98
        $this->assertEquals('40999999', (string) $xml->shipping->address->postalCode);
99
        $this->assertEquals('Red River', (string) $xml->shipping->address->district);
100
        $this->assertEquals('Beco Sem Nome', (string) $xml->shipping->address->street);
101
        $this->assertEquals('25', (string) $xml->shipping->address->number);
102
        $this->assertEquals('Buteco do França', (string) $xml->shipping->address->complement);
103
    }
104
}
105