|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\NullObject\MethodGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor; |
|
9
|
|
|
use ProxyManagerTestAsset\ClassWithMixedProperties; |
|
10
|
|
|
use ProxyManagerTestAsset\ClassWithMixedTypedProperties; |
|
11
|
|
|
use ProxyManagerTestAsset\ClassWithPrivateProperties; |
|
12
|
|
|
use ReflectionClass; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor} |
|
16
|
|
|
* |
|
17
|
|
|
* @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor |
|
18
|
|
|
* @group Coverage |
|
19
|
|
|
*/ |
|
20
|
|
|
final class StaticProxyConstructorTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
public function testBodyStructure() : void |
|
23
|
|
|
{ |
|
24
|
|
|
$constructor = new StaticProxyConstructor( |
|
25
|
|
|
new ReflectionClass(ClassWithMixedProperties::class) |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
self::assertSame('staticProxyConstructor', $constructor->getName()); |
|
|
|
|
|
|
29
|
|
|
self::assertSame(ClassWithMixedProperties::class, (string) $constructor->getReturnType()); |
|
|
|
|
|
|
30
|
|
|
self::assertTrue($constructor->isStatic()); |
|
|
|
|
|
|
31
|
|
|
self::assertSame('public', $constructor->getVisibility()); |
|
|
|
|
|
|
32
|
|
|
self::assertCount(0, $constructor->getParameters()); |
|
|
|
|
|
|
33
|
|
|
self::assertSame( |
|
|
|
|
|
|
34
|
|
|
'static $reflection; |
|
35
|
|
|
|
|
36
|
|
|
$reflection = $reflection ?? new \ReflectionClass(__CLASS__); |
|
37
|
|
|
$instance = $reflection->newInstanceWithoutConstructor(); |
|
38
|
|
|
|
|
39
|
|
|
$instance->publicProperty0 = null; |
|
40
|
|
|
$instance->publicProperty1 = null; |
|
41
|
|
|
$instance->publicProperty2 = null; |
|
42
|
|
|
|
|
43
|
|
|
return $instance;', |
|
44
|
|
|
$constructor->getBody() |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testBodyStructureWithoutPublicProperties() : void |
|
49
|
|
|
{ |
|
50
|
|
|
$constructor = new StaticProxyConstructor( |
|
51
|
|
|
new ReflectionClass(ClassWithPrivateProperties::class) |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
self::assertSame('staticProxyConstructor', $constructor->getName()); |
|
|
|
|
|
|
55
|
|
|
self::assertCount(0, $constructor->getParameters()); |
|
|
|
|
|
|
56
|
|
|
self::assertSame(ClassWithPrivateProperties::class, (string) $constructor->getReturnType()); |
|
|
|
|
|
|
57
|
|
|
$body = $constructor->getBody(); |
|
58
|
|
|
self::assertSame( |
|
|
|
|
|
|
59
|
|
|
'static $reflection; |
|
60
|
|
|
|
|
61
|
|
|
$reflection = $reflection ?? new \ReflectionClass(__CLASS__); |
|
62
|
|
|
$instance = $reflection->newInstanceWithoutConstructor(); |
|
63
|
|
|
|
|
64
|
|
|
return $instance;', |
|
65
|
|
|
$body |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testBodyStructureWithTypedProperties() : void |
|
70
|
|
|
{ |
|
71
|
|
|
$constructor = new StaticProxyConstructor(new ReflectionClass(ClassWithMixedTypedProperties::class)); |
|
72
|
|
|
|
|
73
|
|
|
self::assertSame('staticProxyConstructor', $constructor->getName()); |
|
|
|
|
|
|
74
|
|
|
self::assertSame(ClassWithMixedTypedProperties::class, (string) $constructor->getReturnType()); |
|
|
|
|
|
|
75
|
|
|
self::assertTrue($constructor->isStatic()); |
|
|
|
|
|
|
76
|
|
|
self::assertSame('public', $constructor->getVisibility()); |
|
|
|
|
|
|
77
|
|
|
self::assertCount(0, $constructor->getParameters()); |
|
|
|
|
|
|
78
|
|
|
self::assertSame( |
|
|
|
|
|
|
79
|
|
|
'static $reflection; |
|
80
|
|
|
|
|
81
|
|
|
$reflection = $reflection ?? new \ReflectionClass(__CLASS__); |
|
82
|
|
|
$instance = $reflection->newInstanceWithoutConstructor(); |
|
83
|
|
|
|
|
84
|
|
|
$instance->publicUnTypedProperty = null; |
|
85
|
|
|
$instance->publicUnTypedPropertyWithoutDefaultValue = null; |
|
86
|
|
|
$instance->publicNullableBoolProperty = null; |
|
87
|
|
|
$instance->publicNullableBoolPropertyWithoutDefaultValue = null; |
|
88
|
|
|
$instance->publicNullableIntProperty = null; |
|
89
|
|
|
$instance->publicNullableIntPropertyWithoutDefaultValue = null; |
|
90
|
|
|
$instance->publicNullableFloatProperty = null; |
|
91
|
|
|
$instance->publicNullableFloatPropertyWithoutDefaultValue = null; |
|
92
|
|
|
$instance->publicNullableStringProperty = null; |
|
93
|
|
|
$instance->publicNullableStringPropertyWithoutDefaultValue = null; |
|
94
|
|
|
$instance->publicNullableArrayProperty = null; |
|
95
|
|
|
$instance->publicNullableArrayPropertyWithoutDefaultValue = null; |
|
96
|
|
|
$instance->publicNullableIterableProperty = null; |
|
97
|
|
|
$instance->publicNullableIterablePropertyWithoutDefaultValue = null; |
|
98
|
|
|
$instance->publicNullableObjectProperty = null; |
|
99
|
|
|
$instance->publicNullableClassProperty = null; |
|
100
|
|
|
|
|
101
|
|
|
return $instance;', |
|
102
|
|
|
$constructor->getBody() |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
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.