1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Items; |
3
|
|
|
|
4
|
|
|
class ItemTest extends \PHPUnit_Framework_TestCase |
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* @var Item |
8
|
|
|
*/ |
9
|
|
|
protected $item; |
10
|
|
|
|
11
|
|
|
protected function setUp() |
12
|
|
|
{ |
13
|
|
|
$this->item = new Item( |
14
|
|
|
str_repeat('01', 51), |
15
|
|
|
str_repeat('a very long description', 100), |
16
|
|
|
150.23, |
17
|
|
|
3, |
18
|
|
|
10.30, |
19
|
|
|
123 |
20
|
|
|
); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @test |
25
|
|
|
*/ |
26
|
|
|
public function constructorShouldConfigureTheAttributes() |
27
|
|
|
{ |
28
|
|
|
$this->assertAttributeEquals(str_repeat('01', 51), 'id', $this->item); |
29
|
|
|
$this->assertAttributeEquals(str_repeat('a very long description', 100), 'description', $this->item); |
30
|
|
|
$this->assertAttributeEquals(150.23, 'amount', $this->item); |
31
|
|
|
$this->assertAttributeEquals(3, 'quantity', $this->item); |
32
|
|
|
$this->assertAttributeEquals(10.30, 'shippingCost', $this->item); |
33
|
|
|
$this->assertAttributeEquals('123', 'weight', $this->item); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @test |
38
|
|
|
*/ |
39
|
|
|
public function gettersShouldReturnTheAttributeValue() |
40
|
|
|
{ |
41
|
|
|
$this->assertAttributeEquals($this->item->getId(), 'id', $this->item); |
42
|
|
|
$this->assertAttributeEquals($this->item->getDescription(), 'description', $this->item); |
43
|
|
|
$this->assertAttributeEquals($this->item->getAmount(), 'amount', $this->item); |
44
|
|
|
$this->assertAttributeEquals($this->item->getQuantity(), 'quantity', $this->item); |
45
|
|
|
$this->assertAttributeEquals($this->item->getShippingCost(), 'shippingCost', $this->item); |
46
|
|
|
$this->assertAttributeEquals($this->item->getWeight(), 'weight', $this->item); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
*/ |
52
|
|
|
public function xmlSerializeMustAppendFormattedItemData() |
53
|
|
|
{ |
54
|
|
|
$data = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />'); |
55
|
|
|
$xml = $this->item->xmlSerialize($data); |
56
|
|
|
|
57
|
|
|
$this->assertEquals(str_repeat('01', 51), (string) $xml->item->id); |
58
|
|
|
$this->assertEquals(str_repeat('a very long description', 100), (string) $xml->item->description); |
59
|
|
|
$this->assertEquals(150.23, (string) $xml->item->amount); |
60
|
|
|
$this->assertEquals(3, (string) $xml->item->quantity); |
61
|
|
|
$this->assertEquals(10.30, (string) $xml->item->shippingCost); |
62
|
|
|
$this->assertEquals('123', (string) $xml->item->weight); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|