|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ProxyManagerTest\Generator; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use ProxyManager\Generator\MagicMethodGenerator; |
|
9
|
|
|
use ProxyManagerTestAsset\ClassWithByRefMagicMethods; |
|
10
|
|
|
use ProxyManagerTestAsset\ClassWithMagicMethods; |
|
11
|
|
|
use ProxyManagerTestAsset\EmptyClass; |
|
12
|
|
|
use ReflectionClass; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Tests for {@see \ProxyManager\Generator\MagicMethodGenerator} |
|
16
|
|
|
* |
|
17
|
|
|
* @group Coverage |
|
18
|
|
|
* @covers \ProxyManager\Generator\MagicMethodGenerator |
|
19
|
|
|
*/ |
|
20
|
|
|
final class MagicMethodGeneratorTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
public function testGeneratesCorrectByRefReturnValue() : void |
|
23
|
|
|
{ |
|
24
|
|
|
$reflection = new ReflectionClass(ClassWithByRefMagicMethods::class); |
|
25
|
|
|
$magicMethod = new MagicMethodGenerator($reflection, '__get', ['name']); |
|
26
|
|
|
|
|
27
|
|
|
self::assertStringMatchesFormat('%Apublic function & __get(%A', $magicMethod->generate()); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testGeneratesCorrectByValReturnValue() : void |
|
31
|
|
|
{ |
|
32
|
|
|
$reflection = new ReflectionClass(ClassWithMagicMethods::class); |
|
33
|
|
|
$magicMethod = new MagicMethodGenerator($reflection, '__get', ['name']); |
|
34
|
|
|
|
|
35
|
|
|
self::assertStringMatchesFormat('%Apublic function __get(%A', $magicMethod->generate()); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGeneratesByRefReturnValueWithNonExistingGetMethod() : void |
|
39
|
|
|
{ |
|
40
|
|
|
$reflection = new ReflectionClass(EmptyClass::class); |
|
41
|
|
|
$magicMethod = new MagicMethodGenerator($reflection, '__get', ['name']); |
|
42
|
|
|
|
|
43
|
|
|
self::assertStringMatchesFormat('%Apublic function & __get(%A', $magicMethod->generate()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testGeneratesByValReturnValueWithNonExistingNonGetMethod() : void |
|
47
|
|
|
{ |
|
48
|
|
|
$reflection = new ReflectionClass(EmptyClass::class); |
|
49
|
|
|
$magicMethod = new MagicMethodGenerator($reflection, '__set', ['name']); |
|
50
|
|
|
|
|
51
|
|
|
self::assertStringMatchesFormat('%Apublic function __set(%A', $magicMethod->generate()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.