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

ChargeTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 61
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A constructShouldConfigureTheAttributes() 0 4 1
A setReferenceShouldConfigureTheReference() 0 8 1
A setSubscriptionCodeShouldConfigureTheSubscriptionCode() 0 8 1
A testSerializeShouldXMLFull() 0 16 1
1
<?php
2
namespace PHPSC\PagSeguro\Purchases\Subscriptions;
3
4
use SimpleXMLElement;
5
use PHPSC\PagSeguro\Items\Items;
6
use PHPSC\PagSeguro\Items\Item;
7
use PHPSC\PagSeguro\Items\ItemCollection;
8
9
/**
10
 * @author Adelar Tiemann Junior <[email protected]>
11
 */
12
class ChargeTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @var Charge
16
     */
17
    private $charge;
18
19
    protected function setUp()
20
    {
21
        $this->charge = new Charge();
22
    }
23
24
    /**
25
     * @test
26
     */
27
    public function constructShouldConfigureTheAttributes()
28
    {
29
        $this->assertInstanceOf(ItemCollection::class, $this->charge->getItems());
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function setReferenceShouldConfigureTheReference()
36
    {
37
        $charge = new Charge();
38
        $charge->setReference('SomeRef');
39
        
40
        $this->assertAttributeEquals('SomeRef', 'reference', $charge);
41
        $this->assertEquals('SomeRef', $charge->getReference());
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function setSubscriptionCodeShouldConfigureTheSubscriptionCode()
48
    {
49
        $charge = new Charge();
50
        $charge->setSubscriptionCode('SomeSubscription');
51
        
52
        $this->assertAttributeEquals('SomeSubscription', 'subscriptionCode', $charge);
53
        $this->assertEquals('SomeSubscription', $charge->getSubscriptionCode());
54
    }
55
56
    public function testSerializeShouldXMLFull()
57
    {
58
        $items = new Items;
59
        $items->add(new Item(99, 'Produto 03', 1.77, 8, 12.9, 360));
60
        $items->add(new Item(97, 'Produto 04', 43.67, 3, 134.98, 1100));
61
62
        $charge = new Charge($items);
63
        $charge->setSubscriptionCode(4556788);
64
        $charge->setReference('abcdef');
65
66
        $xml = $charge->xmlSerialize();
67
68
        $this->assertInstanceOf(SimpleXMLElement::class, $xml);
69
        $expected = simplexml_load_file(__DIR__.'/xml/chargeFull.xml');
70
        $this->assertEquals($expected, $xml);
71
    }
72
}
73