ZF-Commons / ZfcUser

A generic user registration and authentication module for ZF2. Supports Zend\Db and Doctrine2. (Formerly EdpUser)
BSD 3-Clause "New" or "Revised" License
497 stars 343 forks source link

Idea around the controller tests for improvement I thought worth sharing. #671

Open jeremyquinton opened 7 years ago

jeremyquinton commented 7 years ago

When putting together this issue https://github.com/ZF-Commons/ZfcUser/issues/670 I was looking at the test cases and come up with an idea on how the tests cases could potentially be improved. Just an idea or opinion I'm sharing not trying to be critical :-)

https://github.com/ZF-Commons/ZfcUser/blob/3.x/tests/ZfcUserTest/Controller/UserControllerTest.php#L154

A data provider is used for the test case but potentially break the test out and making each test case explicit will help with maintainability.

For example when validation fails and the user is redirected the test case name could be as follows.

testLoginActionInvalidFormRedirectTrue()

The test takes no arguments and its clear what it does.

Another idea might just be to change the test name. I feel with the current test name is not clear as to what its testing. The current data arguments are (true, false) or (true, true) etc but the test name has the words Valid and False in the name. testLoginActionValidFormRedirectFalse($isValid, $wantRedirect). In the scenario I was looking at testLoginActionValidFormRedirectFalse(false, true) is a little confusing.

The test name could perhaps be a bit more abstract. testLoginActionFormAndRedirect or testLoginActionFormStatusRedirectStatus as the arguments then from the data provider (true, true),(true,false) etc make more sense.

Just an idea feel free to close the issue if you think its not worthwhile.