Laravel test different scenarios

Posted 11 months ago by tiagomatosweb

Hi all,

I am doing testings in Laravel 5.3+. Everything is going well, but there is a particular case that there must be a better/quicker way to create unit test.

  • Lets say I have Project model which has an attribute called status.
  • Status can be draft, in_progress and closed
  • A project belongs to a user who is the owner.
  • The owner can add other users to a project as a participant.
  • The owner only can add users while a project is in draft.

So, my ProjectTest file would have one single method for each of the scenario above? For instance:

owner_can_add_users_to_draft_project(){ ... }
owner_cant_add_users_to_inprogress_project(){ ... }
owner_cant_add_users_closed_project(){ ... }

etc...

Is that you guys usually do or is there any other better approach to avoid repetition?

cheers!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.