Owner: Dev Team | Last Updated: 2026-02-21 | Status: Current
Testing requirements and test structure.
| Tool | Version | Purpose |
|---|---|---|
| PHPUnit | 11.x | Unit and Feature tests (PHP) |
| Faker | 1.23+ | Test data generation |
| Mockery | 1.6+ | Dependency mocking |
tests/
├── Feature/ # Integration/Feature tests
│ ├── Auth/ # Authentication tests
│ ├── Booking/ # Booking flow tests
│ └── ...
├── Unit/ # Unit tests
│ ├── Services/ # Service tests
│ ├── Actions/ # Action tests
│ └── ...
└── TestCase.php # Base test class
# All tests
php artisan test
# PHPUnit directly
./vendor/bin/phpunit
# Specific test file
php artisan test --filter=BookingServiceTest
# Specific method
php artisan test --filter=BookingServiceTest::test_create_booking
# With coverage
php artisan test --coverage
File: phpunit.xml
Testing Environment:
# .env.testing
APP_ENV=testing
DB_CONNECTION=mysql
DB_DATABASE=booking_testing
QUEUE_CONNECTION=sync
CACHE_DRIVER=array
class BookingFlowTest extends TestCase
{
use RefreshDatabase;
public function test_user_can_create_booking(): void
{
$user = User::factory()->create(['role' => UserRole::ADMIN->value]);
$experience = Experience::factory()->create();
$response = $this->actingAs($user)
->post('/rest/bookings', [
'experience_id' => $experience->id,
'date' => '2026-03-15',
'time' => '18:00',
]);
$response->assertStatus(201);
$this->assertDatabaseHas('orders', [
'customer_id' => $user->id,
]);
}
}
class BookingServiceTest extends TestCase
{
public function test_calculate_cost_with_coupon(): void
{
$service = app(BookingService::class);
$dto = new BookingCostDTO(
experiences: [...],
couponCode: 'SPRING2026',
);
$cost = $service->getBookingCost($dto);
$this->assertLessThan($cost->subtotal, $cost->total);
$this->assertGreaterThan(0, $cost->discount);
}
}
RefreshDatabase trait for isolation| Date | Author | Change |
|---|---|---|
| 2026-02-21 | Documentation Team | Initial creation |
Prev: Coding Standards | Next: Git Workflow | Up: Contributing