forked from merklik/refactoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomerTest.php
169 lines (142 loc) · 3.81 KB
/
CustomerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
require_once('Customer.php');
require_once('Rental.php');
require_once('Movie.php');
class CustomerTest extends PHPUnit_Framework_TestCase
{
/** @var \Refactoring\Customer */
public $customer;
public function setUp()
{
$this->customer = new \Refactoring\Customer("Joe");
}
/**
* @test
*/
public function statment_OneRental_Childrens()
{
//Arrange
$this->addRental("Rambo 1", \Refactoring\Movie::CHILDRENS, 1);
// Act
$s = $this->customer->getStatementData();
// Assert
$expected = array(
'name' => "Joe",
'charge' => 1.5,
'points' => 1,
'rentals' => array(
array
(
'title' => "Rambo 1",
'charge' => 1.5,
)
)
);
$this->assertEquals($expected, $s);
}
/**
* @test
*/
public function statment_TwoRentalsOneDay_NewRelease()
{
// Arrange
$this->addRental("Rambo 1", \Refactoring\Movie::CHILDRENS, 1);
$this->addRental("Rambo 2", \Refactoring\Movie::NEW_RELEASE, 1);
// Act
$s = $this->customer->getStatementData();
// Assert
$expected = array(
'name' => "Joe",
'charge' => 4.5,
'points' => 2,
'rentals' => array(
array
(
'title' => "Rambo 1",
'charge' => 1.5,
),
array
(
'title' => "Rambo 2",
'charge' => 3,
)
)
);
$this->assertEquals($expected, $s);
}
/**
* @test
*/
public function statment_TwoRentals_NewRelease()
{
// Arrange
$this->addRental("Rambo 1", \Refactoring\Movie::CHILDRENS, 1);
$this->addRental("Rambo 2", \Refactoring\Movie::NEW_RELEASE, 2);
// Act
$s = $this->customer->getStatementData();
// Assert
$expected = array(
'name' => "Joe",
'charge' => 7.5,
'points' => 3,
'rentals' => array(
array
(
'title' => "Rambo 1",
'charge' => 1.5,
),
array
(
'title' => "Rambo 2",
'charge' => 6,
)
)
);
$this->assertEquals($expected, $s);
}
/**
* @test
*/
public function statment_ThreeRentals_NewRelease()
{
// Arrange
$this->addRental("Rambo 1", \Refactoring\Movie::CHILDRENS, 1);
$this->addRental("Rambo 2", \Refactoring\Movie::NEW_RELEASE, 2);
$this->addRental("Rambo 3", \Refactoring\Movie::REGULAR, 1);
// Act
$s = $this->customer->getStatementData();
//Assert
$expected = array(
'name' => "Joe",
'charge' => 9.5,
'points' => 4,
'rentals' => array(
array
(
'title' => "Rambo 1",
'charge' => 1.5,
),
array
(
'title' => "Rambo 2",
'charge' => 6,
),
array
(
'title' => "Rambo 3",
'charge' => 2,
)
)
);
$this->assertEquals($expected, $s);
}
/**
* @param $title
* @param $priceCode
* @param $days
*/
public function addRental($title, $priceCode, $days)
{
$this->customer->addRental(new \Refactoring\Rental(new \Refactoring\Movie($title, $priceCode), $days));
}
}