1
|
|
|
<?php |
2
|
|
|
namespace DavidePastore\CodiceFiscale; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Test for the Calculator class. |
6
|
|
|
* @author davidepastore |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
class CalculatorTest extends \PHPUnit_Framework_TestCase { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Test for calculate. |
13
|
|
|
* @dataProvider calculateProvider |
14
|
|
|
*/ |
15
|
|
|
public function testCalculate($subject, $omocodiaLevel, $expectedCodiceFiscale){ |
16
|
|
|
$calculator = new Calculator($subject, array( |
17
|
|
|
"omocodiaLevel" => $omocodiaLevel |
18
|
|
|
)); |
19
|
|
|
$actual = $calculator->calculate(); |
20
|
|
|
$this->assertEquals($expectedCodiceFiscale, $actual); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Test for calculateAllPossibilities. |
25
|
|
|
* @dataProvider calculateAllPossibilitiesProvider |
26
|
|
|
*/ |
27
|
|
|
public function testCalculateAllPossibilities($subject, $expected){ |
28
|
|
|
$calculator = new Calculator($subject); |
29
|
|
|
$actual = $calculator->calculateAllPossibilities(); |
30
|
|
|
$this->assertEquals($expected, $actual); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The calculate data provider. |
35
|
|
|
*/ |
36
|
|
|
public function calculateProvider(){ |
37
|
|
|
return array( |
38
|
|
|
array( |
39
|
|
|
new Subject( |
40
|
|
|
array( |
41
|
|
|
"name" => "Mario", |
42
|
|
|
"surname" => "Rossi", |
43
|
|
|
"birthDate" => "1985-12-10", |
44
|
|
|
"gender" => "M", |
45
|
|
|
"belfioreCode" => "A562" |
46
|
|
|
) |
47
|
|
|
), |
48
|
|
|
0, |
49
|
|
|
"RSSMRA85T10A562S" |
50
|
|
|
), |
51
|
|
|
array( |
52
|
|
|
new Subject( |
53
|
|
|
array( |
54
|
|
|
"name" => "Roberto", |
55
|
|
|
"surname" => "Santini", |
56
|
|
|
"birthDate" => "1963-05-08", |
57
|
|
|
"gender" => "M", |
58
|
|
|
"belfioreCode" => "H501" |
59
|
|
|
) |
60
|
|
|
), |
61
|
|
|
0, |
62
|
|
|
"SNTRRT63E08H501T" |
63
|
|
|
), |
64
|
|
|
array( |
65
|
|
|
new Subject( |
66
|
|
|
array( |
67
|
|
|
"name" => "Maria", |
68
|
|
|
"surname" => "Montessori", |
69
|
|
|
"birthDate" => "1870-08-31", |
70
|
|
|
"gender" => "F", |
71
|
|
|
"belfioreCode" => "C615" |
72
|
|
|
) |
73
|
|
|
), |
74
|
|
|
0, |
75
|
|
|
"MNTMRA70M71C615I" |
76
|
|
|
), |
77
|
|
|
array( |
78
|
|
|
new Subject( |
79
|
|
|
array( |
80
|
|
|
"name" => "Mario", |
81
|
|
|
"surname" => "Rossi", |
82
|
|
|
"birthDate" => new \DateTime('1985-12-10'), |
83
|
|
|
"gender" => "M", |
84
|
|
|
"belfioreCode" => "A562" |
85
|
|
|
) |
86
|
|
|
), |
87
|
|
|
0, |
88
|
|
|
"RSSMRA85T10A562S" |
89
|
|
|
), |
90
|
|
|
array( |
91
|
|
|
new Subject( |
92
|
|
|
array( |
93
|
|
|
"name" => "Gianfranco", |
94
|
|
|
"surname" => "Rossi", |
95
|
|
|
"birthDate" => "1985-12-10", |
96
|
|
|
"gender" => "M", |
97
|
|
|
"belfioreCode" => "A562" |
98
|
|
|
) |
99
|
|
|
), |
100
|
|
|
0, |
101
|
|
|
"RSSGFR85T10A562I" |
102
|
|
|
), |
103
|
|
|
array( |
104
|
|
|
new Subject( |
105
|
|
|
array( |
106
|
|
|
"name" => "Mario", |
107
|
|
|
"surname" => "Fo", |
108
|
|
|
"birthDate" => "1985-12-10", |
109
|
|
|
"gender" => "M", |
110
|
|
|
"belfioreCode" => "A562" |
111
|
|
|
) |
112
|
|
|
), |
113
|
|
|
0, |
114
|
|
|
"FOXMRA85T10A562G" |
115
|
|
|
), |
116
|
|
|
array( |
117
|
|
|
new Subject( |
118
|
|
|
array( |
119
|
|
|
"name" => "", |
120
|
|
|
"surname" => "Rossi", |
121
|
|
|
"birthDate" => "1985-12-10", |
122
|
|
|
"gender" => "M", |
123
|
|
|
"belfioreCode" => "A562" |
124
|
|
|
) |
125
|
|
|
), |
126
|
|
|
0, |
127
|
|
|
"RSSXXX85T10A562R" |
128
|
|
|
), |
129
|
|
|
array( |
130
|
|
|
new Subject( |
131
|
|
|
array( |
132
|
|
|
"name" => "Mario", |
133
|
|
|
"surname" => "", |
134
|
|
|
"birthDate" => "1985-12-10", |
135
|
|
|
"gender" => "M", |
136
|
|
|
"belfioreCode" => "A562" |
137
|
|
|
) |
138
|
|
|
), |
139
|
|
|
0, |
140
|
|
|
"XXXMRA85T10A562B" |
141
|
|
|
), |
142
|
|
|
array( |
143
|
|
|
new Subject( |
144
|
|
|
array( |
145
|
|
|
"name" => "", |
146
|
|
|
"surname" => "", |
147
|
|
|
"birthDate" => "1985-12-10", |
148
|
|
|
"gender" => "M", |
149
|
|
|
"belfioreCode" => "A562" |
150
|
|
|
) |
151
|
|
|
), |
152
|
|
|
0, |
153
|
|
|
"XXXXXX85T10A562A" |
154
|
|
|
), |
155
|
|
|
array( |
156
|
|
|
new Subject( |
157
|
|
|
array( |
158
|
|
|
"name" => "Roberto", |
159
|
|
|
"surname" => "Santi", |
160
|
|
|
"birthDate" => "1963-05-08", |
161
|
|
|
"gender" => "M", |
162
|
|
|
"belfioreCode" => "H501" |
163
|
|
|
) |
164
|
|
|
), |
165
|
|
|
1, |
166
|
|
|
"SNTRRT63E08H50ML" |
167
|
|
|
), |
168
|
|
|
array( |
169
|
|
|
new Subject( |
170
|
|
|
array( |
171
|
|
|
"name" => "Mario", |
172
|
|
|
"surname" => "Rossi", |
173
|
|
|
"birthDate" => "1985-12-10", |
174
|
|
|
"gender" => "M", |
175
|
|
|
"belfioreCode" => "A562" |
176
|
|
|
) |
177
|
|
|
), |
178
|
|
|
1, |
179
|
|
|
"RSSMRA85T10A56NH" |
180
|
|
|
), |
181
|
|
|
array( |
182
|
|
|
new Subject( |
183
|
|
|
array( |
184
|
|
|
"name" => "Mario", |
185
|
|
|
"surname" => "Rossi", |
186
|
|
|
"birthDate" => "1985-12-10", |
187
|
|
|
"gender" => "M", |
188
|
|
|
"belfioreCode" => "A562" |
189
|
|
|
) |
190
|
|
|
), |
191
|
|
|
3, |
192
|
|
|
"RSSMRA85T10ARSNO" |
193
|
|
|
) |
194
|
|
|
); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* The calculate all possibilities data provider. |
199
|
|
|
*/ |
200
|
|
|
public function calculateAllPossibilitiesProvider(){ |
201
|
|
|
return array( |
202
|
|
|
array( |
203
|
|
|
new Subject( |
204
|
|
|
array( |
205
|
|
|
"name" => "Mario", |
206
|
|
|
"surname" => "Rossi", |
207
|
|
|
"birthDate" => "1985-12-10", |
208
|
|
|
"gender" => "M", |
209
|
|
|
"belfioreCode" => "A562" |
210
|
|
|
) |
211
|
|
|
), |
212
|
|
|
array( |
213
|
|
|
"RSSMRA85T10A562S", |
214
|
|
|
"RSSMRA85T10A56NH", |
215
|
|
|
"RSSMRA85T10A5SNT", |
216
|
|
|
"RSSMRA85T10ARSNO", |
217
|
|
|
"RSSMRA85T1LARSNR", |
218
|
|
|
"RSSMRA85TMLARSNC", |
219
|
|
|
"RSSMRA8RTMLARSNO", |
220
|
|
|
"RSSMRAURTMLARSNL" |
221
|
|
|
) |
222
|
|
|
), |
223
|
|
|
array( |
224
|
|
|
new Subject( |
225
|
|
|
array( |
226
|
|
|
"name" => "Roberto", |
227
|
|
|
"surname" => "Santi", |
228
|
|
|
"birthDate" => "1963-05-08", |
229
|
|
|
"gender" => "M", |
230
|
|
|
"belfioreCode" => "H501" |
231
|
|
|
) |
232
|
|
|
), |
233
|
|
|
array( |
234
|
|
|
"SNTRRT63E08H501T", |
235
|
|
|
"SNTRRT63E08H50ML", |
236
|
|
|
"SNTRRT63E08H5LMW", |
237
|
|
|
"SNTRRT63E08HRLMR", |
238
|
|
|
"SNTRRT63E0UHRLMO", |
239
|
|
|
"SNTRRT63ELUHRLMZ", |
240
|
|
|
"SNTRRT6PELUHRLML", |
241
|
|
|
"SNTRRTSPELUHRLMI" |
242
|
|
|
) |
243
|
|
|
) |
244
|
|
|
); |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|