|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
declare(strict_types=1); |
|
20
|
|
|
|
|
21
|
|
|
namespace ProxyManagerTest\ProxyGenerator; |
|
22
|
|
|
|
|
23
|
|
|
use ProxyManager\Exception\InvalidProxiedClassException; |
|
24
|
|
|
use ProxyManager\Proxy\GhostObjectInterface; |
|
25
|
|
|
use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator; |
|
26
|
|
|
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; |
|
27
|
|
|
use ProxyManagerTestAsset\BaseInterface; |
|
28
|
|
|
use ProxyManagerTestAsset\ClassWithAbstractPublicMethod; |
|
29
|
|
|
use ReflectionClass; |
|
30
|
|
|
use Zend\Code\Generator\ClassGenerator; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator} |
|
34
|
|
|
* |
|
35
|
|
|
* @author Marco Pivetta <[email protected]> |
|
36
|
|
|
* @license MIT |
|
37
|
|
|
* |
|
38
|
|
|
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator |
|
39
|
|
|
* @group Coverage |
|
40
|
|
|
*/ |
|
41
|
|
|
class LazyLoadingGhostGeneratorTest extends AbstractProxyGeneratorTest |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* @dataProvider getTestedImplementations |
|
45
|
|
|
* |
|
46
|
|
|
* {@inheritDoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testGeneratesValidCode(string $className) : void |
|
49
|
|
|
{ |
|
50
|
|
|
$reflectionClass = new ReflectionClass($className); |
|
51
|
|
|
|
|
52
|
|
|
if ($reflectionClass->isInterface()) { |
|
53
|
|
|
// @todo interfaces *may* be proxied by deferring property localization to the constructor (no hardcoding) |
|
54
|
|
|
$this->expectException(InvalidProxiedClassException::class); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
parent::testGeneratesValidCode($className); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testWillRejectInterfaces() : void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->expectException(InvalidProxiedClassException::class); |
|
63
|
|
|
|
|
64
|
|
|
$this |
|
65
|
|
|
->getProxyGenerator() |
|
66
|
|
|
->generate(new \ReflectionClass(BaseInterface::class), new ClassGenerator()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testAllAbstractMethodsWillBeMadeConcrete() : void |
|
70
|
|
|
{ |
|
71
|
|
|
$classGenerator = new ClassGenerator(); |
|
72
|
|
|
|
|
73
|
|
|
$this |
|
74
|
|
|
->getProxyGenerator() |
|
75
|
|
|
->generate(new \ReflectionClass(ClassWithAbstractPublicMethod::class), $classGenerator); |
|
76
|
|
|
|
|
77
|
|
|
foreach ($classGenerator->getMethods() as $method) { |
|
78
|
|
|
self::assertFalse($method->isAbstract()); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritDoc} |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function getProxyGenerator() : ProxyGeneratorInterface |
|
86
|
|
|
{ |
|
87
|
|
|
return new LazyLoadingGhostGenerator(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritDoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getExpectedImplementedInterfaces() : array |
|
94
|
|
|
{ |
|
95
|
|
|
return [GhostObjectInterface::class]; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|