#!/bin/sh
# Reload the schema + sample data into a scratch database, then run the service tests.
# Usage: DB_USER=root sh tests/run.sh   (needs the mysql client; schema path as $1)
SCHEMA=${1:-/tmp/fashion_ecommerce_schema.sql}
DIR=$(cd "$(dirname "$0")/.." && pwd)
mysql -u"${DB_ADMIN_USER:-root}" -e "DROP DATABASE IF EXISTS fashion_shop_test; CREATE DATABASE fashion_shop_test CHARACTER SET utf8mb4" || exit 1
sed "s/fashion_shop/fashion_shop_test/g" "$SCHEMA" | mysql -u"${DB_ADMIN_USER:-root}" fashion_shop_test || exit 1
sed "s/USE fashion_shop;/USE fashion_shop_test;/" "$DIR/database/everop_store_seed.sql" | mysql -u"${DB_ADMIN_USER:-root}" fashion_shop_test || exit 1
DB_NAME=fashion_shop_test php "$DIR/tests/services_test.php"
