Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ Added phpunit tests run command to make it easier to integrate with…

… various test suites
  • Loading branch information...
commit e87096acf3c79d2de189e5c9be2c04aff448c1ea 1 parent 19d68ca
@IvanChepurnyi IvanChepurnyi authored
Showing with 67 additions and 4 deletions.
  1. +67 −4 bin/mage-ci
View
71 bin/mage-ci
@@ -16,7 +16,7 @@
# @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
-script_bin=$(readlink -f $0)
+script_bin=$(readlink -f $0 || realpath $0)
script=$(basename $script_bin)
script_dir=$(dirname $script_bin)
action=$1
@@ -71,6 +71,9 @@ ${MAGECIF[4]}$ mage-ci db-dump <directory> <prefix> <version1> ... <versionN> <O
-u <db_user> DB Username
-p <db_pass> DB Password
-s <file_prefix> sql file prefix
+
+${MAGECIF[4]}$ mage-ci phpunit <directory> <OPTIONS> ${MAGECIF[0]}
+ Runs unit tests for all phpunit.xml or phpunit.dist.xml files in <directory> or its subdirectories. <OPTIONS> will be passed directly to phpunit.
"
}
@@ -80,6 +83,65 @@ show_usage ()
exit 1;
}
+run_phpunit ()
+{
+ local test_dir=$1;
+ local phpunit_version=$(phpunit --version)
+
+ # Check existance of phpunit at the system
+ if [ $? -ne 0 ]
+ then
+ echo "${MAGECIF[3]}PHPUnit is not installed on your system, please visit http://phpunit.de/ for installation"
+ exit 1;
+ fi;
+
+ # Check that first parameter is directory
+ if [ ! -d "$test_dir" -a -d tests ]
+ then
+ tests_dir="tests"
+ elif [ ! -d "$test_dir" ]
+ then
+ echo "${MAGECIF[3]}PHPUnit tests directory doesn't exists: $test_dir${MAGECIF[0]}"
+ exit 1
+ else
+ shift; # Correct test dir, so remove it from args list
+ fi
+
+ test_dir=$(readlink -f $test_dir || realpath $test_dir);
+ cd $test_dir
+
+ local exitCode=1
+
+ if [ -f phpunit.xml -o -f phpunit.xml.dist ]
+ then
+ echo "${MAGECIF[2]}Running test in $test_dir...${MAGECIF[0]}"
+ phpunit ${@}
+ check_error_exit
+ exitCode=0
+ else
+ for dir in $test_dir/*
+ do
+ if [ -f "$dir/phpunit.xml" -o -f "$dir/phpunit.xml.dist" ]
+ then
+ cd $dir;
+ echo "${MAGECIF[2]}Running test in $dir...${MAGECIF[0]}"
+ phpunit ${@}
+ check_error_exit
+ exitCode=0
+ fi
+ done
+ fi
+
+ if [ $exitCode -eq 1 ]
+ then
+ echo "${MAGECIF[2]}No tests were found${MAGECIF[0]}"
+ else
+ echo "${MAGECIF[1]}PHPUnit tests run completed${MAGECIF[0]}"
+ fi
+
+ exit $exitCode
+}
+
dump_magento ()
{
local dest_dir=$1; local prefix=$2; shift 2;
@@ -155,7 +217,7 @@ install_multiple_magento ()
fi
done
- while getopts :u:p:f:d:t opt $options
+ while getopts :u:r:p:f:d:t opt $options
do
case $opt in
u) pass_options="$pass_options -u $OPTARG" ;;
@@ -186,14 +248,13 @@ install_multiple_magento ()
}
install_magento ()
-
{
local magento_dir=$1; local version=$2; local db_name=$3; shift 3
local db_create; local db_user="root"; local db_pass=""; local sql_dump_file=""; local include_test_db
local phpunit_local_xml; local opt; local sql_base_url; local db_cred
local download_dir="$(dirname $script_dir)/.tmp";
- while getopts :u:p:f:d:ct opt
+ while getopts :u:r:p:f:d:ct opt
do
case $opt in
u) db_user=$OPTARG ;;
@@ -202,6 +263,7 @@ install_magento ()
c) db_create="1" ;;
t) include_test_db="1" ;;
d) download_dir=$OPTARG ;;
+ r) sql_base_url=$OPTARG ;;
\?) echo "${MAGECIF[3]}Unkown option -$OPTARG${MAGECIF[0]}" >&2; print_usage; exit 1 ;;
:) echo "${MAGECIF[3]}Option -$OPTARG requires an argument.${MAGECIF[0]}" >&2; print_usage; exit 1 ;;
esac
@@ -520,5 +582,6 @@ uninstall-module) uninstall_module "$@" ;;
uninstall) uninstall_magento "$@" ;;
install-multiple) install_multiple_magento "$@" ;;
db-dump) dump_magento "$@" ;;
+phpunit) run_phpunit "$@" ;;
*) show_usage ;;
esac
Please sign in to comment.
Something went wrong with that request. Please try again.