|
1 | | -<?php |
| 1 | +<?php declare(strict_types=1); |
2 | 2 | /* |
3 | 3 | * This file is part of PHPUnit. |
4 | 4 | * |
|
8 | 8 | * file that was distributed with this source code. |
9 | 9 | */ |
10 | 10 |
|
| 11 | +use PHPUnit\Framework\MockObject\MockObject; |
11 | 12 | use PHPUnit\Framework\TestCase; |
12 | 13 |
|
13 | | -class ProxyObjectTest extends TestCase |
| 14 | +final class ProxyObjectTest extends TestCase |
14 | 15 | { |
15 | | - public function testMockedMethodIsProxiedToOriginalMethod(): void |
| 16 | + public function testProxyingMethodWithUndeclaredScalarReturnTypeWorks(): void |
16 | 17 | { |
17 | | - $proxy = $this->getMockBuilder(Bar::class) |
18 | | - ->enableProxyingToOriginalMethods() |
19 | | - ->getMock(); |
| 18 | + $proxy = $this->createTestProxy(TestProxyFixture::class); |
20 | 19 |
|
21 | 20 | $proxy->expects($this->once()) |
22 | | - ->method('doSomethingElse'); |
| 21 | + ->method('returnString'); |
23 | 22 |
|
24 | | - $foo = new Foo; |
| 23 | + \assert($proxy instanceof MockObject); |
| 24 | + \assert($proxy instanceof TestProxyFixture); |
25 | 25 |
|
26 | | - $this->assertEquals('result', $foo->doSomething($proxy)); |
| 26 | + $this->assertSame('result', $proxy->returnString()); |
27 | 27 | } |
28 | 28 |
|
29 | | - public function testMockedMethodWithReferenceIsProxiedToOriginalMethod(): void |
| 29 | + public function testProxyingMethodWithDeclaredScalarReturnTypeWorks(): void |
30 | 30 | { |
31 | | - $proxy = $this->getMockBuilder(MethodCallbackByReference::class) |
32 | | - ->enableProxyingToOriginalMethods() |
33 | | - ->getMock(); |
| 31 | + $proxy = $this->createTestProxy(TestProxyFixture::class); |
34 | 32 |
|
35 | | - $a = $b = $c = 0; |
| 33 | + $proxy->expects($this->once()) |
| 34 | + ->method('returnTypedString'); |
| 35 | + |
| 36 | + \assert($proxy instanceof MockObject); |
| 37 | + \assert($proxy instanceof TestProxyFixture); |
| 38 | + |
| 39 | + $this->assertSame('result', $proxy->returnTypedString()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testProxyingMethodWithUndeclaredObjectReturnTypeWorks(): void |
| 43 | + { |
| 44 | + $proxy = $this->createTestProxy(TestProxyFixture::class); |
| 45 | + |
| 46 | + $proxy->expects($this->once()) |
| 47 | + ->method('returnObject'); |
| 48 | + |
| 49 | + \assert($proxy instanceof MockObject); |
| 50 | + \assert($proxy instanceof TestProxyFixture); |
| 51 | + |
| 52 | + $this->assertInstanceOf(TestProxyFixture::class, $proxy->returnObject()); |
| 53 | + } |
| 54 | + |
| 55 | + public function testProxyingMethodWithDeclaredObjectReturnTypeWorks(): void |
| 56 | + { |
| 57 | + $proxy = $this->createTestProxy(TestProxyFixture::class); |
| 58 | + |
| 59 | + $proxy->expects($this->once()) |
| 60 | + ->method('returnTypedObject'); |
36 | 61 |
|
37 | | - $proxy->callback($a, $b, $c); |
| 62 | + \assert($proxy instanceof MockObject); |
| 63 | + \assert($proxy instanceof TestProxyFixture); |
38 | 64 |
|
39 | | - $this->assertEquals(1, $b); |
| 65 | + $this->assertInstanceOf(TestProxyFixture::class, $proxy->returnTypedObject()); |
40 | 66 | } |
41 | 67 | } |
0 commit comments