alias test8mysqlUnit='rm -fr /var/www/html/rconfig8/.phpunit.*.checksum && rm -fr /var/www/html/rconfig8/tests/vega8_test_snapshot.sql && cd /var/www/html/rconfig8 && php artisan test --profile --configuration=phpunit.mysql.xml '
alias test8pgsqlUnit='rm -fr /var/www/html/rconfig8/.phpunit.*.checksum && rm -fr /var/www/html/rconfig8/tests/vega8_test_snapshot.sql && cd /var/www/html/rconfig8 && php artisan test --profile --configuration=phpunit.pgsql.xml'

#!/bin/bash
# run-remote-tests-local-mail.sh

REMOTE_HOST="vega.rconfig.com"
LOCAL_REPORT_DIR="$HOME/test-reports"
TODAY_FILE="$LOCAL_REPORT_DIR/unit-tests-$(date +%F).log"
TO="stephen@rconfig.com"
FROM="root@$(hostname)"
SUBJECT="Unit Test Results - $(date)"

# Ensure local report directory exists
mkdir -p "$LOCAL_REPORT_DIR"

REMOTE_CMD='
echo "=== START RUN: $(date) ==="

# Cleanup before MySQL
rm -f /var/www/html/rconfig8/.phpunit.*.checksum 2>/dev/null
rm -f /var/www/html/rconfig8/tests/vega8_test_snapshot.sql 2>/dev/null

echo "--- MySQL Test START: $(date) ---"
cd /var/www/html/rconfig8
php artisan test --profile --configuration=phpunit.mysql.xml --testsuite=Unit
echo "--- MySQL Test END: $(date) ---"

# Cleanup before PostgreSQL
rm -f /var/www/html/rconfig8/.phpunit.*.checksum 2>/dev/null
rm -f /var/www/html/rconfig8/tests/vega8_test_snapshot.sql 2>/dev/null

echo "--- PostgreSQL Test START: $(date) ---"
cd /var/www/html/rconfig8
php artisan test --profile --configuration=phpunit.pgsql.xml --testsuite=Unit
echo "--- PostgreSQL Test END: $(date) ---"

# Final cleanup
rm -f /var/www/html/rconfig8/.phpunit.*.checksum 2>/dev/null
rm -f /var/www/html/rconfig8/tests/vega8_test_snapshot.sql 2>/dev/null

echo "=== END RUN: $(date) ==="
'

# Append timestamp & run remote command, storing output locally
{
    echo "==============================="
    echo "Run at: $(date)"
    echo "==============================="
    ssh "$REMOTE_HOST" "$REMOTE_CMD"
    echo
} >> "$TODAY_FILE"

# Send the full file via sendmail
(echo -e "To: $TO\nSubject: $SUBJECT\nFrom: $FROM\n"; cat "$TODAY_FILE") | sendmail "$TO"
