I'm trying to test my post
method in the controller. The method definition is something like :
public function store(Request $request)
{
$article = new Article;
$article->id = $request->input('article_id');
$article->title = $request->input('title');
$article->body = $request->input('body');
return response(["success"], 200);
}
I've created a test which just stores the data and checks if the response is 200. Please also show me how can I make this test better new to testing. But I'm getting 404 error
I don't know what is the error. How can I display the errors what are the setting I need to configure? Test:
public function test_post_new_article(){
$article = factory(Article::class)->make();
$this->call('POST', 'article', [
'_token' => csrf_token(),
'article_id' => 6,
'title'=>"hey",
'body' => "this is a body"
])->assertStatus(200);
}
phpunit error:
There was 1 failure:
1) Tests\Unit\ExampleTest::test_post_new_article
Expected status code 200 but received 404.
Failed asserting that false is true.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire