Skip to content

Testing

Where this lives / How to run

  • Repo: Eliinova/the-one-otc-api
  • Test directory: tests/ (Feature: tests/Feature/, Unit: tests/Unit/)
  • Config: phpunit.xml
  • Run all tests: php artisan test
  • Run a single test: php artisan test --filter=LoginControllerTest
  • CI: tests run automatically on push (see .github/workflows/ in the repo)

This section covers the testing setup and practices for the EasyOTC API project.

Test Suite

The project uses PHPUnit for testing with Laravel's testing framework. All tests are located in the tests/ directory.

Running Tests

To run the test suite, use the following command:

bash
php artisan test

Test Results

Here's a screenshot of the current test results:

Test Results

Test Structure

The test suite includes:

  • Feature Tests: Located in tests/Feature/

    • LoginControllerTest.php - Tests for login functionality
    • PasswordResetTest.php - Tests for password reset flow
    • RolePermissionTest.php - Tests for role and permission system
  • Unit Tests: Located in tests/Unit/

    • ExampleTest.php - Basic unit test examples

Test Configuration

The test configuration is defined in phpunit.xml and includes:

  • Database configuration for testing
  • Test environment setup
  • Coverage reporting settings

Writing Tests

When adding new features, ensure you write corresponding tests:

  1. Feature Tests: For testing complete user workflows and API endpoints
  2. Unit Tests: For testing individual methods and classes
  3. Integration Tests: For testing component interactions

Test Database

Tests use a separate test database to avoid affecting development data. The database is automatically migrated and seeded for each test run.

Continuous Integration

Tests are automatically run in CI/CD pipelines to ensure code quality and prevent regressions.