#!/bin/bash

set -e

export APP_ENV=test

SCRIPT_DIR=$(dirname "$(realpath "$0")")
pushd "${SCRIPT_DIR}"/../

SKIP_DB=false
FIX_FEATURES=false

for arg in "$@"; do
    case $arg in
        --skip-db)
            SKIP_DB=true
            ;;
        --fix-features)
            FIX_FEATURES=true
            ;;
    esac
done

if [ "$SKIP_DB" = false ]; then
    bin/prepare-test-db
fi

# Access control tests
SYMFONY_PHPUNIT_VERSION=9.5.3 vendor/bin/simple-phpunit

if [ "$FIX_FEATURES" = true ]; then
    vendor/bin/behat -f fixer
else
    vendor/bin/behat -f progress -o std -f junit -o results
fi
popd
