1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator; |
6
|
|
|
|
7
|
|
|
use Laminas\Code\Generator\PropertyGenerator; |
8
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor; |
11
|
|
|
use ProxyManagerTestAsset\ClassWithProtectedProperties; |
12
|
|
|
use ProxyManagerTestAsset\ClassWithPublicProperties; |
13
|
|
|
use ReflectionClass; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor} |
17
|
|
|
* |
18
|
|
|
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\StaticProxyConstructor |
19
|
|
|
* @group Coverage |
20
|
|
|
*/ |
21
|
|
|
final class StaticProxyConstructorTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** @var PropertyGenerator&MockObject */ |
24
|
|
|
private PropertyGenerator $prefixInterceptors; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** @var PropertyGenerator&MockObject */ |
27
|
|
|
private PropertyGenerator $suffixInterceptors; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritDoc} |
31
|
|
|
*/ |
32
|
|
|
protected function setUp() : void |
33
|
|
|
{ |
34
|
|
|
$this->prefixInterceptors = $this->createMock(PropertyGenerator::class); |
35
|
|
|
$this->suffixInterceptors = $this->createMock(PropertyGenerator::class); |
36
|
|
|
|
37
|
|
|
$this->prefixInterceptors->method('getName')->willReturn('pre'); |
38
|
|
|
$this->suffixInterceptors->method('getName')->willReturn('post'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testSignature() : void |
42
|
|
|
{ |
43
|
|
|
$method = new StaticProxyConstructor(new ReflectionClass(ClassWithProtectedProperties::class)); |
44
|
|
|
|
45
|
|
|
self::assertSame('staticProxyConstructor', $method->getName()); |
46
|
|
|
self::assertTrue($method->isStatic()); |
47
|
|
|
self::assertSame('public', $method->getVisibility()); |
48
|
|
|
|
49
|
|
|
$parameters = $method->getParameters(); |
50
|
|
|
|
51
|
|
|
self::assertCount(3, $parameters); |
52
|
|
|
|
53
|
|
|
self::assertSame(ClassWithProtectedProperties::class, $parameters['localizedObject']->getType()); |
54
|
|
|
self::assertSame('array', $parameters['prefixInterceptors']->getType()); |
55
|
|
|
self::assertSame('array', $parameters['suffixInterceptors']->getType()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testBodyStructure() : void |
59
|
|
|
{ |
60
|
|
|
$method = new StaticProxyConstructor(new ReflectionClass(ClassWithPublicProperties::class)); |
61
|
|
|
|
62
|
|
|
self::assertSame( |
63
|
|
|
'static $reflection; |
64
|
|
|
|
65
|
|
|
$reflection = $reflection ?? new \ReflectionClass(__CLASS__); |
66
|
|
|
$instance = $reflection->newInstanceWithoutConstructor(); |
67
|
|
|
|
68
|
|
|
$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors); |
69
|
|
|
|
70
|
|
|
return $instance;', |
71
|
|
|
$method->getBody() |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|