Passed
Push — develop ( 19a8b8...726e4d )
by Luís
29s
created

CheckoutBuilderTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 122
rs 10
1
<?php
2
namespace PHPSC\PagSeguro\Requests\Checkout;
3
4
use PHPSC\PagSeguro\Customer\Customer;
5
use PHPSC\PagSeguro\Items\Item;
6
use PHPSC\PagSeguro\Shipping\Shipping;
7
8
/**
9
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
10
 */
11
class CheckoutBuilderTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var Checkout
15
     */
16
    private $checkout;
17
18
    /**
19
     * @var CheckoutBuilder
20
     */
21
    private $builder;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function setUp()
27
    {
28
        $this->checkout = new Checkout();
29
        $this->builder = new CheckoutBuilder($this->checkout);
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function constructShouldConfigureAttributes()
36
    {
37
        $this->assertAttributeSame($this->checkout, 'checkout', $this->builder);
38
    }
39
40
    /**
41
     * @test
42
     */
43
    public function constructShouldCreateANewCheckoutWhenItWasntInformed()
44
    {
45
        $this->assertAttributeInstanceOf(
46
            Checkout::class,
47
            'checkout',
48
            new CheckoutBuilder()
49
        );
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function addItemShouldAppendTheGivenItem()
56
    {
57
        $item = new Item(1, 'testing', 10);
58
        $this->builder->addItem($item);
59
60
        $this->assertTrue($this->checkout->getOrder()->getItems()->contains($item));
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function setShippingShouldConfigureTheShipping()
67
    {
68
        $shipping = new Shipping(1);
69
        $this->builder->setShipping($shipping);
70
71
        $this->assertAttributeSame($shipping, 'shipping', $this->checkout->getOrder());
72
    }
73
74
    /**
75
     * @test
76
     */
77
    public function setReferenceShouldConfigureTheReference()
78
    {
79
        $this->builder->setReference('testing');
80
81
        $this->assertAttributeEquals('testing', 'reference', $this->checkout->getOrder());
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function setCustomerShouldConfigureTheReference()
88
    {
89
        $customer = new Customer('[email protected]');
90
        $this->builder->setCustomer($customer);
91
92
        $this->assertAttributeSame($customer, 'customer', $this->checkout);
93
    }
94
95
    /**
96
     * @test
97
     */
98
    public function setRedirectToShouldConfigureTheRedirectionUri()
99
    {
100
        $this->builder->setRedirectTo('http://test.com');
101
102
        $this->assertAttributeEquals('http://test.com', 'redirectTo', $this->checkout);
103
    }
104
105
    /**
106
     * @test
107
     */
108
    public function setMaxAgeShouldConfigureTheMaximumAge()
109
    {
110
        $this->builder->setMaxAge(1);
111
112
        $this->assertAttributeEquals(1, 'maxAge', $this->checkout);
113
    }
114
115
    /**
116
     * @test
117
     */
118
    public function setMaxUsesShouldTheNumberOfUses()
119
    {
120
        $this->builder->setMaxUses(1);
121
122
        $this->assertAttributeEquals(1, 'maxUses', $this->checkout);
123
    }
124
125
    /**
126
     * @test
127
     */
128
    public function getCheckoutShouldReturnTheConfiguredCheckout()
129
    {
130
        $this->assertSame($this->checkout, $this->builder->getCheckout());
131
    }
132
}
133