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 --parallelCoverage Reports
bash
# Generate HTML coverage report
docker exec wedissimo-api composer run coverage-html
# View report at: tests/coverage/index.htmlTest 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 testsWriting 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
- Descriptive names:
test('user can create listing with valid data') - One assertion focus: Test one thing per test
- Arrange-Act-Assert: Clear test structure
- Database refresh: Use
RefreshDatabasetrait - Factory usage: Create test data with factories
See CLAUDE.md for more testing guidelines.