|
| 1 | +# Testing Steps |
| 2 | + |
| 3 | +This document outlines how to set up, run tests, and use code quality tools for the Utopia Database library. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Docker and Docker Compose installed |
| 8 | +- Composer (optional, for local dependency management) |
| 9 | + |
| 10 | +## 1. Install Dependencies |
| 11 | + |
| 12 | +```bash |
| 13 | +composer install --prefer-dist |
| 14 | +``` |
| 15 | + |
| 16 | +Or using Docker: |
| 17 | + |
| 18 | +```bash |
| 19 | +docker run --rm -v "$(pwd)":/app -w /app composer:latest install --prefer-dist --ignore-platform-reqs |
| 20 | +``` |
| 21 | + |
| 22 | +## 2. Build Docker Images |
| 23 | + |
| 24 | +```bash |
| 25 | +composer build |
| 26 | +``` |
| 27 | + |
| 28 | +Or directly: |
| 29 | + |
| 30 | +```bash |
| 31 | +docker compose build |
| 32 | +``` |
| 33 | + |
| 34 | +## 3. Start Services |
| 35 | + |
| 36 | +Start all database containers and the test environment: |
| 37 | + |
| 38 | +```bash |
| 39 | +composer start |
| 40 | +``` |
| 41 | + |
| 42 | +Or directly: |
| 43 | + |
| 44 | +```bash |
| 45 | +docker compose up -d |
| 46 | +``` |
| 47 | + |
| 48 | +This starts the following services: |
| 49 | + |
| 50 | +| Service | Container Name | Port | Description | |
| 51 | +|-------------------|------------------------|-------|--------------------------| |
| 52 | +| PostgreSQL | utopia-postgres | 8701 | Primary PostgreSQL | |
| 53 | +| PostgreSQL Mirror | utopia-postgres-mirror | 8702 | PostgreSQL replica | |
| 54 | +| MariaDB | utopia-mariadb | 8703 | Primary MariaDB | |
| 55 | +| MariaDB Mirror | utopia-mariadb-mirror | 8704 | MariaDB replica | |
| 56 | +| MySQL | utopia-mysql | 8706 | Primary MySQL | |
| 57 | +| MySQL Mirror | utopia-mysql-mirror | 8707 | MySQL replica | |
| 58 | +| Redis | utopia-redis | 8708 | Primary Redis | |
| 59 | +| Redis Mirror | utopia-redis-mirror | 8709 | Redis replica | |
| 60 | +| MongoDB | utopia-mongo | 9706 | MongoDB with replica set | |
| 61 | +| Adminer | utopia-adminer | 8700 | Database admin UI | |
| 62 | +| Mongo Express | mongo-express | 8083 | MongoDB admin UI | |
| 63 | + |
| 64 | +## 4. Run Tests |
| 65 | + |
| 66 | +Run the full test suite: |
| 67 | + |
| 68 | +```bash |
| 69 | +composer test |
| 70 | +``` |
| 71 | + |
| 72 | +Or directly: |
| 73 | + |
| 74 | +```bash |
| 75 | +docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml |
| 76 | +``` |
| 77 | + |
| 78 | +### Run Specific Tests |
| 79 | + |
| 80 | +Run a specific test file: |
| 81 | + |
| 82 | +```bash |
| 83 | +docker compose exec tests vendor/bin/phpunit --filter DatabaseTest |
| 84 | +``` |
| 85 | + |
| 86 | +Run a specific test method: |
| 87 | + |
| 88 | +```bash |
| 89 | +docker compose exec tests vendor/bin/phpunit --filter testCreateDocument |
| 90 | +``` |
| 91 | + |
| 92 | +## 5. Code Quality Tools |
| 93 | + |
| 94 | +### Linting (Pint - PSR-12) |
| 95 | + |
| 96 | +Check code style: |
| 97 | + |
| 98 | +```bash |
| 99 | +composer lint |
| 100 | +``` |
| 101 | + |
| 102 | +Or directly: |
| 103 | + |
| 104 | +```bash |
| 105 | +docker compose exec tests php -d memory_limit=2G ./vendor/bin/pint --test |
| 106 | +``` |
| 107 | + |
| 108 | +### Format Code |
| 109 | + |
| 110 | +Auto-fix code style issues: |
| 111 | + |
| 112 | +```bash |
| 113 | +composer format |
| 114 | +``` |
| 115 | + |
| 116 | +Or directly: |
| 117 | + |
| 118 | +```bash |
| 119 | +docker compose exec tests php -d memory_limit=2G ./vendor/bin/pint |
| 120 | +``` |
| 121 | + |
| 122 | +### Static Analysis (PHPStan) |
| 123 | + |
| 124 | +Run PHPStan at level 7: |
| 125 | + |
| 126 | +```bash |
| 127 | +composer check |
| 128 | +``` |
| 129 | + |
| 130 | +Or directly: |
| 131 | + |
| 132 | +```bash |
| 133 | +docker compose exec tests ./vendor/bin/phpstan analyse --level 7 src tests --memory-limit 2G |
| 134 | +``` |
| 135 | + |
| 136 | +### Code Coverage |
| 137 | + |
| 138 | +Generate and check code coverage (requires tests to have been run with coverage): |
| 139 | + |
| 140 | +```bash |
| 141 | +composer coverage |
| 142 | +``` |
| 143 | + |
| 144 | +This checks that code coverage is at least 90%. |
| 145 | + |
| 146 | +## 6. Stop Services |
| 147 | + |
| 148 | +```bash |
| 149 | +docker compose down |
| 150 | +``` |
| 151 | + |
| 152 | +To also remove volumes: |
| 153 | + |
| 154 | +```bash |
| 155 | +docker compose down -v |
| 156 | +``` |
| 157 | + |
| 158 | +## Quick Reference |
| 159 | + |
| 160 | +| Command | Description | |
| 161 | +|--------------------|--------------------------------------| |
| 162 | +| `composer build` | Build Docker images | |
| 163 | +| `composer start` | Start all services | |
| 164 | +| `composer test` | Run PHPUnit tests | |
| 165 | +| `composer lint` | Check code style (PSR-12) | |
| 166 | +| `composer format` | Auto-fix code style | |
| 167 | +| `composer check` | Run PHPStan static analysis | |
| 168 | +| `composer coverage`| Check code coverage (min 90%) | |
| 169 | + |
| 170 | +## Database Credentials |
| 171 | + |
| 172 | +### PostgreSQL |
| 173 | +- Host: `postgres` (or `localhost:8701` from host) |
| 174 | +- User: `root` |
| 175 | +- Password: `password` |
| 176 | +- Database: `root` |
| 177 | + |
| 178 | +### MariaDB |
| 179 | +- Host: `mariadb` (or `localhost:8703` from host) |
| 180 | +- User: `root` |
| 181 | +- Password: `password` |
| 182 | + |
| 183 | +### MySQL |
| 184 | +- Host: `mysql` (or `localhost:8706` from host) |
| 185 | +- User: `root` / `user` |
| 186 | +- Password: `password` |
| 187 | +- Database: `default` |
| 188 | + |
| 189 | +### MongoDB |
| 190 | +- Host: `mongo` (or `localhost:9706` from host) |
| 191 | +- User: `root` |
| 192 | +- Password: `password` |
| 193 | +- Database: `utopia_testing` |
| 194 | + |
| 195 | +### Redis |
| 196 | +- Host: `redis` (or `localhost:8708` from host) |
| 197 | +- No authentication required |
| 198 | + |
| 199 | +## Troubleshooting |
| 200 | + |
| 201 | +### Services not healthy |
| 202 | + |
| 203 | +If services fail health checks, check their logs: |
| 204 | + |
| 205 | +```bash |
| 206 | +docker compose logs postgres |
| 207 | +docker compose logs mariadb |
| 208 | +docker compose logs mongo |
| 209 | +``` |
| 210 | + |
| 211 | +### Tests fail to connect |
| 212 | + |
| 213 | +Ensure all services are healthy: |
| 214 | + |
| 215 | +```bash |
| 216 | +docker compose ps |
| 217 | +``` |
| 218 | + |
| 219 | +All services should show `healthy` status. |
| 220 | + |
| 221 | +### Permission issues |
| 222 | + |
| 223 | +If you encounter permission issues with mounted volumes: |
| 224 | + |
| 225 | +```bash |
| 226 | +sudo chown -R $USER:$USER . |
| 227 | +``` |
0 commit comments