Passed
Pull Request — master (#9)
by lee
03:23
created

IntegrationTest::strongAlphanumericFormatOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace DeGraciaMathieu\Riddler\Tests;
4
5
use DeGraciaMathieu\Riddler\Formats;
6
use DeGraciaMathieu\Riddler\Criteria;
7
use DeGraciaMathieu\Riddler\Password;
8
use DeGraciaMathieu\Riddler\Occurrences;
9
use DeGraciaMathieu\Riddler\Dictionaries;
10
use PHPUnit\Framework\TestCase;
11
12
class IntegrationTest extends TestCase
13
{
14
    /** @test */
15
    public function emptyPassword()
16
    {
17
        $pw = new Password();
18
19
        $str = $pw->generate();
20
21
        $this->assertEmpty($str);
22
    }
23
24
    /** @test */
25 View Code Duplication
    public function letterPasswordOnly()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $pw = new Password();
28
29
        $pw->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(10));
30
31
        $str = $pw->generate();
32
33
        $this->assertNotEmpty($str);
34
35
        $this->assertRegExp('/[a-z]/', $str);
36
    }
37
38
    /** @test */
39
    public function alphanumericPasswordOnly()
40
    {
41
        $pw = new Password();
42
43
        $pw->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(5));
44
        $pw->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(5));
45
        $pw->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(5));
46
47
        $str = $pw->generate();
48
49
        $this->assertNotEmpty($str);
50
51
        $this->assertEquals(15, mb_strlen($str));
52
53
        $this->assertRegExp('/[a-zA-Z0-9]/', $str);
54
    }
55
56
    /** @test */
57 View Code Duplication
    public function accentedLetterOnly()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $pw = new Password();
60
61
        $accentedLetter = new Dictionaries\AccentedLetter();
62
63
        $pw->addCriteria($accentedLetter, new Occurrences\Strict(5));
64
65
        $str = $pw->generate();
66
67
        $this->assertNotEmpty($str);
68
69
        $this->assertRegExp('/[' . implode($accentedLetter->handle()) . ']{5}/', $str);
70
    }
71
72
    /** @test */
73 View Code Duplication
    public function accentedUppercaseLetterOnly()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $pw = new Password();
76
77
        $accentedUppercaseLetter = new Dictionaries\AccentedUppercaseLetter();
78
79
        $pw->addCriteria($accentedUppercaseLetter, new Occurrences\Strict(5));
80
81
        $str = $pw->generate();
82
83
        $this->assertNotEmpty($str);
84
85
        $this->assertRegExp('/[' . implode($accentedUppercaseLetter->handle()) . ']{5}/', $str);
86
    }
87
88
    /** @test */
89
    public function specialCharacterOnly()
90
    {
91
        $pw = new Password();
92
93
        $specialCharacter = new Dictionaries\SpecialCharacter();
94
95
        $pw->addCriteria($specialCharacter, new Occurrences\Strict(5));
96
97
        $str = $pw->generate();
98
99
        $this->assertNotEmpty($str);
100
101
        $chars = array_map(function ($c) {
102
            return '\\' . $c;
103
        }, $specialCharacter->handle());
104
105
        $this->assertRegExp('/[' . implode($chars) . ']{5}/', $str);
106
    }
107
108
    /** @test */
109
    public function longDigitFormatOnly()
110
    {
111
        $pw = new Password();
112
113
        $pw->addFormat(new Formats\LongDigit());
114
115
        $str = $pw->generate();
116
117
        $this->assertNotEmpty($str);
118
119
        $this->assertRegExp('/\d{30}/', $str);
120
    }
121
122
    /** @test */
123 View Code Duplication
    public function smallAlphanumericFormatOnly()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
    {
125
        $pw = new Password();
126
127
        $pw->addFormat(new Formats\SmallAlphanumeric());
128
129
        $str = $pw->generate();
130
131
        $this->assertNotEmpty($str);
132
133
        $this->assertEquals(15, mb_strlen($str));
134
135
        $this->assertRegExp('/[a-zA-Z0-9]/', $str);
136
    }
137
138
    /** @test */
139 View Code Duplication
    public function strongAlphanumericFormatOnly()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        $pw = new Password();
142
143
        $pw->addFormat(new Formats\StrongAlphanumeric());
144
145
        $str = $pw->generate();
146
147
        $this->assertNotEmpty($str);
148
149
        $this->assertEquals(30, mb_strlen($str));
150
151
        $this->assertRegExp('/[a-zA-Z0-9]/', $str);
152
    }
153
154
    /** @test */
155
    public function mixedStrongFormatOnly()
156
    {
157
        $pw = new Password();
158
159
        $pw->addFormat(new Formats\MixedStrong());
160
161
        $str = $pw->generate();
162
163
        $this->assertNotEmpty($str);
164
165
        // $this->assertEquals(30, mb_strlen($str));
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
167
        // $this->assertRegExp('/[a-zA-Z0-9]/', $str);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
168
    }
169
170
    /** @test */
171
    public function mixedComplexFormatOnly()
172
    {
173
        $pw = new Password();
174
175
        $pw->addFormat(new Formats\MixedComplex());
176
177
        $str = $pw->generate();
178
179
        $this->assertNotEmpty($str);
180
181
        // $this->assertEquals(30, mb_strlen($str));
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
182
183
        // $this->assertRegExp('/[a-zA-Z0-9]/', $str);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
184
    }
185
186
187
    /** @test */
188 View Code Duplication
    public function digitPasswordOnly()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
189
    {
190
        $pw = new Password();
191
192
        $pw->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(10));
193
194
        $str = $pw->generate();
195
196
        $this->assertNotEmpty($str);
197
198
        $this->assertRegExp('/\d{10}/', $str);
199
    }
200
201
    /** @test */
202
    public function strictOccurrences()
203
    {
204
        $dictionary = new Dictionaries\Letter();
205
206
        $occurrence = new Occurrences\Strict(5);
207
208
        $criteria = new Criteria(null, $dictionary, $occurrence);
209
210
        $result = $criteria->build();
211
212
        $this->assertTrue(is_array($result));
213
        $this->assertEquals(5, count($result));
214
        $this->assertContains($result[0], $dictionary->handle());
215
        $this->assertContains($result[1], $dictionary->handle());
216
        $this->assertContains($result[2], $dictionary->handle());
217
        $this->assertContains($result[3], $dictionary->handle());
218
    }
219
220
    /** @test */
221
    public function betweenOccurrences()
222
    {
223
        $dictionary = new Dictionaries\Letter();
224
225
        $occurrence = new Occurrences\Between(3, 5);
226
227
        $criteria = new Criteria(null, $dictionary, $occurrence);
228
229
        $result = $criteria->build();
230
231
        $this->assertTrue(is_array($result));
232
        $this->assertTrue(count($result) >= 3 && count($result) <= 5);
233
        $this->assertContains($result[0], $dictionary->handle());
234
        $this->assertContains($result[1], $dictionary->handle());
235
        $this->assertContains($result[2], $dictionary->handle());
236
    }
237
238
    /** @test */
239 View Code Duplication
    public function simpleStrictPerfectScore()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
240
    {
241
        $string = '1a2b3c';
242
243
        $password = new Password();
244
245
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
246
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3));
247
248
        $this->assertEquals($password->score($string), 100);
249
    }
250
251
    /** @test */
252 View Code Duplication
    public function simpleBetweenPerfectScore()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
253
    {
254
        $string = '1a2b3c4';
255
256
        $password = new Password();
257
258
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Between(3, 5));
259
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5));
260
261
        $this->assertEquals($password->score($string), 100);
262
    }
263
264
    /** @test */
265 View Code Duplication
    public function simpleMixedPerfectScore()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
266
    {
267
        $string = '1a2b3cde';
268
269
        $password = new Password();
270
271
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
272
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5));
273
274
        $this->assertEquals($password->score($string), 100);
275
    }
276
277
    /** @test */
278 View Code Duplication
    public function simpleMixedIncompleteScore()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
279
    {
280
        $string = '1a2bc';
281
282
        $password = new Password();
283
284
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
285
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5));
286
287
        $this->assertEquals($password->score($string), 50);
288
    }
289
290
    /** @test */
291 View Code Duplication
    public function complexStrictPerfectScore()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
292
    {
293
        $string = '123abcABC[&+àáâÀÁÂ';
294
295
        $password = new Password();
296
297
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
298
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3));
299
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3));
300
        $password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Strict(3));
301
        $password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3));
302
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(3));
303
304
        $this->assertEquals($password->score($string), 100);
305
    }
306
307
    /** @test */
308 View Code Duplication
    public function complexStrictIncompleteScore()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
309
    {
310
        $string = '12abcAB[&+àáâÀÁÂ';
311
312
        $password = new Password();
313
314
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
315
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3));
316
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3));
317
        $password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Strict(3));
318
        $password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3));
319
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(3));
320
321
        $this->assertEquals($password->score($string), 67);
322
    }
323
324
    /** @test */
325 View Code Duplication
    public function complexMixedPerfectScore()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
326
    {
327
        $string = '123abcdEFG[&+éèàÒÓÔ';
328
329
        $password = new Password();
330
331
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
332
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5));
333
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3));
334
        $password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Between(3, 5));
335
        $password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3));
336
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Between(3, 5));
337
338
        $this->assertEquals($password->score($string), 100);
339
    }
340
341
    /** @test */
342
    public function checkLettersParticularities()
343
    {
344
        $string = 'eaEAéèàÉÈÀ';
345
346
        $password = new Password();
347
348
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2));
349
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2));
350
        $password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3));
351
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(3));
352
353
        $this->assertEquals($password->score($string), 100);
354
355
        $string = 'ea';
356
357
        $password = new Password();
358
359
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2));
360
        $password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(2));
361
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(2));
362
363
        $this->assertEquals($password->score($string), 0);
364
365
        $string = 'EA';
366
367
        $password = new Password();
368
369
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2));
370
        $password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(2));
371
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(2));
372
373
        $this->assertEquals($password->score($string), 0);
374
375
        $string = 'éèà';
376
377
        $password = new Password();
378
379
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2));
380
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2));
381
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(2));
382
383
        $this->assertEquals($password->score($string), 0);
384
385
        $string = 'ÉÈÀ';
386
387
        $password = new Password();
388
389
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2));
390
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2));
391
        $password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(2));
392
393
        $this->assertEquals($password->score($string), 0);
394
    }
395
396
    /** @test */
397
    public function generatePasswordWithNoneOccurrence()
398
    {
399
        $password = new Password();
400
401
        $digit = new Dictionaries\Digit();
402
        $letter = new Dictionaries\Letter();
403
404
        $password->addCriteria($digit, new Occurrences\Strict(3));
405
        $password->addCriteria($letter, new Occurrences\None());
406
407
        $str = $password->generate();
408
409
        $this->assertNotEmpty($str);
410
411
        $this->assertEquals(3, mb_strlen($str));
412
413
        $this->assertRegExp('/[' . implode($digit->handle()) . ']{3}/', $str);
414
        $this->assertRegExp('/[' . implode($letter->handle()) . ']{0}/', $str);
415
    }
416
417
    /** @test */
418 View Code Duplication
    public function passwordWithoutLetterOk()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
419
    {
420
        $string = '0123';
421
422
        $password = new Password();
423
424
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\None());
425
426
        $this->assertEquals($password->score($string), 100);
427
    }
428
429
    /** @test */
430 View Code Duplication
    public function passwordWithoutLetterFail()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
431
    {
432
        $string = '0123a';
433
434
        $password = new Password();
435
436
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\None());
437
438
        $this->assertEquals($password->score($string), 0);
439
    }
440
441
    /** @test */
442
    public function criteriaWithName()
443
    {
444
        $dictionary = new Dictionaries\Letter();
445
446
        $occurrence = new Occurrences\Strict(5);
447
448
        $criteria = new Criteria('name', $dictionary, $occurrence);
449
450
        $this->assertEquals($criteria->getName(), 'name');
451
    }
452
453
    /** @test */
454
    public function criteriaWithDefaultName()
455
    {
456
        $dictionary = new Dictionaries\Letter();
457
458
        $occurrence = new Occurrences\Strict(5);
459
460
        $criteria = new Criteria(null, $dictionary, $occurrence);
461
462
        $this->assertEquals($criteria->getName(), 'letter_strict_5');
463
464
        $dictionary = new Dictionaries\Digit();
465
466
        $occurrence = new Occurrences\Between(1, 5);
467
468
        $criteria = new Criteria(null, $dictionary, $occurrence);
469
470
        $this->assertEquals($criteria->getName(), 'digit_between_1_5');
471
472
        $dictionary = new Dictionaries\UppercaseLetter();
473
474
        $occurrence = new Occurrences\None();
475
476
        $criteria = new Criteria(null, $dictionary, $occurrence);
477
478
        $this->assertEquals($criteria->getName(), 'uppercaseletter_none');
479
    }
480
481
    /** @test */
482 View Code Duplication
    public function simpleStrictPerfectPassed()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
483
    {
484
        $string = '1a2b3c';
485
486
        $password = new Password();
487
488
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
489
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3));
490
491
        $expectedArray = [
492
            [
493
                'name' => 'digit_strict_3',
494
                'passed' => true,
495
            ],
496
            [
497
                'name' => 'letter_strict_3',
498
                'passed' => true,
499
            ],
500
        ];
501
502
        $this->assertEquals($password->passed($string), $expectedArray);
503
    }
504
505
    /** @test */
506 View Code Duplication
    public function simpleBetweenPerfectPassed()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
507
    {
508
        $string = '1a2b3c4';
509
510
        $password = new Password();
511
512
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Between(3, 5));
513
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5));
514
515
        $expectedArray = [
516
            [
517
                'name' => 'digit_between_3_5',
518
                'passed' => true,
519
            ],
520
            [
521
                'name' => 'letter_between_3_5',
522
                'passed' => true,
523
            ],
524
        ];
525
526
        $this->assertEquals($password->passed($string), $expectedArray);
527
    }
528
529
    /** @test */
530
    public function mixedIncompletePassed()
531
    {
532
        $string = '1a2bcABC[&+Ó';
533
534
        $password = new Password();
535
536
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
537
        $password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3));
538
        $password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5));
539
        $password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Between(1, 2));
540
        $password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(1));
541
542
        $expectedArray = [
543
            [
544
                'name' => 'digit_strict_3',
545
                'passed' => false,
546
            ],
547
            [
548
                'name' => 'uppercaseletter_strict_3',
549
                'passed' => true,
550
            ],
551
            [
552
                'name' => 'letter_between_3_5',
553
                'passed' => true,
554
            ],
555
            [
556
                'name' => 'specialcharacter_between_1_2',
557
                'passed' => false,
558
            ],
559
            [
560
                'name' => 'accenteduppercaseletter_strict_1',
561
                'passed' => true,
562
            ],
563
        ];
564
565
        $this->assertEquals($password->passed($string), $expectedArray);
566
    }
567
568
    /** @test */
569 View Code Duplication
    public function mixedPerfecPassedWithName()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
570
    {
571
        $string = '1a2b3c';
572
573
        $password = new Password();
574
575
        $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3));
576
        $password->addNamedCriteria('name', new Dictionaries\Letter(), new Occurrences\Between(3, 5));
577
578
        $expectedArray = [
579
            [
580
                'name' => 'digit_strict_3',
581
                'passed' => true,
582
            ],
583
            [
584
                'name' => 'name',
585
                'passed' => true,
586
            ],
587
        ];
588
589
        $this->assertEquals($password->passed($string), $expectedArray);
590
    }
591
}
592