Creating an HTTP Test

When creating a test function, use the @testannotation. This will execute when the functional tests run. The test method should contain a description of what the test is attempting to verify and should be in snake case to make it more readable in the terminal.

Function Test Naming Convention:

Tests should be in snake case for readability when the test's name is rendered to the CI. The test name should follow this format:

[module_name]_[controller_name]_[http_method]_[controller method]_returns_[status code]

For example, testing the RotationScheduleController with the method index should be called: clinical_rotations_get_index_returns_200

In instances where the controller has the same name as the module, then the word controller can be used instead of the controller name: clinical_controller_get_index_returns_200

This is to avoid `Clinical` twice in the name

Example:

/**
 * Test that the GET /events returns 200
 *
 * @test
 * @return void
 */
public function events_get_method_index_returns_200(): void
{
    // ...
}

The method's name has all the information to determine what and how it’s being tested.

To call an endpoint, we need to state what user is requesting the call before we send the request.

/**
 * Test that the GET /events returns 200
 *
 * @test
 * @return void
 */
public function events_get_method_index_returns_200(): void
{
    $this->actingAs(User::find(2));
}

If the acted-on user has an ID of 1 (default administrator), then $this->actingAsAdmin() can be used instead

Last updated