testGeneratesSameClassNameWithSameParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\Inflector;
6
7
use PHPUnit\Framework\TestCase;
8
use ProxyManager\Inflector\ClassNameInflector;
9
use ProxyManager\Inflector\ClassNameInflectorInterface;
10
11
/**
12
 * Tests for {@see \ProxyManager\Inflector\ClassNameInflector}
13
 *
14
 * @group Coverage
15
 * @covers \ProxyManager\Inflector\ClassNameInflector
16
 */
17
final class ClassNameInflectorTest extends TestCase
18
{
19
    /**
20
     * @param class-string $realClassName
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
21
     * @param class-string $proxyClassName
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
22
     *
23
     * @dataProvider getClassNames
24
     */
25
    public function testInflector(string $realClassName, string $proxyClassName) : void
26
    {
27
        $inflector = new ClassNameInflector('ProxyNS');
28
29
        self::assertFalse($inflector->isProxyClassName($realClassName));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
30
        self::assertTrue($inflector->isProxyClassName($proxyClassName));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
31
        self::assertStringMatchesFormat($realClassName, $inflector->getUserClassName($realClassName));
0 ignored issues
show
Bug introduced by
The method assertStringMatchesFormat() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
32
        self::assertStringMatchesFormat($proxyClassName, $inflector->getProxyClassName($proxyClassName));
0 ignored issues
show
Bug introduced by
The method assertStringMatchesFormat() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
33
        self::assertStringMatchesFormat($proxyClassName, $inflector->getProxyClassName($realClassName));
0 ignored issues
show
Bug introduced by
The method assertStringMatchesFormat() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
34
        self::assertStringMatchesFormat($realClassName, $inflector->getUserClassName($proxyClassName));
0 ignored issues
show
Bug introduced by
The method assertStringMatchesFormat() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
35
    }
36
37
    public function testGeneratesSameClassNameWithSameParameters() : void
38
    {
39
        /** @var class-string $fooBar */
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
40
        $fooBar    = 'Foo\\Bar';
41
        $inflector = new ClassNameInflector('ProxyNS');
42
43
        self::assertSame($inflector->getProxyClassName($fooBar), $inflector->getProxyClassName($fooBar));
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
44
        self::assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
45
            $inflector->getProxyClassName($fooBar, ['baz' => 'tab']),
46
            $inflector->getProxyClassName($fooBar, ['baz' => 'tab'])
47
        );
48
        self::assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
49
            $inflector->getProxyClassName($fooBar, ['tab' => 'baz']),
50
            $inflector->getProxyClassName($fooBar, ['tab' => 'baz'])
51
        );
52
    }
53
54
    public function testGeneratesDifferentClassNameWithDifferentParameters() : void
55
    {
56
        /** @var class-string $fooBar */
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
57
        $fooBar    = 'Foo\\Bar';
58
        $inflector = new ClassNameInflector('ProxyNS');
59
60
        self::assertNotSame(
0 ignored issues
show
Bug introduced by
The method assertNotSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
61
            $inflector->getProxyClassName($fooBar),
62
            $inflector->getProxyClassName($fooBar, ['foo' => 'bar'])
63
        );
64
        self::assertNotSame(
0 ignored issues
show
Bug introduced by
The method assertNotSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
65
            $inflector->getProxyClassName($fooBar, ['baz' => 'tab']),
66
            $inflector->getProxyClassName($fooBar, ['tab' => 'baz'])
67
        );
68
        self::assertNotSame(
0 ignored issues
show
Bug introduced by
The method assertNotSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
69
            $inflector->getProxyClassName($fooBar, ['foo' => 'bar', 'tab' => 'baz']),
70
            $inflector->getProxyClassName($fooBar, ['foo' => 'bar'])
71
        );
72
        self::assertNotSame(
0 ignored issues
show
Bug introduced by
The method assertNotSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
73
            $inflector->getProxyClassName($fooBar, ['foo' => 'bar', 'tab' => 'baz']),
74
            $inflector->getProxyClassName($fooBar, ['tab' => 'baz', 'foo' => 'bar'])
75
        );
76
    }
77
78
    public function testGeneratesCorrectClassNameWhenGivenLeadingBackslash() : void
79
    {
80
        /** @var class-string $fooBar */
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
81
        $fooBar = 'Foo\\Bar';
82
        /** @var class-string $fooBarPrefixed */
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
83
        $fooBarPrefixed = '\\Foo\\Bar';
84
        $inflector      = new ClassNameInflector('ProxyNS');
85
86
        self::assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
87
            $inflector->getProxyClassName($fooBarPrefixed, ['tab' => 'baz']),
88
            $inflector->getProxyClassName($fooBar, ['tab' => 'baz'])
89
        );
90
    }
91
92
    /**
93
     * @param class-string         $className
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
94
     * @param array<string, mixed> $parameters
95
     *
96
     * @dataProvider getClassAndParametersCombinations
97
     */
98
    public function testClassNameIsValidClassIdentifier(string $className, array $parameters) : void
99
    {
100
        $inflector = new ClassNameInflector('ProxyNS');
101
102
        self::assertRegExp(
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<ProxyManagerTest\...ClassNameInflectorTest>.

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...
103
            '/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)*/',
104
            $inflector->getProxyClassName($className, $parameters),
105
            'Class name string is a valid class identifier'
106
        );
107
    }
108
109
    /**
110
     * Data provider.
111
     *
112
     * @return string[][]
113
     */
114
    public static function getClassNames() : array
115
    {
116
        return [
117
            ['Foo', 'ProxyNS\\' . ClassNameInflectorInterface::PROXY_MARKER . '\\Foo\\%s'],
118
            ['Foo\\Bar', 'ProxyNS\\' . ClassNameInflectorInterface::PROXY_MARKER . '\\Foo\\Bar\\%s'],
119
        ];
120
    }
121
122
    /**
123
     * Data provider.
124
     *
125
     * @return mixed[][]
126
     */
127
    public static function getClassAndParametersCombinations() : array
128
    {
129
        return [
130
            ['Foo', []],
131
            ['Foo\\Bar', []],
132
            ['Foo', [null]],
133
            ['Foo\\Bar', [null]],
134
            ['Foo', ['foo' => 'bar']],
135
            ['Foo\\Bar', ['foo' => 'bar']],
136
            ['Foo', ["\0" => "very \0 bad"]],
137
            ['Foo\\Bar', ["\0" => "very \0 bad"]],
138
        ];
139
    }
140
}
141