1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Requests\Checkout; |
3
|
|
|
|
4
|
|
|
use PHPSC\PagSeguro\Customer\Customer; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
class CheckoutTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Checkout |
13
|
|
|
*/ |
14
|
|
|
private $checkout; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var Order |
18
|
|
|
*/ |
19
|
|
|
private $order; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->order = new Order(); |
27
|
|
|
$this->checkout = new Checkout($this->order); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
*/ |
33
|
|
|
public function constructShouldConfigureAttributes() |
34
|
|
|
{ |
35
|
|
|
$this->assertAttributeSame($this->order, 'order', $this->checkout); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @test |
40
|
|
|
*/ |
41
|
|
|
public function constructShouldCreateANewOrderWhenItWasntInformed() |
42
|
|
|
{ |
43
|
|
|
$this->assertAttributeInstanceOf( |
44
|
|
|
Order::class, |
45
|
|
|
'order', |
46
|
|
|
new Checkout() |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getOrderShouldReturnConfiguredOrder() |
51
|
|
|
{ |
52
|
|
|
$this->assertSame($this->order, $this->checkout->getOrder()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @test |
57
|
|
|
*/ |
58
|
|
|
public function setCustomerShouldConfigureTheReference() |
59
|
|
|
{ |
60
|
|
|
$customer = new Customer('[email protected]'); |
61
|
|
|
$this->checkout->setCustomer($customer); |
62
|
|
|
|
63
|
|
|
$this->assertAttributeSame($customer, 'customer', $this->checkout); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @test |
68
|
|
|
*/ |
69
|
|
|
public function setRedirectToShouldConfigureTheRedirectionUri() |
70
|
|
|
{ |
71
|
|
|
$this->checkout->setRedirectTo('http://test.com'); |
72
|
|
|
|
73
|
|
|
$this->assertAttributeEquals('http://test.com', 'redirectTo', $this->checkout); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @test |
78
|
|
|
*/ |
79
|
|
|
public function setMaxAgeShouldConfigureTheMaximumAge() |
80
|
|
|
{ |
81
|
|
|
$this->checkout->setMaxAge(1); |
82
|
|
|
|
83
|
|
|
$this->assertAttributeEquals(1, 'maxAge', $this->checkout); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @test |
88
|
|
|
*/ |
89
|
|
|
public function setMaxUsesShouldTheNumberOfUses() |
90
|
|
|
{ |
91
|
|
|
$this->checkout->setMaxUses(1); |
92
|
|
|
|
93
|
|
|
$this->assertAttributeEquals(1, 'maxUses', $this->checkout); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @test |
98
|
|
|
*/ |
99
|
|
|
public function getMaxAgeShouldReturnConfiguredMaxAge() |
100
|
|
|
{ |
101
|
|
|
$this->checkout->setMaxAge(12); |
102
|
|
|
|
103
|
|
|
$this->assertEquals(12, $this->checkout->getMaxAge()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @test |
108
|
|
|
*/ |
109
|
|
|
public function getMaxUsesShouldReturnConfiguredMaxUses() |
110
|
|
|
{ |
111
|
|
|
$this->checkout->setMaxUses(7); |
112
|
|
|
|
113
|
|
|
$this->assertEquals(7, $this->checkout->getMaxUses()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @test |
118
|
|
|
*/ |
119
|
|
|
public function getRedirectToShouldReturnConfiguredRedirectTo() |
120
|
|
|
{ |
121
|
|
|
$this->checkout->setRedirectTo('someRedirect'); |
122
|
|
|
|
123
|
|
|
$this->assertEquals('someRedirect', $this->checkout->getRedirectTo()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @test |
128
|
|
|
*/ |
129
|
|
|
public function getCustomerShouldReturnConfiguredCustomer() |
130
|
|
|
{ |
131
|
|
|
$customer = $this->getMock(Customer::class, [], [], '', false); |
132
|
|
|
$this->checkout->setCustomer($customer); |
133
|
|
|
|
134
|
|
|
$this->assertSame($customer, $this->checkout->getCustomer()); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @test |
139
|
|
|
*/ |
140
|
|
|
public function setNotificationURLShouldConfigureTheNotificationUri() |
141
|
|
|
{ |
142
|
|
|
$uri = 'http://chibungo.com'; |
143
|
|
|
$this->checkout->setNotificationURL($uri); |
144
|
|
|
$this->assertAttributeEquals($uri, 'notificationURL', $this->checkout); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|