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

Unit tests for User #10

Open
wants to merge 8 commits into
base: 8.x-2.x
Choose a base branch
from
Open

Unit tests for User #10

wants to merge 8 commits into from

Conversation

agr0chal
Copy link
Member

@agr0chal agr0chal commented Dec 20, 2019

I've created unit tests for UserAuthenticator.php and SocialAuthUser.php

@agr0chal
Copy link
Member Author

agr0chal commented Jan 4, 2020

I've refactored to set and get response using functions, because
For example:
Function A was using $this->response = $this->getPostLoginRedirection; return;
and then Function B was calling function A and returning $this->response.
Which was causing problems while testing, because the easiest and clearest way is just mock function B, and make a callback to set response, $this->response is protected variable so the best option was creating a function setResponse.

* The tested Social Auth UserAuthenticator.
*
* @var \Drupal\social_auth\User\UserAuthenticator
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget about |\PHPUnit_Framework_MockObject_MockObject

Copy link
Contributor

@gvso gvso Jan 10, 2020

Choose a reason for hiding this comment

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

You have to repeat the process with all mocked objects. The point is that, for instance, my text editor highlights things as an error because you call the method expects which is only defined in the \PHPUnit_Framework_MockObject_MockObject class

* The tested Social Auth UserAuthenticator.
*
* @var \Drupal\social_auth\User\UserAuthenticator
*/
Copy link
Contributor

@gvso gvso Jan 10, 2020

Choose a reason for hiding this comment

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

You have to repeat the process with all mocked objects. The point is that, for instance, my text editor highlights things as an error because you call the method expects which is only defined in the \PHPUnit_Framework_MockObject_MockObject class

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.

2 participants