Hi everybody, I just started studyng the fabulous world of automated testing. Main concepts seems pretty clear to me, but I still have some doubts on how to apply them to a Laravel-based application (I'm currently using Laravel 5.4), because I read opposite opinions and suggestions about it in the last week.
I have a new service which will be launching in a few months and my current task is to write tests to make it stable, fixing possible bugs on-the-fly. My first idea was to test controllers in every possible situation of input data in order to make it stable even if underlying implementation changes, but I'm pretty sure those are more feature tests than unit tests and that's actually too much work to be the right idea. Many people online suggest to avoid testing controllers at all because they shall hold very little logic, which is true but that "little logic" must tested anyway, in my opinion.
Insert now FormRequests and we keep adding up problems: many say they must not be tested (like controllers) because the rules are already tested by their own. I understand that point of view but the composition of the rules is, in fact, part of the application logic, so again it looks to me that they must be tested to avoid developers to alter validation behaviour introducing possible bugs.
Maybe it's all about the fact that they are tightly bounded with controllers methods and are used only one time in all the codebase without actually changing any data, but even knowing this I'm not really sure about how to behave: shall I test only the "best case" (all rules pass, all alterations took place) and "worst case" (all rules break, no alteration took place, all expected errors are returned)? Or shall I test only the "not trivial" scenarios?
On top of this, Authorization Policies jumps in. Unlike FormRequests, they can be "reused" (more that one controller method can be bound to a single policy rule).
After doing some tests, my idea on how to proceed is this:
Is this a good workflow? Is there a de-facto standard out there that I missed or is testing environment in laravel really this caotic? Of course from now on I'll follow TDD, my problem is just to catch up with the current codebase.
Sign in to participate in this thread!