Elentra API
  • Introduction
  • Developers
    • Getting Started
    • Quickstart Guide
      • Set up Repositories
      • Validate the setup
      • Exploring the API
      • Creating a new Module
      • Setup Routing
      • Introduction to Postman
      • Create a Controller
      • Using Eloquent Models
      • Input Validation
      • API Resource Authorization
  • Elentra API Standards
    • HTTP Methods & Status Codes
    • Routing & Parameters
      • Example Routing Patterns with HTTP Method
        • /courses/{course}/contacts
        • /courses/{course}/contacts?type={contact_type}
        • /courses/{course}/contacts/{contact}
        • /courses/{course}/syllabus
      • Common Mistakes
        • [GET] /admissions/file-review/file/rubric-score/{cycle_id}/{pool_id}/{subpool_id}
        • [DELETE] /notices/1,2,3
        • [GET] /cbe/curriculum/framework/{framework_id}/hierarchy-by-depth
        • [GET] /admissions/file-review/file/rubric-score/delete/{id}
        • [GET] /portfolio/entries/{entry_id}/get-file
        • [POST] /cbe/curriculum/updateframework
  • Automated Testing
    • Getting Started
      • Setting up a testing environment
      • Running Automated Tests
    • Seed Data
      • Folder Structure
      • Creating Seed Data
    • Functional Tests
      • Creating a Functional Test File
      • Testing HTTP Verbs
        • Creating an HTTP Test
        • GET Requests
        • POST / PUT / DELETE Requests
        • GraphQL Requests
      • Asserting API Response
      • Annotations
    • Code Style Linting
Powered by GitBook
On this page
  1. Automated Testing
  2. Functional Tests
  3. Testing HTTP Verbs

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

PreviousTesting HTTP VerbsNextGET Requests

Last updated 2 years ago