Completed
Pull Request — master (#384)
by
unknown
11:33
created

testGeneratesValidIdentifiers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
declare(strict_types=1);
20
21
namespace ProxyManagerTest\Generator\Util;
22
23
use PHPUnit_Framework_TestCase;
24
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
25
26
/**
27
 * Tests for {@see \ProxyManager\Generator\Util\UniqueIdentifierGenerator}
28
 *
29
 * @author Marco Pivetta <[email protected]>
30
 * @license MIT
31
 *
32
 * @group Coverage
33
 * @covers \ProxyManager\Generator\Util\UniqueIdentifierGenerator
34
 */
35
class UniqueIdentifierGeneratorTest extends PHPUnit_Framework_TestCase
36
{
37
    /**
38
     * @dataProvider getBaseIdentifierNames
39
     *
40
     * @param string $name
41
     */
42
    public function testGeneratesUniqueIdentifiers(string $name) : void
43
    {
44
        self::assertNotSame(
45
            UniqueIdentifierGenerator::getIdentifier($name),
46
            UniqueIdentifierGenerator::getIdentifier($name)
47
        );
48
    }
49
50
    /**
51
     * @dataProvider getBaseIdentifierNames
52
     *
53
     * @param string $name
54
     */
55
    public function testGeneratesUniqueIdentifiersByName(string $name) : void
56
    {
57
        self::assertSame(
58
            UniqueIdentifierGenerator::getIdentifier($name, true),
59
            UniqueIdentifierGenerator::getIdentifier($name, true)
60
        );
61
    }
62
63
    /**
64
     * @dataProvider getBaseIdentifierNames
65
     *
66
     * @param string $name
67
     */
68
    public function testGeneratesValidIdentifiers(string $name) : void
69
    {
70
        self::assertRegExp(
71
            '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/',
72
            UniqueIdentifierGenerator::getIdentifier($name)
73
        );
74
    }
75
76
    /**
77
     * @dataProvider getBaseIdentifierNames
78
     *
79
     * @param string $name
80
     */
81
    public function testGeneratedIdentifierEntropy(string $name) : void
82
    {
83
        self::assertGreaterThan(14, strlen(UniqueIdentifierGenerator::getIdentifier($name)));
84
    }
85
86
    /**
87
     * Data provider generating identifier names to be checked
88
     *
89
     * @return string[][]
90
     */
91
    public function getBaseIdentifierNames() : array
92
    {
93
        return [
94
            [''],
95
            ['1'],
96
            ['foo'],
97
            ['Foo'],
98
            ['bar'],
99
            ['Bar'],
100
            ['foo_bar'],
101
        ];
102
    }
103
}
104