diff --git a/library/Mockery.php b/library/Mockery.php index e147df16e..95abd1b9d 100644 --- a/library/Mockery.php +++ b/library/Mockery.php @@ -886,7 +886,7 @@ private static function getNewDemeterMock( $parRefMethod = $parRef->getMethod($method); $parRefMethodRetType = Reflector::getReturnType($parRefMethod, true); - if ($parRefMethodRetType !== null) { + if ($parRefMethodRetType !== null && $parRefMethodRetType !== 'mixed') { $nameBuilder = new MockNameBuilder(); $nameBuilder->addPart('\\' . $newMockName); $mock = self::namedMock($nameBuilder->build(), $parRefMethodRetType); diff --git a/tests/Mockery/MockingMethodsWithMixedReturnTypeTest.php b/tests/Mockery/MockingMethodsWithMixedReturnTypeTest.php new file mode 100644 index 000000000..ae10a5f5a --- /dev/null +++ b/tests/Mockery/MockingMethodsWithMixedReturnTypeTest.php @@ -0,0 +1,40 @@ +shouldReceive("foo->bar")->andReturn("bar"); + $this->assertSame('bar', $mock->foo()->bar()); + } +} + +interface MyInterface +{ + public function getFoo(): mixed; +}