Skip to content

Commit

Permalink
replace test script with phpunit script and before and after scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gregor-j committed May 29, 2024
1 parent b88412a commit 34c653f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <args>
```

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
Expand Down
3 changes: 3 additions & 0 deletions Test/after_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
# stop mysql service at the end of the tests
service mysql stop
12 changes: 0 additions & 12 deletions Test/test.sh → Test/before_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions Test/phpunit.sh
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 34c653f

Please sign in to comment.