@davy_yg You have done what is usually called a happy path test and that is all well and good. However you need to test the things that goes wrong as well.
If you create a blog and you are testing the store method these are some of the things you need to test.
- A valid post is stored in the database
- Only a logged in user can store a post
- The title is required
- The title must be at least five characters
- The title must be unique
- The body is required
- The body must be at least one sentence
- The author is required
- The author must exist in the users table
- The published at date is optional
- The published at must be a date when present
These are just a few examples on what you need to test for just one method.
Here is an example from one of the applications that I develop and it's just the authorizations to see that all the routes has the correct middleware.
<?php
namespace Tests\Feature\Http;
use Tests\TestCase;
class AuthorizationTest extends TestCase
{
public function protectedRoutesProvider()
{
return [
'Artists: a guest is not authorized to visit the create page' => ['get', '/artists/create'],
'Artists: a guest is not authorized to visit the edit page' => ['get', '/artists/1/edit'],
'Artists: a guest is not authorized to visit the store page' => ['post', '/artists'],
'Artists: a guest is not authorized to visit the update page' => ['put', '/artists/1'],
'Artists: a guest is not authorized to visit the delete page' => ['delete', '/artists/1'],
'Authors: a guest is not authorized to visit the create page' => ['get', '/authors/create'],
'Authors: a guest is not authorized to visit the edit page' => ['get', '/authors/1/edit'],
'Authors: a guest is not authorized to visit the store page' => ['post', '/authors'],
'Authors: a guest is not authorized to visit the update page' => ['put', '/authors/1'],
'Authors: a guest is not authorized to visit the delete page' => ['delete', '/authors/1'],
'Books: a guest is not authorized to visit the create page' => ['get', '/books/create'],
'Books: a guest is not authorized to visit the edit page' => ['get', '/books/1/edit'],
'Books: a guest is not authorized to visit the store page' => ['post', '/books'],
'Books: a guest is not authorized to visit the update page' => ['put', '/books/1'],
'Books: a guest is not authorized to visit the delete page' => ['delete', '/books/1'],
'Formats: a guest is not authorized to visit the create page' => ['get', '/formats/create'],
'Formats: a guest is not authorized to visit the edit page' => ['get', '/formats/1/edit'],
'Formats: a guest is not authorized to visit the store page' => ['post', '/formats'],
'Formats: a guest is not authorized to visit the update page' => ['put', '/formats/1'],
'Formats: a guest is not authorized to visit the delete page' => ['delete', '/formats/1'],
'Genres: a guest is not authorized to visit the create page' => ['get', '/genres/create'],
'Genres: a guest is not authorized to visit the edit page' => ['get', '/genres/1/edit'],
'Genres: a guest is not authorized to visit the store page' => ['post', '/genres'],
'Genres: a guest is not authorized to visit the update page' => ['put', '/genres/1'],
'Genres: a guest is not authorized to visit the delete page' => ['delete', '/genres/1'],
'Records: a guest is not authorized to visit the create page' => ['get', '/records/create'],
'Records: a guest is not authorized to visit the edit page' => ['get', '/records/1/edit'],
'Records: a guest is not authorized to visit the store page' => ['post', '/records'],
'Records: a guest is not authorized to visit the update page' => ['put', '/records/1'],
'Records: a guest is not authorized to visit the delete page' => ['delete', '/records/1'],
'Tracks: a guest is not authorized to visit the create page' => ['get', '/tracks/create'],
'Tracks: a guest is not authorized to visit the edit page' => ['get', '/tracks/1/edit'],
'Tracks: a guest is not authorized to visit the store page' => ['post', '/tracks'],
'Tracks: a guest is not authorized to visit the update page' => ['put', '/tracks/1'],
'Trackss: a guest is not authorized to visit the delete page' => ['delete', '/tracks/1'],
'BookCollection: a guest is not authorized to visit the store page' => ['post', '/bookcollections'],
'BookCollection: a guest is not authorized to visit the delete page' => ['delete', '/bookcollections/1'],
'BookRead: a guest is not authorized to visit the store page' => ['post', '/books/read'],
'BookRead: a guest is not authorized to visit the delete page' => ['delete', '/books/read/1'],
'UserPages: a guest is not authorized to visit the dashboard (home) page' => ['get', '/home']
];
}
/**
* @test
* @dataProvider protectedRoutesProvider
* @param $method
* @param $route
*/
public function guests_are_redirected_to_login($method, $route)
{
$response = $this->$method($route);
$response->assertLocation('/login');
}
}