UniqueIdentifierGeneratorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeneratesUniqueIdentifiers() 0 7 1
A testGeneratesValidIdentifiers() 0 7 1
A testGeneratedIdentifierEntropy() 0 4 1
A getBaseIdentifierNames() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\Generator\Util;
6
7
use PHPUnit\Framework\TestCase;
8
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
9
use function strlen;
10
11
/**
12
 * Tests for {@see \ProxyManager\Generator\Util\UniqueIdentifierGenerator}
13
 *
14
 * @group Coverage
15
 * @covers \ProxyManager\Generator\Util\UniqueIdentifierGenerator
16
 */
17
final class UniqueIdentifierGeneratorTest extends TestCase
18
{
19
    /**
20
     * @dataProvider getBaseIdentifierNames
21
     */
22
    public function testGeneratesUniqueIdentifiers(string $name) : void
23
    {
24
        self::assertNotSame(
0 ignored issues
show
Bug introduced by
The method assertNotSame() does not seem to exist on object<ProxyManagerTest\...dentifierGeneratorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
            UniqueIdentifierGenerator::getIdentifier($name),
26
            UniqueIdentifierGenerator::getIdentifier($name)
27
        );
28
    }
29
30
    /**
31
     * @dataProvider getBaseIdentifierNames
32
     */
33
    public function testGeneratesValidIdentifiers(string $name) : void
34
    {
35
        self::assertRegExp(
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<ProxyManagerTest\...dentifierGeneratorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
            '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/',
37
            UniqueIdentifierGenerator::getIdentifier($name)
38
        );
39
    }
40
41
    /**
42
     * @dataProvider getBaseIdentifierNames
43
     */
44
    public function testGeneratedIdentifierEntropy(string $name) : void
45
    {
46
        self::assertGreaterThan(14, strlen(UniqueIdentifierGenerator::getIdentifier($name)));
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<ProxyManagerTest\...dentifierGeneratorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
    }
48
49
    /**
50
     * Data provider generating identifier names to be checked
51
     *
52
     * @return string[][]
53
     */
54
    public static function getBaseIdentifierNames() : array
55
    {
56
        return [
57
            [''],
58
            ['1'],
59
            ['foo'],
60
            ['Foo'],
61
            ['bar'],
62
            ['Bar'],
63
            ['foo_bar'],
64
        ];
65
    }
66
}
67