#!/bin/bash
# this will save the panel environment selected into the $DEFAULT_PANEL_FILE location
# to be read from the MigrationTestAbstract.php constructor.

PHPUNIT_PANEL_CPANEL=1
PHPUNIT_PANEL_IWORX=2

DEFAULT_PANEL_FILE=/tmp/.phpunit-migration-default-panel

if test -f "$DEFAULT_PANEL_FILE"; then
  PHPUNIT_DEFAULT_PANEL=$(<"${DEFAULT_PANEL_FILE}")
else
    PHPUNIT_DEFAULT_PANEL=$PHPUNIT_PANEL_CPANEL;
    echo "$PHPUNIT_DEFAULT_PANEL" > "$DEFAULT_PANEL_FILE"
fi;

printf "=========================================\n"
printf "Please select panel type to import from:\n"
printf "Cpanel = %s\n" $PHPUNIT_PANEL_CPANEL
printf "Iworx = %s\n" $PHPUNIT_PANEL_IWORX
printf "Please choose a panel [%s]: " "${PHPUNIT_DEFAULT_PANEL}";
read PHPUNIT_PROMPT_PANEL
printf "=========================================\n\n"

if [[ -n "${PHPUNIT_PROMPT_PANEL}" ]]
  then
  if [[ ! $PHPUNIT_PROMPT_PANEL =~ ^[1-2]{1}$ ]]; then
      echo 'Invalid Option';
  else
    echo "${PHPUNIT_PROMPT_PANEL}" > "${DEFAULT_PANEL_FILE}"
  fi
fi

~iworx/bin/php ~iworx/vendor/phpunit/phpunit/phpunit --stderr "$@"
