getMockBuilder(GeoProvider::class) ->disableOriginalConstructor() ->getMock(); $nominatimGeocoder->method('getAddressCollection') ->willThrowException(new InvalidServerResponse()); $handler = new UserAddressQueryHandler($nominatimGeocoder); $this->expectException(\RuntimeException::class); $address = (new Address()) ->setAddress('foo') ->setLocality('foo') ->setPostalCode('foo') ->setCountry('FR') ; $handler(new UserAddressQuery($address)); } }