Skip to content

Commit

Permalink
Test already instantiated stub instances
Browse files Browse the repository at this point in the history
  • Loading branch information
christeredvartsen authored and sebastianbergmann committed Oct 28, 2019
1 parent fac99b5 commit e6e0ad1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}

0 comments on commit e6e0ad1

Please sign in to comment.