This test could fall well under both unit and feature testing but I wrote it as a part of a group of tests on three Laravel verbs ie: create, read and update.
There are plenty of ideas out there on how to perform tests on get() and post() requests in Laravel but I have hardly seen any on put requests under the Phpunit framework. This is how I did mine:
public function test_user_can_edit_object() { // Import user from the User Class
$user = User::first(); // Get object from preferred class
$object = Object::first(); $response = $this->actingAs($user)
->put('/put-object-url/'.$object->id, [
'object_id' => 'USER-18980042',
'user_name' => 'Joan Akello',
'status_id' => 1
]);
$response->assertRedirect('objects/list');}
The function gets an authorised user using the actingAs() method to perform editing on an object on the put request url specified in the web.php file. The confirmation that the object was edited is then validated by asserting that a redirect indeed happens after editing the object.