CanProxyAssertionTest::testAllowedClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator\Assertion;
6
7
use BadMethodCallException;
8
use PHPUnit\Framework\TestCase;
9
use ProxyManager\Exception\InvalidProxiedClassException;
10
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
11
use ProxyManagerTestAsset\AccessInterceptorValueHolderMock;
12
use ProxyManagerTestAsset\BaseClass;
13
use ProxyManagerTestAsset\BaseInterface;
14
use ProxyManagerTestAsset\CallableTypeHintClass;
15
use ProxyManagerTestAsset\ClassWithAbstractProtectedMethod;
16
use ProxyManagerTestAsset\ClassWithByRefMagicMethods;
17
use ProxyManagerTestAsset\ClassWithFinalMagicMethods;
18
use ProxyManagerTestAsset\ClassWithFinalMethods;
19
use ProxyManagerTestAsset\ClassWithMethodWithDefaultParameters;
20
use ProxyManagerTestAsset\ClassWithMixedProperties;
21
use ProxyManagerTestAsset\ClassWithParentHint;
22
use ProxyManagerTestAsset\ClassWithPrivateProperties;
23
use ProxyManagerTestAsset\ClassWithProtectedProperties;
24
use ProxyManagerTestAsset\ClassWithPublicArrayProperty;
25
use ProxyManagerTestAsset\ClassWithPublicProperties;
26
use ProxyManagerTestAsset\ClassWithSelfHint;
27
use ProxyManagerTestAsset\EmptyClass;
28
use ProxyManagerTestAsset\FinalClass;
29
use ProxyManagerTestAsset\HydratedObject;
30
use ProxyManagerTestAsset\LazyLoadingMock;
31
use ProxyManagerTestAsset\NullObjectMock;
32
use ReflectionClass;
33
34
/**
35
 * Tests for {@see \ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion}
36
 *
37
 * @covers \ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion
38
 * @group Coverage
39
 */
40
final class CanProxyAssertionTest extends TestCase
41
{
42
    public function testDeniesFinalClasses() : void
43
    {
44
        $this->expectException(InvalidProxiedClassException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<ProxyManagerTest\...\CanProxyAssertionTest>.

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
46
        CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass(FinalClass::class));
47
    }
48
49
    public function testDeniesClassesWithAbstractProtectedMethods() : void
50
    {
51
        $this->expectException(InvalidProxiedClassException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<ProxyManagerTest\...\CanProxyAssertionTest>.

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...
52
53
        CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass(
54
            ClassWithAbstractProtectedMethod::class
55
        ));
56
    }
57
58
    public function testAllowsInterfaceByDefault() : void
59
    {
60
        CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass(
61
            BaseInterface::class
62
        ));
63
64
        self::assertTrue(true); // not nice, but assertions are just fail-checks, no real code executed
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProxyManagerTest\...\CanProxyAssertionTest>.

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
    }
66
67
    public function testDeniesInterfaceIfSpecified() : void
68
    {
69
        CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass(BaseClass::class), false);
70
71
        $this->expectException(InvalidProxiedClassException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<ProxyManagerTest\...\CanProxyAssertionTest>.

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...
72
73
        CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass(BaseInterface::class), false);
74
    }
75
76
    /**
77
     * @dataProvider validClasses
78
     * @psalm-param class-string $className
79
     */
80
    public function testAllowedClass(string $className) : void
81
    {
82
        CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass($className));
83
84
        self::assertTrue(true); // not nice, but assertions are just fail-checks, no real code executed
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ProxyManagerTest\...\CanProxyAssertionTest>.

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...
85
    }
86
87
    public function testDisallowsConstructor() : void
88
    {
89
        $this->expectException(BadMethodCallException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<ProxyManagerTest\...\CanProxyAssertionTest>.

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...
90
91
        new CanProxyAssertion();
92
    }
93
94
    /**
95
     * @return string[][]
96
     */
97
    public function validClasses() : array
98
    {
99
        return [
100
            [AccessInterceptorValueHolderMock::class],
101
            [BaseClass::class],
102
            [BaseInterface::class],
103
            [CallableTypeHintClass::class],
104
            [ClassWithByRefMagicMethods::class],
105
            [ClassWithFinalMagicMethods::class],
106
            [ClassWithFinalMethods::class],
107
            [ClassWithMethodWithDefaultParameters::class],
108
            [ClassWithMixedProperties::class],
109
            [ClassWithPrivateProperties::class],
110
            [ClassWithProtectedProperties::class],
111
            [ClassWithPublicProperties::class],
112
            [ClassWithPublicArrayProperty::class],
113
            [ClassWithSelfHint::class],
114
            [ClassWithParentHint::class],
115
            [EmptyClass::class],
116
            [HydratedObject::class],
117
            [LazyLoadingMock::class],
118
            [NullObjectMock::class],
119
        ];
120
    }
121
}
122