I am building an application using Laravel, a bug was found, so, I would to know where to put the hotfix test. I have this tests structure:
Tests -> Feature -> Http -> MyControllerTest.php, more files…
Tests -> Unit-> Models-> MyModelTest.php, more files…
I know that I have to write a test for that bug, but I don’t know where to put it, it is related to the authorization using tokens, some routes are not being protected, and it looks like I need to write a custom middleware I think, I am not sure yet, I was thinking to put it in a differente file in Feature/Http folder, something like HotFixTest.php?, or maybe in the same MyControllerTest.php file, I don’t know where? what can I do? thanks.
2
Answers
If you are going to fix that given BUG simply implementing a middleware, you can "cover" that implementation by simply written a UnitTest.
I have no context, but given a new file at
/app/Http/Middleware/TokenGuardMiddleare
you can create the test/test/unit/Http/Middleware/TokenGuardMiddleare
What I do is, depending on what you have to do to fix the bug, I would:
Tests -> Feature -> Http -> MyControllerTest.php
it should beTests -> Feature -> Htpp -> UserRegistration
(let’s say thatMyController
allows a user to register)./user/123
and the bug is that it has no authntication, you have to create a new test in there, that will do aGET
or whatever to/user/123
and you should expect a401
or403
, but another normal test that if you do send the token, you get a200
or whatever is successful for you. See that it is TIED to the feature. You have to do this for each route, do not unit test the middleware