@@ -30,8 +30,7 @@ protected function setUp(): void
30
30
{
31
31
parent ::setUp ();
32
32
33
- $ config = new Auth ();
34
- $ this ->validator = new NothingPersonalValidator ($ config );
33
+ $ this ->validator = new NothingPersonalValidator (new Auth ());
35
34
}
36
35
37
36
public function testFalseOnPasswordIsEmail (): void
@@ -86,11 +85,8 @@ public function testTrueWhenPasswordHasNothingPersonal(): void
86
85
{
87
86
$ config = new Auth ();
88
87
$ config ->maxSimilarity = 50 ;
89
- $ config ->personalFields = [
90
- 'firstname ' ,
91
- 'lastname ' ,
92
- ];
93
- $ this ->validator = new NothingPersonalValidator ($ config );
88
+ $ config ->personalFields = ['firstname ' , 'lastname ' ];
89
+ $ this ->validator = new NothingPersonalValidator ($ config );
94
90
95
91
$ user = new User ([
96
92
'email ' => 'jsmith@example.com ' ,
@@ -110,11 +106,8 @@ public function testTrueWhenNoUsername(): void
110
106
{
111
107
$ config = new Auth ();
112
108
$ config ->maxSimilarity = 50 ;
113
- $ config ->personalFields = [
114
- 'firstname ' ,
115
- 'lastname ' ,
116
- ];
117
- $ this ->validator = new NothingPersonalValidator ($ config );
109
+ $ config ->personalFields = ['firstname ' , 'lastname ' ];
110
+ $ this ->validator = new NothingPersonalValidator ($ config );
118
111
119
112
$ user = new User ([
120
113
'email ' => 'jsmith@example.com ' ,
@@ -169,9 +162,9 @@ public function testFalseForSensibleMatch(): void
169
162
* $config->maxSimilarity = 50; is the highest setting where all tests pass.
170
163
*/
171
164
#[DataProvider('provideIsNotPersonalFalsePositivesCaughtByIsNotSimilar ' )]
172
- public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar (mixed $ password ): void
165
+ public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar (string $ password ): void
173
166
{
174
- new User ([
167
+ $ user = new User ([
175
168
'username ' => 'CaptainJoe ' ,
176
169
'email ' => 'JosephSmith@example.com ' ,
177
170
]);
@@ -180,16 +173,19 @@ public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar(mixed $passw
180
173
$ config ->maxSimilarity = 50 ;
181
174
$ this ->validator = new NothingPersonalValidator ($ config );
182
175
183
- $ isNotPersonal = $ this -> getPrivateMethodInvoker ($ this ->validator , 'isNotPersonal ' );
176
+ $ isNotPersonal = self :: getPrivateMethodInvoker ($ this ->validator , 'isNotPersonal ' );
184
177
185
- $ isNotSimilar = $ this -> getPrivateMethodInvoker ($ this ->validator , 'isNotSimilar ' );
178
+ $ isNotSimilar = self :: getPrivateMethodInvoker ($ this ->validator , 'isNotSimilar ' );
186
179
187
- $ this ->assertNotSame ($ isNotPersonal , $ isNotSimilar );
180
+ $ this ->assertNotSame ($ isNotPersonal( $ password , $ user ), $ isNotSimilar( $ password , $ user ) );
188
181
}
189
182
183
+ /**
184
+ * @return iterable<int, array{0: string}>
185
+ */
190
186
public static function provideIsNotPersonalFalsePositivesCaughtByIsNotSimilar (): iterable
191
187
{
192
- return [
188
+ yield from [
193
189
['JoeTheCaptain ' ],
194
190
['JoeCaptain ' ],
195
191
['CaptainJ ' ],
@@ -202,15 +198,12 @@ public static function provideIsNotPersonalFalsePositivesCaughtByIsNotSimilar():
202
198
}
203
199
204
200
#[DataProvider('provideConfigPersonalFieldsValues ' )]
205
- public function testConfigPersonalFieldsValues (mixed $ firstName , mixed $ lastName , mixed $ expected ): void
201
+ public function testConfigPersonalFieldsValues (string $ firstName , string $ lastName , bool $ expected ): void
206
202
{
207
203
$ config = new Auth ();
208
204
$ config ->maxSimilarity = 66 ;
209
- $ config ->personalFields = [
210
- 'firstname ' ,
211
- 'lastname ' ,
212
- ];
213
- $ this ->validator = new NothingPersonalValidator ($ config );
205
+ $ config ->personalFields = ['firstname ' , 'lastname ' ];
206
+ $ this ->validator = new NothingPersonalValidator ($ config );
214
207
215
208
$ user = new User ([
216
209
'username ' => 'Vlad the Impaler ' ,
@@ -226,9 +219,12 @@ public function testConfigPersonalFieldsValues(mixed $firstName, mixed $lastName
226
219
$ this ->assertSame ($ expected , $ result ->isOK ());
227
220
}
228
221
222
+ /**
223
+ * @return iterable<int, array{0: string, 1: string, 2: bool}>
224
+ */
229
225
public static function provideConfigPersonalFieldsValues (): iterable
230
226
{
231
- return [
227
+ yield from [
232
228
[
233
229
'Count ' ,
234
230
'' ,
@@ -248,7 +244,7 @@ public static function provideConfigPersonalFieldsValues(): iterable
248
244
}
249
245
250
246
#[DataProvider('provideMaxSimilarityZeroTurnsOffSimilarityCalculation ' )]
251
- public function testMaxSimilarityZeroTurnsOffSimilarityCalculation (mixed $ maxSimilarity , mixed $ expected ): void
247
+ public function testMaxSimilarityZeroTurnsOffSimilarityCalculation (int $ maxSimilarity , bool $ expected ): void
252
248
{
253
249
$ config = new Auth ();
254
250
$ config ->maxSimilarity = $ maxSimilarity ;
@@ -266,6 +262,9 @@ public function testMaxSimilarityZeroTurnsOffSimilarityCalculation(mixed $maxSim
266
262
$ this ->assertSame ($ expected , $ result ->isOK ());
267
263
}
268
264
265
+ /**
266
+ * @return iterable<int, array{0: int, 1: bool}>
267
+ */
269
268
public static function provideMaxSimilarityZeroTurnsOffSimilarityCalculation (): iterable
270
269
{
271
270
return [
@@ -298,6 +297,9 @@ public function testCheckPasswordWithBadEmail(string $email, bool $expected): vo
298
297
$ this ->assertSame ($ expected , $ result ->isOK ());
299
298
}
300
299
300
+ /**
301
+ * @return iterable<int, array{0: string, 1: bool}>
302
+ */
301
303
public static function provideCheckPasswordWithBadEmail (): iterable
302
304
{
303
305
return [
0 commit comments