Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockHandler - Add support to reset internal queue #2143

Merged
merged 1 commit into from
Oct 23, 2019

Conversation

ingluisjimenez
Copy link
Contributor

@ingluisjimenez ingluisjimenez commented Sep 13, 2018

Q A
Bug? no
New Feature? yes
Version 6.3.3

Actual Behavior

MockHandler doesn't offer a way of resetting the internal queue. There are testing scenarios where the handler has been initialized in the setUp() method of a test suite, to avoid duplication, and some specific responses are queued up as the default behavior but then you have tests which need to queue up something different (i.e a request error).

In this cases, it is not possible to reuse the handler defined in setUp(), and instad, it is required to re-instantiate and re-wire a handler and the dependencies all over again.

Expected Behavior

To avoid having to wire and set up the handler all over again, it would be great to expose a way to reset the internal queue in the MockHandler instance, and then just queue the new response(s).

This PR adds a method to MockHandler to reset the internal queue. Calling $handler->reset(); would reset the internal array and allow the tester to queue up new responses.

@ingluisjimenez
Copy link
Contributor Author

@sagikazarmark @Nyholm Please let me know what do you think about this little feature, and whether this is the correct way of doing this or if there is a better way that maybe I'm not aware of.

@ingluisjimenez ingluisjimenez force-pushed the mock-handler-reset-queue branch 2 times, most recently from 9e2dde8 to 0ff5bf2 Compare September 14, 2018 15:33
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@Nyholm Nyholm added this to the 6.5.0 milestone Oct 19, 2019
@ingluisjimenez
Copy link
Contributor Author

rebased with latest from master

@Nyholm Nyholm merged commit 6a94646 into guzzle:master Oct 23, 2019
@ingluisjimenez
Copy link
Contributor Author

Thank you for reviewing/merging! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants