diff --git a/README.md b/README.md index d3e39b1..27074e2 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,25 @@ In order to generate GET forms add `'type' => 'GET'` to the `filterForm()` or `b ## Testing +To run PHPUnit tests: + +```shell +Test/phpunit.sh +``` + +Execute shell for manual testing + ```shell -docker pull devkba/cake2-app-template:staging; +docker pull devkba/cake2-app-template:staging docker run \ --rm \ + --init \ -it \ -v "$(pwd)":/cakephp-filter-plugin \ -e DEBUG=0 \ - devkba/cake2-app-template:staging /cakephp-filter-plugin/Test/test.sh + -e BEFORE_SCRIPT="/cakephp-filter-plugin/Test/before_script.sh" \ + -e AFTER_SCRIPT="/cakephp-filter-plugin/Test/after_script.sh" \ + devkba/cake2-app-template:staging ``` ## Contributing diff --git a/Test/after_script.sh b/Test/after_script.sh new file mode 100755 index 0000000..3c60c71 --- /dev/null +++ b/Test/after_script.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +# stop mysql service at the end of the tests +service mysql stop diff --git a/Test/test.sh b/Test/before_script.sh similarity index 69% rename from Test/test.sh rename to Test/before_script.sh index 00da225..a92cd29 100755 --- a/Test/test.sh +++ b/Test/before_script.sh @@ -9,15 +9,3 @@ composer config repositories.cakephp-filter-plugin '{"type": "path", "url": "/ca composer config repo.packagist false # require the current dev version of the filter plugin composer require --prefer-source kba-team/cakephp-filter-plugin:@dev -# Either use the test case from the parameter, or run all tests -if [ -n "${1}" ]; then - # call PHPUnit and remember return code - vendor/bin/phpunit ${*} - E=$? -else - (>&2 echo "ERROR: Missing test case!") -fi -# stop mysql service at the end of the tests -service mysql stop -# exit with the return code of phpunit -exit $E diff --git a/Test/phpunit.sh b/Test/phpunit.sh new file mode 100755 index 0000000..cc7cb3a --- /dev/null +++ b/Test/phpunit.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# the docker image to use for phpunit testing +DOCKER_IMAGE="devkba/cake2-app-template:staging" +# the path to prepend to the test case +TEST_PREFIX="Plugin/Filter/" +# compile PHPUnit parameters +PARAMS="" +for arg in "$@"; do + # add prefix in case an argument is a path to a test + if [[ "${arg}" == *Test.php ]]; then + arg="${TEST_PREFIX}${arg}" + fi + # in case this is the first argument, don't add $IFS + if [ "${PARAMS}" == "" ]; then + PARAMS="${arg}" + else + PARAMS="${PARAMS}${IFS}${arg}" + fi +done +# pull latest docker image +docker pull "${DOCKER_IMAGE}" || exit $? +# run actual PHPUnit inside docker container +docker run \ + --rm \ + --init \ + -it \ + -v "$(pwd)":/cakephp-filter-plugin \ + -e DEBUG=0 \ + -e BEFORE_SCRIPT="/cakephp-filter-plugin/Test/before_script.sh" \ + -e AFTER_SCRIPT="/cakephp-filter-plugin/Test/after_script.sh" \ + "${DOCKER_IMAGE}" vendor/bin/phpunit ${PARAMS}