Skip to content

Instantly share code, notes, and snippets.

@devmsh
Created February 10, 2020 08:06
Show Gist options
  • Select an option

  • Save devmsh/d9622dca2d700697ce8dabc2c9b1556e to your computer and use it in GitHub Desktop.

Select an option

Save devmsh/d9622dca2d700697ce8dabc2c9b1556e to your computer and use it in GitHub Desktop.
Write better Laravel tests
<?php
// Option 1, write a simple comment
public function test_users_can_get_their_categories_list()
{
factory(Category::class, 5)->create();
// once the user created, we will have a copy of the default categories
$user = factory(User::class)->create();
// ...
}
// Option 2, use the test dependancy feature that PHPUnit provide.
/**
* @depends test_user_have_a_copy_of_the_default_categories
*/
public function test_users_can_get_their_categories_list()
{
factory(Category::class, 5)->create();
$user = factory(User::class)->create();
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment