|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy; |
|
9
|
|
|
use Zend\Code\Generator\PropertyGenerator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy} |
|
13
|
|
|
* |
|
14
|
|
|
* @author Marco Pivetta <[email protected]> |
|
15
|
|
|
* @license MIT |
|
16
|
|
|
* |
|
17
|
|
|
* @group Coverage |
|
18
|
|
|
*/ |
|
19
|
|
|
class InitializeProxyTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy::__construct |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testBodyStructure() : void |
|
25
|
|
|
{ |
|
26
|
|
|
/* @var $initializer PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ |
|
27
|
|
|
$initializer = $this->createMock(PropertyGenerator::class); |
|
28
|
|
|
/* @var $valueHolder PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject */ |
|
29
|
|
|
$valueHolder = $this->createMock(PropertyGenerator::class); |
|
30
|
|
|
|
|
31
|
|
|
$initializer->expects(self::any())->method('getName')->will(self::returnValue('foo')); |
|
32
|
|
|
$valueHolder->expects(self::any())->method('getName')->will(self::returnValue('bar')); |
|
33
|
|
|
|
|
34
|
|
|
$initializeProxy = new InitializeProxy($initializer, $valueHolder); |
|
35
|
|
|
|
|
36
|
|
|
self::assertSame('initializeProxy', $initializeProxy->getName()); |
|
37
|
|
|
self::assertCount(0, $initializeProxy->getParameters()); |
|
38
|
|
|
self::assertSame( |
|
39
|
|
|
'return $this->foo && ($this->foo->__invoke($bar, $this, \'initializeProxy\', array(), $this->foo) || 1)' |
|
40
|
|
|
. ' && $this->bar = $bar;' |
|
41
|
|
|
$initializeProxy->getBody() |
|
|
|
|
|
|
42
|
|
|
); |
|
43
|
|
|
self::assertStringMatchesFormat('%A : bool%A', $initializeProxy->generate(), 'Return type hint is boolean'); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|