|
13 | 13 | # Exit 0 iff every BLOCKING check passes (npm audit + the soft-delete grep are |
14 | 14 | # advisory, mirroring the CI's continue-on-error / warn-only behaviour). |
15 | 15 | # |
16 | | -# DB: the standalone unit tests need MySQL. Defaults below match the canonical |
17 | | -# local dev DB (MySQL on the Homebrew socket). Override via the E2E_DB_* env. |
| 16 | +# DB: the standalone unit tests need MySQL. Credentials come from the gitignored |
| 17 | +# .env (same source the .unit.php tests use) — NEVER hardcode a password here. |
| 18 | +# Override any of them via the environment before invoking the script. |
18 | 19 |
|
19 | 20 | set -uo pipefail |
20 | 21 | cd "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" || exit 2 |
21 | 22 |
|
22 | | -export E2E_DB_SOCKET="${E2E_DB_SOCKET:-/opt/homebrew/var/mysql/mysql.sock}" |
| 23 | +# Load DB_* from .env (gitignored) unless already set in the environment. |
| 24 | +if [ -f .env ]; then |
| 25 | + while IFS='=' read -r k v; do |
| 26 | + v="${v%\"}"; v="${v#\"}"; v="${v%\'}"; v="${v#\'}" |
| 27 | + [ -n "${!k:-}" ] || export "$k=$v" |
| 28 | + done < <(grep -E '^(DB_HOST|DB_PORT|DB_USER|DB_PASS|DB_PASSWORD|DB_NAME|DB_SOCKET)=' .env 2>/dev/null) |
| 29 | +fi |
| 30 | +# Only non-secret fallbacks (socket path/host/port) — no password default. |
| 31 | +export E2E_DB_SOCKET="${E2E_DB_SOCKET:-${DB_SOCKET:-/opt/homebrew/var/mysql/mysql.sock}}" |
23 | 32 | export DB_HOST="${DB_HOST:-127.0.0.1}" |
24 | 33 | export DB_PORT="${DB_PORT:-3306}" |
25 | | -export DB_USER="${DB_USER:-fabiodal_biblioteca_user}" |
26 | | -export DB_PASSWORD="${DB_PASSWORD:-Zd10)uwziWlK}" |
27 | | -export DB_NAME="${DB_NAME:-fabiodal_biblioteca}" |
28 | | -# The .unit.php tests read DB_USER/DB_PASS/DB_NAME (and E2E_DB_*). |
29 | | -export DB_PASS="${DB_PASS:-$DB_PASSWORD}" |
| 34 | +export DB_PASS="${DB_PASS:-${DB_PASSWORD:-}}" |
30 | 35 |
|
31 | 36 | PHPSTAN="${PHPSTAN:-$HOME/.composer/vendor/bin/phpstan}" |
32 | 37 | [ -x "$PHPSTAN" ] || PHPSTAN="phpstan" |
|
0 commit comments