Passed
Branch master (854f93)
by DeGracia
03:28 queued 01:16
created

Test::smallAlphanumericFormatOnly()   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
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /** @test */
11
    public function emptyPassword()
12
    {
13
        $pw = new Password();
14
15
        $str = $pw->generate();
16
17
        $this->assertEmpty($str);
18
    }
19
20
    /** @test */
21
    public function letterPasswordOnly()
22
    {
23
        $pw = new Password();
24
25
        $pw->addCriteria(new Criterias\Letter(), new Occurences\Strict(10));
26
27
        $str = $pw->generate();
28
29
        $this->assertNotEmpty($str);
30
31
        $this->assertRegExp('/[a-z]/', $str);
32
    }
33
34
    /** @test */
35
    public function alphanumericPasswordOnly()
36
    {
37
        $pw = new Password();
38
39
        $pw->addCriteria(new Criterias\Letter(), new Occurences\Strict(5));
40
        $pw->addCriteria(new Criterias\UppercaseLetter(), new Occurences\Strict(5));
41
        $pw->addCriteria(new Criterias\Digit(), new Occurences\Strict(5));
42
43
        $str = $pw->generate();
44
45
        $this->assertNotEmpty($str);
46
47
        $this->assertEquals(15, mb_strlen($str));
48
49
        $this->assertRegExp('/[a-zA-Z0-9]/', $str);
50
    }
51
52
    /** @test */
53 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...
54
    {
55
        $pw = new Password();
56
57
        $accentedLetter = new Criterias\AccentedLetter();
58
59
        $pw->addCriteria($accentedLetter, new Occurences\Strict(5));
60
61
        $str = $pw->generate();
62
63
        $this->assertNotEmpty($str);
64
65
        $this->assertEquals(5, mb_strlen($str));
66
67
        $this->assertRegExp('/[' . implode($accentedLetter->handle()) . ']{5}/', $str);        
68
    }
69
70
    /** @test */
71 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...
72
    {
73
        $pw = new Password();
74
75
        $accentedUppercaseLetter = new Criterias\AccentedUppercaseLetter();
76
77
        $pw->addCriteria($accentedUppercaseLetter, new Occurences\Strict(5));
78
79
        $str = $pw->generate();
80
81
        $this->assertNotEmpty($str);
82
83
        $this->assertEquals(5, mb_strlen($str));
84
85
        $this->assertRegExp('/[' . implode($accentedUppercaseLetter->handle()) . ']{5}/', $str);        
86
    }    
87
88
    /** @test */
89 View Code Duplication
    public function specialCharacterOnly()
0 ignored issues
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...
90
    {
91
        $pw = new Password();
92
93
        $pw->addCriteria(new Criterias\SpecialCharacter(), new Occurences\Strict(5));
94
95
        $str = $pw->generate();
96
97
        $this->assertNotEmpty($str);
98
99
        $this->assertEquals(5, mb_strlen($str));
100
101
        $this->assertRegExp('/[\[\&\+\#\|\^\°\=\!\@\%\*\?\_\~\-\§\:\;\.\]]{5}/', $str);        
102
    }   
103
104
    /** @test */
105
    public function longDigitFormatOnly()
106
    {
107
        $pw = new Password();
108
109
        $pw->addFormat(new Formats\LongDigit());
110
111
        $str = $pw->generate();
112
113
        $this->assertNotEmpty($str);
114
115
        $this->assertRegExp('/\d{30}/', $str);
116
    }
117
118
    /** @test */
119 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...
120
    {
121
        $pw = new Password();
122
123
        $pw->addFormat(new Formats\SmallAlphanumeric());
124
125
        $str = $pw->generate();
126
127
        $this->assertNotEmpty($str);
128
129
        $this->assertEquals(15, mb_strlen($str));
130
131
        $this->assertRegExp('/[a-zA-Z0-9]/', $str);
132
    }
133
134
    /** @test */
135 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...
136
    {
137
        $pw = new Password();
138
139
        $pw->addFormat(new Formats\StrongAlphanumeric());
140
141
        $str = $pw->generate();
142
143
        $this->assertNotEmpty($str);
144
145
        $this->assertEquals(30, mb_strlen($str));
146
147
        $this->assertRegExp('/[a-zA-Z0-9]/', $str);
148
    }
149
150
    /** @test */
151
    public function mixedStrongFormatOnly()
152
    {
153
        $pw = new Password();
154
155
        $pw->addFormat(new Formats\MixedStrong());
156
157
        $str = $pw->generate();
158
159
        $this->assertNotEmpty($str);
160
161
        // $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...
162
163
        // $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...
164
    }
165
166
    /** @test */
167
    public function mixedComplexFormatOnly()
168
    {
169
        $pw = new Password();
170
171
        $pw->addFormat(new Formats\MixedComplex());
172
173
        $str = $pw->generate();
174
175
        $this->assertNotEmpty($str);
176
177
        // $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...
178
179
        // $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...
180
    }
181
182
183
    /** @test */
184
    public function digitPasswordOnly()
185
    {
186
        $pw = new Password();
187
188
        $pw->addCriteria(new Criterias\Digit(), new Occurences\Strict(10));
189
190
        $str = $pw->generate();
191
192
        $this->assertNotEmpty($str);
193
194
        $this->assertRegExp('/\d{10}/', $str);
195
    }    
196
197
    /** @test */
198 View Code Duplication
    public function strictOccurences()
0 ignored issues
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...
199
    {
200
        $dictionary = ['a', 'b', 'c', 'd'];
201
202
        $strict = new Occurences\Strict(5);
203
        $result = $strict->parse($dictionary);
204
205
        $this->assertTrue(is_array($result));
206
        $this->assertEquals(5, count($result));
207
        $this->assertContains($result[0], $dictionary);
208
        $this->assertContains($result[1], $dictionary);
209
        $this->assertContains($result[2], $dictionary);
210
        $this->assertContains($result[3], $dictionary);
211
    }
212
213
    /** @test */
214 View Code Duplication
    public function betweenOccurences()
0 ignored issues
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...
215
    {
216
        $dictionary = ['a', 'b', 'c', 'd'];
217
218
        $strict = new Occurences\Between(3, 5);
219
        $result = $strict->parse($dictionary);
220
221
        $this->assertTrue(is_array($result));
222
        $this->assertTrue(count($result) >= 3);
223
        $this->assertTrue(count($result) <= 5);
224
        $this->assertContains($result[0], $dictionary);
225
        $this->assertContains($result[1], $dictionary);
226
        $this->assertContains($result[2], $dictionary);
227
    }
228
}
229