1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator; |
6
|
|
|
|
7
|
|
|
use Laminas\Code\Generator\PropertyGenerator; |
8
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset; |
11
|
|
|
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; |
12
|
|
|
use ProxyManagerTestAsset\EmptyClass; |
13
|
|
|
use ReflectionClass; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset} |
17
|
|
|
* |
18
|
|
|
* @group Coverage |
19
|
|
|
*/ |
20
|
|
|
final class MagicIssetTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset::__construct |
24
|
|
|
*/ |
25
|
|
|
public function testBodyStructure() : void |
26
|
|
|
{ |
27
|
|
|
$reflection = new ReflectionClass(EmptyClass::class); |
28
|
|
|
$initializer = $this->createMock(PropertyGenerator::class); |
|
|
|
|
29
|
|
|
$valueHolder = $this->createMock(PropertyGenerator::class); |
|
|
|
|
30
|
|
|
$publicProperties = $this->createMock(PublicPropertiesMap::class); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$initializer->method('getName')->willReturn('foo'); |
|
|
|
|
33
|
|
|
$valueHolder->method('getName')->willReturn('bar'); |
|
|
|
|
34
|
|
|
$publicProperties->method('isEmpty')->willReturn(false); |
|
|
|
|
35
|
|
|
$publicProperties->method('getName')->willReturn('bar'); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$magicIsset = new MagicIsset($reflection, $initializer, $valueHolder, $publicProperties); |
|
|
|
|
38
|
|
|
|
39
|
|
|
self::assertSame('__isset', $magicIsset->getName()); |
|
|
|
|
40
|
|
|
self::assertCount(1, $magicIsset->getParameters()); |
|
|
|
|
41
|
|
|
self::assertStringMatchesFormat( |
|
|
|
|
42
|
|
|
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__isset', array('name' => \$name)" |
43
|
|
|
. ", \$this->foo);\n\n" |
44
|
|
|
. "if (isset(self::\$bar[\$name])) {\n return isset(\$this->bar->\$name);\n}" |
45
|
|
|
. '%areturn %s;', |
46
|
|
|
$magicIsset->getBody() |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.