|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use Laminas\Code\Generator\ClassGenerator; |
|
8
|
|
|
use ProxyManager\Exception\InvalidProxiedClassException; |
|
9
|
|
|
use ProxyManager\Exception\UnsupportedProxiedClassException; |
|
10
|
|
|
use ProxyManager\Proxy\AccessInterceptorInterface; |
|
11
|
|
|
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator; |
|
12
|
|
|
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; |
|
13
|
|
|
use ProxyManagerTestAsset\BaseInterface; |
|
14
|
|
|
use ProxyManagerTestAsset\ClassWithMixedTypedProperties; |
|
15
|
|
|
use ReflectionClass; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator} |
|
19
|
|
|
* |
|
20
|
|
|
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator |
|
21
|
|
|
* @group Coverage |
|
22
|
|
|
*/ |
|
23
|
|
|
final class AccessInterceptorScopeLocalizerTest extends AbstractProxyGeneratorTest |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @dataProvider getTestedImplementations |
|
27
|
|
|
* |
|
28
|
|
|
* {@inheritDoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testGeneratesValidCode(string $className) : void |
|
31
|
|
|
{ |
|
32
|
|
|
$reflectionClass = new ReflectionClass($className); |
|
33
|
|
|
|
|
34
|
|
|
if ($reflectionClass->isInterface()) { |
|
35
|
|
|
// @todo interfaces *may* be proxied by deferring property localization to the constructor (no hardcoding) |
|
36
|
|
|
$this->expectException(InvalidProxiedClassException::class); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if ($reflectionClass->getName() === ClassWithMixedTypedProperties::class) { |
|
40
|
|
|
$this->expectException(UnsupportedProxiedClassException::class); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
parent::testGeneratesValidCode($className); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testWillRejectInterfaces() : void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->expectException(InvalidProxiedClassException::class); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$this |
|
51
|
|
|
->getProxyGenerator() |
|
52
|
|
|
->generate(new ReflectionClass(BaseInterface::class), new ClassGenerator()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritDoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function getProxyGenerator() : ProxyGeneratorInterface |
|
59
|
|
|
{ |
|
60
|
|
|
return new AccessInterceptorScopeLocalizerGenerator(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritDoc} |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getExpectedImplementedInterfaces() : array |
|
67
|
|
|
{ |
|
68
|
|
|
return [AccessInterceptorInterface::class]; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
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.