1 | <?php |
||
22 | final class InterceptedMethodTest extends TestCase |
||
23 | { |
||
24 | /** @var PropertyGenerator&MockObject */ |
||
25 | private PropertyGenerator $prefixInterceptors; |
||
|
|||
26 | |||
27 | /** @var PropertyGenerator&MockObject */ |
||
28 | private PropertyGenerator $suffixInterceptors; |
||
29 | |||
30 | /** |
||
31 | * {@inheritDoc} |
||
32 | */ |
||
33 | protected function setUp() : void |
||
34 | { |
||
35 | parent::setUp(); |
||
36 | |||
37 | $this->prefixInterceptors = $this->createMock(PropertyGenerator::class); |
||
38 | $this->suffixInterceptors = $this->createMock(PropertyGenerator::class); |
||
39 | |||
40 | $this->prefixInterceptors->method('getName')->willReturn('pre'); |
||
41 | $this->suffixInterceptors->method('getName')->willReturn('post'); |
||
42 | } |
||
43 | |||
44 | public function testBodyStructure() : void |
||
45 | { |
||
46 | $method = InterceptedMethod::generateMethod( |
||
47 | new MethodReflection(BaseClass::class, 'publicByReferenceParameterMethod'), |
||
48 | $this->prefixInterceptors, |
||
49 | $this->suffixInterceptors |
||
50 | ); |
||
51 | |||
52 | self::assertInstanceOf(MethodGenerator::class, $method); |
||
53 | |||
54 | self::assertSame('publicByReferenceParameterMethod', $method->getName()); |
||
55 | self::assertCount(2, $method->getParameters()); |
||
56 | self::assertStringMatchesFormat( |
||
57 | '%a$returnValue = parent::publicByReferenceParameterMethod($param, $byRefParam);%A', |
||
58 | $method->getBody() |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | public function testForwardsVariadicParameters() : void |
||
63 | { |
||
64 | $method = InterceptedMethod::generateMethod( |
||
65 | new MethodReflection(ClassWithMethodWithVariadicFunction::class, 'foo'), |
||
66 | $this->prefixInterceptors, |
||
67 | $this->suffixInterceptors |
||
68 | ); |
||
69 | |||
70 | self::assertInstanceOf(MethodGenerator::class, $method); |
||
71 | |||
72 | self::assertSame('foo', $method->getName()); |
||
73 | self::assertCount(2, $method->getParameters()); |
||
74 | self::assertStringMatchesFormat( |
||
75 | '%a$returnValue = parent::foo($bar, ...$baz);%A', |
||
76 | $method->getBody() |
||
77 | ); |
||
78 | } |
||
79 | } |
||
80 |