createMock(CallbackStub::class); $invocationMocker = $mock->expects(self::exactly($invocationCount)) ->method('__invoke'); if ($returnCallback) { $invocationMocker->willReturnCallback($returnCallback); } if ($expectArgs) { $invocationMocker->with(...$expectArgs); } return $mock(...); } }