|
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\MagicSleep; |
|
11
|
|
|
use ProxyManagerTestAsset\ClassWithMagicMethods; |
|
12
|
|
|
use ProxyManagerTestAsset\EmptyClass; |
|
13
|
|
|
use ReflectionClass; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep} |
|
17
|
|
|
* |
|
18
|
|
|
* @group Coverage |
|
19
|
|
|
*/ |
|
20
|
|
|
final class MagicSleepTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep::__construct |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testBodyStructure() : void |
|
26
|
|
|
{ |
|
27
|
|
|
$reflection = new ReflectionClass(EmptyClass::class); |
|
28
|
|
|
$prefixInterceptors = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
29
|
|
|
$suffixInterceptors = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$prefixInterceptors->method('getName')->willReturn('pre'); |
|
|
|
|
|
|
32
|
|
|
$suffixInterceptors->method('getName')->willReturn('post'); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$magicGet = new MagicSleep( |
|
35
|
|
|
$reflection, |
|
36
|
|
|
$prefixInterceptors, |
|
|
|
|
|
|
37
|
|
|
$suffixInterceptors |
|
|
|
|
|
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
self::assertSame('__sleep', $magicGet->getName()); |
|
|
|
|
|
|
41
|
|
|
self::assertEmpty($magicGet->getParameters()); |
|
|
|
|
|
|
42
|
|
|
self::assertStringMatchesFormat('%a$returnValue = array_keys((array) $this);%a', $magicGet->getBody()); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep::__construct |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testBodyStructureWithInheritedMethod() : void |
|
49
|
|
|
{ |
|
50
|
|
|
$reflection = new ReflectionClass(ClassWithMagicMethods::class); |
|
51
|
|
|
$prefixInterceptors = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
52
|
|
|
$suffixInterceptors = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$prefixInterceptors->method('getName')->willReturn('pre'); |
|
|
|
|
|
|
55
|
|
|
$suffixInterceptors->method('getName')->willReturn('post'); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$magicGet = new MagicSleep( |
|
58
|
|
|
$reflection, |
|
59
|
|
|
$prefixInterceptors, |
|
|
|
|
|
|
60
|
|
|
$suffixInterceptors |
|
|
|
|
|
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
self::assertSame('__sleep', $magicGet->getName()); |
|
|
|
|
|
|
64
|
|
|
self::assertEmpty($magicGet->getParameters()); |
|
|
|
|
|
|
65
|
|
|
self::assertStringMatchesFormat('%a$returnValue = & parent::__sleep();%a', $magicGet->getBody()); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
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.