From e6e0ad16bd72396afad4e8cf111369a8a89e8fe4 Mon Sep 17 00:00:00 2001 From: Christer Edvartsen Date: Mon, 28 Oct 2019 12:47:56 +0100 Subject: [PATCH] Test already instantiated stub instances --- .../Builder/InvocationMockerTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php b/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php index 12dd880e60e..d9e22d9ffc2 100644 --- a/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php +++ b/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php @@ -14,6 +14,8 @@ use PHPUnit\Framework\MockObject\IncompatibleReturnValueException; use PHPUnit\Framework\MockObject\InvocationHandler; use PHPUnit\Framework\MockObject\Matcher; +use PHPUnit\Framework\MockObject\Stub\ReturnSelf; +use PHPUnit\Framework\MockObject\Stub\ReturnStub; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\ClassWithImplicitProtocol; @@ -238,4 +240,22 @@ public function testExpectationsAreNotTriggeredUntilPreviousMethodWasCalled(): v $mock->firstCall(); $mock->secondCall(); } + + public function testWillReturnAlreadyInstantiatedStubs(): void + { + $mock = $this->getMockBuilder(stdClass::class) + ->setMethods(['foo', 'bar']) + ->getMock(); + + $mock->expects($this->any()) + ->method('foo') + ->willReturn(new ReturnStub('foo')); + + $mock->expects($this->any()) + ->method('bar') + ->willReturn(new ReturnSelf()); + + $this->assertSame('foo', $mock->foo()); + $this->assertSame($mock, $mock->bar()); + } }