Passed
Push — develop ( 726e4d...2a8883 )
by Luís
37s
created

ChargeBuilderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 38
rs 10
1
<?php
2
namespace PHPSC\PagSeguro\Purchases\Subscriptions;
3
4
use PHPSC\PagSeguro\Purchases\ChargeBuilder as ChargeBuilderInterface;
5
use PHPSC\PagSeguro\Items\Item;
6
use PHPSC\PagSeguro\Items\Items;
7
8
/**
9
 * @author Renato Moura <[email protected]>
10
 */
11
class ChargeBuilderTest extends \PHPUnit_Framework_TestCase
12
{
13
    private $charge;
14
15
    protected function setUp()
16
    {
17
        $this->charge = $this->createMock(Charge::class);
18
19
        $this->charge->expects($this->once())
20
                         ->method('setSubscriptionCode')
21
                         ->with('123456');
22
    }
23
24
    public function testConstructShouldDoCallSetSubscription()
25
    {
26
        $builder = new ChargeBuilder('123456', $this->charge);
27
28
        $this->assertInstanceOf(ChargeBuilderInterface::class, $builder);
29
        $this->assertEquals($this->charge, $builder->getCharge());
30
31
    }
32
33
    public function testAddItemShouldDoCallAddInChargeAndReturnSelfObject()
34
    {
35
        $item = new Item(99, 'Produto 03', 1.77, 8, 12.9, 360);
36
        $items = $this->createMock(Items::class);
37
        $items->expects($this->once())->method('add')->with($item);
38
        $this->charge->expects($this->once())
39
                     ->method('getItems')
40
                     ->willReturn($items);
41
42
        $builder = new ChargeBuilder('123456', $this->charge);
43
44
        $this->assertEquals($builder, $builder->addItem($item));
45
    }
46
47
    public function testsetReferenceShouldDoCallInChargeAndReturnSelfObject()
48
    {
49
        $this->charge->expects($this->once())
50
                     ->method('setReference')
51
                     ->with('ABCDE');
52
53
        $builder = new ChargeBuilder('123456', $this->charge);
54
55
        $this->assertEquals($builder, $builder->setReference('ABCDE'));
56
    }
57
}
58