1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
use DeGraciaMathieu\Riddler\Password;
|
4
|
|
|
use DeGraciaMathieu\Riddler\Criterias;
|
5
|
|
|
use DeGraciaMathieu\Riddler\Formats;
|
6
|
|
|
use DeGraciaMathieu\Riddler\Occurences;
|
7
|
|
|
|
8
|
|
|
class Test extends \PHPUnit\Framework\TestCase
|
|
|
|
|
9
|
|
|
{
|
10
|
|
|
/** @test */
|
11
|
1 |
|
public function emptyPassword()
|
12
|
|
|
{
|
13
|
1 |
|
$pw = new Password();
|
14
|
|
|
|
15
|
1 |
|
$str = $pw->generate();
|
16
|
|
|
|
17
|
1 |
|
$this->assertEmpty($str);
|
18
|
1 |
|
}
|
19
|
|
|
|
20
|
|
|
/** @test */
|
21
|
1 |
|
public function letterPasswordOnly()
|
22
|
|
|
{
|
23
|
1 |
|
$pw = new Password();
|
24
|
|
|
|
25
|
1 |
|
$pw->addCriteria(new Criterias\Letter(), new Occurences\Strict(10));
|
26
|
|
|
|
27
|
1 |
|
$str = $pw->generate();
|
28
|
|
|
|
29
|
1 |
|
$this->assertNotEmpty($str);
|
30
|
|
|
|
31
|
1 |
|
$this->assertRegExp('/[a-z]/', $str);
|
32
|
1 |
|
}
|
33
|
|
|
|
34
|
|
|
/** @test */
|
35
|
1 |
|
public function alphanumericPasswordOnly()
|
36
|
|
|
{
|
37
|
1 |
|
$pw = new Password();
|
38
|
|
|
|
39
|
1 |
|
$pw->addCriteria(new Criterias\Letter(), new Occurences\Strict(5));
|
40
|
1 |
|
$pw->addCriteria(new Criterias\UppercaseLetter(), new Occurences\Strict(5));
|
41
|
1 |
|
$pw->addCriteria(new Criterias\Digit(), new Occurences\Strict(5));
|
42
|
|
|
|
43
|
1 |
|
$str = $pw->generate();
|
44
|
|
|
|
45
|
1 |
|
$this->assertNotEmpty($str);
|
46
|
|
|
|
47
|
1 |
|
$this->assertEquals(15, strlen($str));
|
48
|
|
|
|
49
|
1 |
|
$this->assertRegExp('/[a-zA-Z0-9]/', $str);
|
50
|
1 |
|
}
|
51
|
|
|
|
52
|
|
|
/** @test */
|
53
|
1 |
|
public function longDigitFormatOnly()
|
54
|
|
|
{
|
55
|
1 |
|
$pw = new Password();
|
56
|
|
|
|
57
|
1 |
|
$pw->addFormat(new Formats\LongDigit());
|
58
|
|
|
|
59
|
1 |
|
$str = $pw->generate();
|
60
|
|
|
|
61
|
1 |
|
$this->assertNotEmpty($str);
|
62
|
|
|
|
63
|
1 |
|
$this->assertRegExp('/\d{30}/', $str);
|
64
|
1 |
|
}
|
65
|
|
|
|
66
|
|
|
/** @test */
|
67
|
1 |
|
public function digitPasswordOnly()
|
68
|
|
|
{
|
69
|
1 |
|
$pw = new Password();
|
70
|
|
|
|
71
|
1 |
|
$pw->addCriteria(new Criterias\Digit(), new Occurences\Strict(10));
|
72
|
|
|
|
73
|
1 |
|
$str = $pw->generate();
|
74
|
|
|
|
75
|
1 |
|
$this->assertNotEmpty($str);
|
76
|
|
|
|
77
|
1 |
|
$this->assertRegExp('/\d{10}/', $str);
|
78
|
1 |
|
}
|
79
|
|
|
|
80
|
|
|
/** @test */
|
81
|
1 |
View Code Duplication |
public function strictOccurences()
|
|
|
|
|
82
|
|
|
{
|
83
|
1 |
|
$dictionary = ['a', 'b', 'c', 'd'];
|
84
|
|
|
|
85
|
1 |
|
$strict = new Occurences\Strict(5);
|
86
|
1 |
|
$result = $strict->parse($dictionary);
|
87
|
|
|
|
88
|
1 |
|
$this->assertTrue(is_array($result));
|
89
|
1 |
|
$this->assertEquals(5, count($result));
|
90
|
1 |
|
$this->assertContains($result[0], $dictionary);
|
91
|
1 |
|
$this->assertContains($result[1], $dictionary);
|
92
|
1 |
|
$this->assertContains($result[2], $dictionary);
|
93
|
1 |
|
$this->assertContains($result[3], $dictionary);
|
94
|
1 |
|
}
|
95
|
|
|
|
96
|
|
|
/** @test */
|
97
|
1 |
View Code Duplication |
public function betweenOccurences()
|
|
|
|
|
98
|
|
|
{
|
99
|
1 |
|
$dictionary = ['a', 'b', 'c', 'd'];
|
100
|
|
|
|
101
|
1 |
|
$strict = new Occurences\Between(3, 5);
|
102
|
1 |
|
$result = $strict->parse($dictionary);
|
103
|
|
|
|
104
|
1 |
|
$this->assertTrue(is_array($result));
|
105
|
1 |
|
$this->assertTrue(count($result) >= 3);
|
106
|
1 |
|
$this->assertTrue(count($result) <= 5);
|
107
|
1 |
|
$this->assertContains($result[0], $dictionary);
|
108
|
1 |
|
$this->assertContains($result[1], $dictionary);
|
109
|
1 |
|
$this->assertContains($result[2], $dictionary);
|
110
|
1 |
|
}
|
111
|
|
|
}
|
112
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.