I am using Token based operations. The request for the Edit operation in Project works well in Postman.
public function update(Request $request, $id)
{
$project = Project::find($id);
$project->project_name = request('project_name');
$project->project_description = request('project_description');
$project->save();
return response()->json([
'message' => "Project Updated Successfully",
'updatedId' => $project->id
], 200);
}
But in Unit Testing Not getting Proper Responses
public function testBasicExample()
{
$response = $this->withHeaders([
'Accept' => 'application/json',
'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOi......'
])->json('POST', '/api/updateProject/1',
['project_name' => 'Sally'],
['project_description' => 'testing the api']
);
$response->assertStatus(200);
$response->assertJson(['status' => true]);
}
Error Shows
PS D:\XMAPP\htdocs\minidmsapi> ./vendor/bin/phpunit
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.
..F. 4 / 4 (100%)
Time: 597 ms, Memory: 18.00 MB
There was 1 failure:
1) Modules\Projects\Tests\Unit\ProjectTest::testBasicExample
Expected status code 200 but received 500.
Failed asserting that false is true.
D:\XMAPP\htdocs\minidmsapi\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:166
D:\XMAPP\htdocs\minidmsapi\Modules\Projects\Tests\Unit\ProjectTest.php:35
FAILURES!
Tests: 4, Assertions: 4, Failures: 1.
Why Unit Testing having Error Response 500 and some times its 401 ?
Kindly anyone, please explain to me What is the actual error in unit testing and solution for that.
Aucun commentaire:
Enregistrer un commentaire