|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\Generator\Util; |
|
6
|
|
|
|
|
7
|
|
|
use PackageVersions\Versions; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use ProxyManager\Generator\Util\IdentifierSuffixer; |
|
10
|
|
|
use function serialize; |
|
11
|
|
|
use function sha1; |
|
12
|
|
|
use function strlen; |
|
13
|
|
|
use function substr; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Tests for {@see \ProxyManager\Generator\Util\IdentifierSuffixer} |
|
17
|
|
|
* |
|
18
|
|
|
* @group Coverage |
|
19
|
|
|
* @covers \ProxyManager\Generator\Util\IdentifierSuffixer |
|
20
|
|
|
*/ |
|
21
|
|
|
final class IdentifierSuffixerTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @dataProvider getBaseIdentifierNames |
|
25
|
|
|
*/ |
|
26
|
|
|
public function testGeneratesSuffixedIdentifiers(string $name) : void |
|
27
|
|
|
{ |
|
28
|
|
|
self::assertSame( |
|
|
|
|
|
|
29
|
|
|
IdentifierSuffixer::getIdentifier($name), |
|
30
|
|
|
IdentifierSuffixer::getIdentifier($name) |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @dataProvider getBaseIdentifierNames |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testGeneratedSuffixDependsOnPackageInstalledVersions(string $name) : void |
|
38
|
|
|
{ |
|
39
|
|
|
self::assertStringEndsWith( |
|
|
|
|
|
|
40
|
|
|
substr(sha1($name . sha1(serialize(Versions::VERSIONS))), 0, 5), |
|
41
|
|
|
IdentifierSuffixer::getIdentifier($name) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @dataProvider getBaseIdentifierNames |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testGeneratesValidIdentifiers(string $name) : void |
|
49
|
|
|
{ |
|
50
|
|
|
self::assertRegExp( |
|
|
|
|
|
|
51
|
|
|
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/', |
|
52
|
|
|
IdentifierSuffixer::getIdentifier($name) |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @dataProvider getBaseIdentifierNames |
|
58
|
|
|
*/ |
|
59
|
|
|
public static function testGeneratedIdentifierSuffix(string $name) : void |
|
60
|
|
|
{ |
|
61
|
|
|
// 5 generated characters are enough to keep idiots from tampering with these properties "the easy way" |
|
62
|
|
|
self::assertGreaterThan(5, strlen(IdentifierSuffixer::getIdentifier($name))); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Data provider generating identifier names to be checked |
|
67
|
|
|
* |
|
68
|
|
|
* @return string[][] |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function getBaseIdentifierNames() : array |
|
71
|
|
|
{ |
|
72
|
|
|
return [ |
|
73
|
|
|
[''], |
|
74
|
|
|
['1'], |
|
75
|
|
|
['foo'], |
|
76
|
|
|
['Foo'], |
|
77
|
|
|
['bar'], |
|
78
|
|
|
['Bar'], |
|
79
|
|
|
['foo_bar'], |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
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.