-
Notifications
You must be signed in to change notification settings - Fork 123
Use Prophecy for mocking in "Api" class tests #114
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
Use Prophecy for mocking in "Api" class tests #114
Conversation
|
@jpastoor , ready for review. |
| * | ||
| * @var AuthenticationInterface | ||
| */ | ||
| public function testSetEndpointTrailingSlash() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is replaced by testSetendpoint with data provider usage for cases, when trailing slash is present or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah saw it, tried to remove the comment but you were too fast ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Agree on the change to mock the ClientInterface instead of Api::api. No fan of the change from phpunit to prophesy with the passive aggressive title suggesting that this is THE way to do stuff like this. With extracting the expectClientCall you add a layer of indirection, and the assertFalses on the outputs suggest that is a meaningful route to test but we don't do anything with that state. |
|
(OK for you to merge this one though since above is not important for me enough to be blocking or anything, just wanted to let you know the few things that crossed my mind :) |
My apologies. I've renamed the PR. Actually
This is because of default parameter values. When specifying expectation you don't have any auto-complete based on parameters of mocked method. Since mocked method have ~6 parameters, that must be specified in each expectation and in most cases we only provide 3 of them, then extracting in separate method reduces chances of getting things wrong, when writing unit tests. Also, at least for me, having nice
This tests, that return value of method stays as it is currently. Currently API calls, that are just successful, but doesn't return anything useful just return |
Problems solved:
updateVersionandreleaseVersionmethods were saying that they returnResult, but they never dofindVersionByNamemethod was saying that it returns VersionId, but it actually returns all version fieldsApiclass were mockingApiclass partially and that is considered as bad practice (changed to mock client class instead)ApiclassP.S.
My apologies for 3 places, where PhpStorm removed trailing whitespaces. Not sure if it's worth redoing PR to exclude them.