Jimdo / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
281 stars 213 forks source link

Allow the injection of a Guzzle ClientInterface to PushGateway #54

Closed anthonysterling closed 6 years ago

anthonysterling commented 7 years ago

This PR enables the ability to inject a Guzzle Client in to the Push Gateway on creation, allowing us to mock/configure the Guzzle Client for tests.

bracki commented 6 years ago

Why would you mock this out for tests? Would be helpful to have a test that shows how to do it and also update the docs.

anthonysterling commented 6 years ago

Hello @bracki.

Why would you mock this out for tests?

I needed to write some integration tests for one of our services, and this change allowed me to supply a mock Guzzle client that did not persist the collected metrics during the test runs. As the doRequest method is private sub-classing it wasn't an option, this change seemed to be the best non-breaking change with the additional benefit of allowing the dependency to be injected if required.

I'm more than happy to add a test covering this change and updating the docs if you feel this change is suitable.