CRUD refers to four basic functions: Create, Read, Update, Delete. Test Driven Development (TDD) is a software development approach where test cases are developed to specify and validate what the code will do.
⚠️ IMPORTANT: insert in the controller method a return response like this: return response()->json([ 'status' => true, 'message' => 'User Created Successfully', ], 200); Enter fullscreen mode and now test! public function testCreateUser(){ $response = $this->postJson('/api/users/create', ['name' => 'Sally', 'surname' => 'Willi', 'email' => 's@gmail.com', 'password' => '12345678']); $response->assertStatus(200)->assertJson([ 'message' => 'User Created Successfully', ]); }
Third test - Update User public function testUpdateUser(){ $id = User::all()->first()['id']; $response = $this->put("/api/users/{$id}", ['name' => 'Homer', 'surname' => 'Simpson', 'email' => 'homerS11@gmail.com', 'password' => '12345678']); $response->assertStatus(200)->assertJson([ 'message' => 'User Update Successfully', ]); } if I want to run only this test just run this command: ./vendor/bin/phpunit --filter testUpdateUser tests/Unit/UserControllerTest.php