Completed
Pull Request — master (#348)
by Marco
04:48
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 testGeneratesValidIdentifiers(string $name) : void
56
    {
57
        self::assertRegExp(
58
            '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/',
59
            UniqueIdentifierGenerator::getIdentifier($name)
60
        );
61
    }
62
63
    /**
64
     * @dataProvider getBaseIdentifierNames
65
     *
66
     * @param string $name
67
     */
68
    public function testGeneratedIdentifierEntropy(string $name) : void
69
    {
70
        self::assertGreaterThan(14, strlen(UniqueIdentifierGenerator::getIdentifier($name)));
71
    }
72
73
    /**
74
     * Data provider generating identifier names to be checked
75
     *
76
     * @return string[][]
77
     */
78
    public function getBaseIdentifierNames() : array
79
    {
80
        return [
81
            [''],
82
            ['1'],
83
            ['foo'],
84
            ['Foo'],
85
            ['bar'],
86
            ['Bar'],
87
            ['foo_bar'],
88
        ];
89
    }
90
}
91