# Testing and Production Quality Gates

## Fast local suite

```bash
composer install
php artisan test
vendor/bin/pint --test
vendor/bin/phpstan analyse --memory-limit=1G
php artisan clinic:check-openapi
```

The default PHPUnit configuration uses in-memory SQLite for feature/unit tests.

## MySQL concurrency suite

True row-lock concurrency behavior must be tested with MySQL/MariaDB and the PHP `pcntl` extension:

```bash
mysql -uroot -p -e 'CREATE DATABASE smart_clinic_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'
vendor/bin/phpunit -c phpunit.mysql.xml
```

The concurrency suite forks separate processes and verifies:

- two simultaneous automatic token allocations never return the same token;
- two simultaneous bookings of the same doctor/location slot result in one successful booking and one `SLOT_NOT_AVAILABLE` conflict.

## Fresh database gate

Before a release:

```bash
php artisan migrate:fresh --force
php artisan db:seed --class=EssentialSeeder --force
```

Never run `ClinicDemoSeeder` against a production database.

## CI

`.github/workflows/ci.yml` runs Composer validation, Pint, Larastan/PHPStan, OpenAPI route coverage, the SQLite suite, a fresh MySQL migration/essential seed, and the MySQL concurrency suite.

## Environment/provider acceptance

Code tests cannot prove external provider or infrastructure readiness. Before production sign-off, separately verify HTTPS, MySQL backups/restores, Redis (when selected), queue-worker supervision, scheduler execution, SMTP, WhatsApp templates, Expo/FCM/APNs credentials, alerting, and the production `APP_DEBUG=false` configuration.
