diff --git a/tests/_files/TestProxyFixture.php b/tests/_files/TestProxyFixture.php new file mode 100644 index 00000000000..2396a050583 --- /dev/null +++ b/tests/_files/TestProxyFixture.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +class TestProxyFixture +{ + public function returnString() + { + return 'result'; + } + + public function returnTypedString(): string + { + return 'result'; + } + + public function returnObject() + { + return new self; + } + + public function returnTypedObject(): self + { + return new self; + } +} diff --git a/tests/unit/Framework/MockObject/ProxyObjectTest.php b/tests/unit/Framework/MockObject/ProxyObjectTest.php index b9d85e9d89d..62e3656d98f 100644 --- a/tests/unit/Framework/MockObject/ProxyObjectTest.php +++ b/tests/unit/Framework/MockObject/ProxyObjectTest.php @@ -1,4 +1,4 @@ -getMockBuilder(Bar::class) - ->enableProxyingToOriginalMethods() - ->getMock(); + $proxy = $this->createTestProxy(TestProxyFixture::class); $proxy->expects($this->once()) - ->method('doSomethingElse'); + ->method('returnString'); - $foo = new Foo; + \assert($proxy instanceof MockObject); + \assert($proxy instanceof TestProxyFixture); - $this->assertEquals('result', $foo->doSomething($proxy)); + $this->assertSame('result', $proxy->returnString()); } - public function testMockedMethodWithReferenceIsProxiedToOriginalMethod(): void + public function testProxyingMethodWithDeclaredScalarReturnTypeWorks(): void { - $proxy = $this->getMockBuilder(MethodCallbackByReference::class) - ->enableProxyingToOriginalMethods() - ->getMock(); + $proxy = $this->createTestProxy(TestProxyFixture::class); - $a = $b = $c = 0; + $proxy->expects($this->once()) + ->method('returnTypedString'); + + \assert($proxy instanceof MockObject); + \assert($proxy instanceof TestProxyFixture); + + $this->assertSame('result', $proxy->returnTypedString()); + } + + public function testProxyingMethodWithUndeclaredObjectReturnTypeWorks(): void + { + $proxy = $this->createTestProxy(TestProxyFixture::class); + + $proxy->expects($this->once()) + ->method('returnObject'); + + \assert($proxy instanceof MockObject); + \assert($proxy instanceof TestProxyFixture); + + $this->assertInstanceOf(TestProxyFixture::class, $proxy->returnObject()); + } + + public function testProxyingMethodWithDeclaredObjectReturnTypeWorks(): void + { + $proxy = $this->createTestProxy(TestProxyFixture::class); + + $proxy->expects($this->once()) + ->method('returnTypedObject'); - $proxy->callback($a, $b, $c); + \assert($proxy instanceof MockObject); + \assert($proxy instanceof TestProxyFixture); - $this->assertEquals(1, $b); + $this->assertInstanceOf(TestProxyFixture::class, $proxy->returnTypedObject()); } }