|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator; |
|
6
|
|
|
|
|
7
|
|
|
use Laminas\Code\Generator\PropertyGenerator; |
|
8
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone; |
|
11
|
|
|
use ProxyManagerTestAsset\EmptyClass; |
|
12
|
|
|
use ReflectionClass; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone} |
|
16
|
|
|
* |
|
17
|
|
|
* @group Coverage |
|
18
|
|
|
*/ |
|
19
|
|
|
final class MagicCloneTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone::__construct |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testBodyStructure() : void |
|
25
|
|
|
{ |
|
26
|
|
|
$reflection = new ReflectionClass(EmptyClass::class); |
|
27
|
|
|
$valueHolder = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
28
|
|
|
$prefixInterceptors = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
29
|
|
|
$suffixInterceptors = $this->createMock(PropertyGenerator::class); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$valueHolder->method('getName')->willReturn('bar'); |
|
|
|
|
|
|
32
|
|
|
$prefixInterceptors->method('getName')->willReturn('pre'); |
|
|
|
|
|
|
33
|
|
|
$suffixInterceptors->method('getName')->willReturn('post'); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$magicClone = new MagicClone($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
self::assertSame('__clone', $magicClone->getName()); |
|
|
|
|
|
|
38
|
|
|
self::assertCount(0, $magicClone->getParameters()); |
|
|
|
|
|
|
39
|
|
|
self::assertSame( |
|
|
|
|
|
|
40
|
|
|
'$this->bar = clone $this->bar;' . "\n\n" |
|
41
|
|
|
. 'foreach ($this->pre as $key => $value) {' . "\n" |
|
42
|
|
|
. ' $this->pre[$key] = clone $value;' . "\n" |
|
43
|
|
|
. '}' . "\n\n" |
|
44
|
|
|
. 'foreach ($this->post as $key => $value) {' . "\n" |
|
45
|
|
|
. ' $this->post[$key] = clone $value;' . "\n" |
|
46
|
|
|
. '}', |
|
47
|
|
|
$magicClone->getBody() |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
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.