1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
<?php
declare(strict_types=1);
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
use Laminas\Code\Generator\PropertyGenerator;
use Laminas\Code\Reflection\MethodReflection;
use PHPUnit\Framework\TestCase;
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod;
use ProxyManagerTestAsset\BaseClass;
use ReflectionClass;
/**
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod}
*
* @group Coverage
*/
final class RemoteObjectMethodTest extends TestCase
{
/**
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
*/
public function testBodyStructureWithParameters(): void
{
$adapter = $this->createMock(PropertyGenerator::class);
$adapter->method('getName')->willReturn('adapter');
$reflectionMethod = new MethodReflection(
BaseClass::class,
'publicByReferenceParameterMethod'
);
$method = RemoteObjectMethod::generateMethod(
$reflectionMethod,
$adapter,
new ReflectionClass(PropertyGenerator::class)
);
self::assertSame('publicByReferenceParameterMethod', $method->getName());
self::assertCount(2, $method->getParameters());
self::assertSame(
'$args = \func_get_args();
switch (\func_num_args()) {
case 0: $args[] = null;
case 1: $args[] = null;
}
$return = $this->adapter->call(\'Laminas\\\\Code\\\\Generator\\\\PropertyGenerator\', \'publicByReferenceParameterMethod\', $args);
return $return;',
$method->getBody()
);
}
/**
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
*/
public function testBodyStructureWithArrayParameter(): void
{
$adapter = $this->createMock(PropertyGenerator::class);
$adapter->method('getName')->willReturn('adapter');
$reflectionMethod = new MethodReflection(BaseClass::class, 'publicArrayHintedMethod');
$method = RemoteObjectMethod::generateMethod(
$reflectionMethod,
$adapter,
new ReflectionClass(PropertyGenerator::class)
);
self::assertSame('publicArrayHintedMethod', $method->getName());
self::assertCount(1, $method->getParameters());
self::assertSame(
"\$args = \\func_get_args();
switch (\\func_num_args()) {
case 0: \$args[] = null;
}
\$return = \$this->adapter->call('Laminas\\\\Code\\\\Generator\\\\PropertyGenerator', 'publicArrayHintedMethod', \$args);
return \$return;",
$method->getBody()
);
}
/**
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
*/
public function testBodyStructureWithoutParameters(): void
{
$adapter = $this->createMock(PropertyGenerator::class);
$adapter->method('getName')->willReturn('adapter');
$reflectionMethod = new MethodReflection(BaseClass::class, 'publicMethod');
$method = RemoteObjectMethod::generateMethod(
$reflectionMethod,
$adapter,
new ReflectionClass(PropertyGenerator::class)
);
self::assertSame('publicMethod', $method->getName());
self::assertCount(0, $method->getParameters());
self::assertSame(
"\$args = \\func_get_args();
switch (\\func_num_args()) {
}
\$return = \$this->adapter->call('Laminas\\\\Code\\\\Generator\\\\PropertyGenerator', 'publicMethod', \$args);
return \$return;",
$method->getBody()
);
}
}
|