Passed
Push — master ( c9722a...484084 )
by DeGracia
02:05
created

Test::longDigitFormatOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
ccs 7
cts 7
cp 1
cc 1
eloc 6
nc 1
nop 0
crap 1
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 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()
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...
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()
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...
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