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

Rewrite tests to avoid mocking HTTP messages #45

Open
sagikazarmark opened this issue Sep 2, 2016 · 10 comments
Open

Rewrite tests to avoid mocking HTTP messages #45

sagikazarmark opened this issue Sep 2, 2016 · 10 comments

Comments

@sagikazarmark
Copy link
Member

Q A
Bug? no
New Feature? no
Version <=1.3.x

Actual Behavior

Testing our code is pretty hard because of all the mocks necessary to test HTTP Message related code and Plugin Chain.

Expected Behavior

It should be pretty easy to understand tests, modify behaviour, provide new test cases, etc.

Possible Solutions

  • Rewrite specifications to simple unit tests using the MockClient.
  • Rewrite specifications to use actual Message objects (so only remove mocking, but preserve specifications)

WDYT?

@joelwurtz
Copy link
Member

Rewrite specifications to simple unit tests using the MockClient.

👍 but would need to do this : php-http/mock-client#3

@dbu
Copy link
Contributor

dbu commented Sep 5, 2016

what is the problem, can php-spec not use actual message objects instead of mocks? i'd rather stay consistent with the testing tool if that is not adding another complexity

@sagikazarmark
Copy link
Member Author

Of course PHPSpec can use actual objects, but it would be pointless to use the MockClient in that case, since PHPSpec (obviously) does not allow such assertions.

@dbu
Copy link
Contributor

dbu commented Sep 6, 2016 via email

@joelwurtz
Copy link
Member

asserting things with phpspec would make us using phpunit to do assert, so we should go full phpunit IMO

@sagikazarmark
Copy link
Member Author

I think using actual message implementations is kind of a midway. But it would not work with mock client.

If we want to use MockClient here, we need PHPUnit, and in that case, I would probable migrate all tests to PHPUnit. Downside is that it's huge amount of work.

But do we really want to use MockClient?

@dbu
Copy link
Contributor

dbu commented Sep 6, 2016 via email

@joelwurtz
Copy link
Member

Problem is not the MockClient, if we use actual message implementations we still have to do asserts on the output which will be also message implementations (and not prophecy) so we will have the same problem IMO

@fbourigault
Copy link
Contributor

I wrote those days tests which use mesage implementations. It's phpunit based, but I felt comfortable with using message implementation instead of unreadable mock. I don't know if this could work with phpspec, but it probably worth it to try. See https://github.com/m4tthumphrey/php-gitlab-api/pull/191/files#diff-48ee2e1f1f63bacd2d694cc463c0c8fe for my phpunit example.

@sagikazarmark
Copy link
Member Author

HTTP Messages are kind of Value Objects, so I think it was a mistake that we started mocking them. PHPSpec does not force using mocks, especially not when we don't really mock behaviour of HTTP messages. So just using an implementation should work IMO.

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

No branches or pull requests

4 participants