Skip to content

Testing Guide

Overview

Wedissimo uses Pest v4 for testing with a target of 80% code coverage. All tests are written in a descriptive, readable style that documents functionality.

Running Tests

Basic Commands

bash
# All tests
docker exec wedissimo-api vendor/bin/pest

# Specific file
docker exec wedissimo-api vendor/bin/pest tests/Feature/UserTest.php

# Module tests
docker exec wedissimo-api vendor/bin/pest modules/Vendor/Tests/

# With filter
docker exec wedissimo-api vendor/bin/pest --filter="user can login"

# Parallel execution
docker exec wedissimo-api vendor/bin/pest --parallel

Coverage Reports

bash
# Generate HTML coverage report
docker exec wedissimo-api composer run coverage-html

# View report at: tests/coverage/index.html

Test Structure

tests/
├── Feature/           # HTTP requests, DB interactions
├── Unit/              # Isolated logic, services
└── Pest.php          # Shared configuration

modules/YourModule/Tests/
├── Feature/          # Module integration tests
└── Unit/             # Module unit tests

Writing Tests

Feature Tests

php
test('authenticated user can view profile', function () {
    $user = createUser();

    $response = $this->actingAs($user)
        ->getJson('/api/v1/users/me');

    $response->assertStatus(200)
        ->assertJsonStructure([
            'data' => ['id', 'name', 'email']
        ]);
});

Unit Tests

php
test('service processes data correctly', function () {
    $service = app(YourService::class);

    $result = $service->process(['key' => 'value']);

    expect($result)->toBeInstanceOf(YourModel::class)
        ->and($result->key)->toBe('value');
});

Test Helpers

Available in tests/Pest.php:

php
// Create users with roles
$user = createUser();
$admin = createAdminUser();
$superAdmin = createSuperAdmin();

// Assert authentication
$response->toBeAuthenticated();

// Assert pagination
$response->assertResourcePagination();

Best Practices

  1. Descriptive names: test('user can create listing with valid data')
  2. One assertion focus: Test one thing per test
  3. Arrange-Act-Assert: Clear test structure
  4. Database refresh: Use RefreshDatabase trait
  5. Factory usage: Create test data with factories

See CLAUDE.md for more testing guidelines.

Wedissimo API Documentation