From fb56c6dd310320d4c83e784918d27760336b06fb Mon Sep 17 00:00:00 2001 From: bbakalov Date: Wed, 13 Nov 2024 15:25:54 -0500 Subject: [PATCH] Add bin/test helper scripts to execute unit tests (#1157) Co-authored-by: Mark Shust Co-authored-by: Michael Lehmkuhl Co-authored-by: Jenyamba Co-authored-by: Tu Van Co-authored-by: Cid Lopes --- README.md | 3 +++ compose/bin/test/unit | 24 ++++++++++++++++++++++++ compose/bin/test/unit-coverage | 24 ++++++++++++++++++++++++ compose/bin/test/unit-xdebug | 24 ++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100755 compose/bin/test/unit create mode 100755 compose/bin/test/unit-coverage create mode 100755 compose/bin/test/unit-xdebug diff --git a/README.md b/README.md index b951e15dd..f93f95bd9 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,9 @@ It is recommended to keep your root docker config files in one repository, and y - `bin/status`: Check the container status. - `bin/stop`: Stop all project containers. - `bin/stopall`: Stop all docker running containers +- `bin/test/unit`: Run unit tests for a specific path. Ex. `bin/test/unit my-dir` +- `bin/test/unit-coverage`: Generate unit tests coverage reports, saved to the folder `dev/tests/unit/report`. Ex. `bin/test/unit-coverage my-dir` +- `bin/test/unit-xdebug`: Run unit tests with Xdebug. Ex. `bin/test/unit-xdebug my-dir` - `bin/update`: Update your project to the most recent version of `docker-magento`. - `bin/xdebug`: Disable or enable Xdebug. Accepts argument `disable`, `enable`, or `status`. Ex. `bin/xdebug enable` diff --git a/compose/bin/test/unit b/compose/bin/test/unit new file mode 100755 index 000000000..3eea02382 --- /dev/null +++ b/compose/bin/test/unit @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +display_help() { + echo -e "Description: + Run unit tests + +Usage: + bin/test/unit + +Arguments: + Specify a path to your test or folder with tests Ex: bin/test/unit app/code/Vendor/Module + +Options: + -h, --help Display help message" +} + + +if [[ $1 == "-h" || $1 == "--help" ]]; then + display_help +elif [[ -z $1 ]]; then + echo -e "Please specify a path to your test or folder with tests (ex. app/code/Vendor/Module)" +else + bin/php vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist /var/www/html/"$1" +fi \ No newline at end of file diff --git a/compose/bin/test/unit-coverage b/compose/bin/test/unit-coverage new file mode 100755 index 000000000..544d581f3 --- /dev/null +++ b/compose/bin/test/unit-coverage @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +display_help() { + echo -e "Description: + Generate unit tests coverage report in folder: dev/tests/unit/report + +Usage: + bin/test/unit-coverage + +Arguments: + Specify a path to your test or folder with tests Ex: bin/test/unit-coverage app/code/Vendor/Module + +Options: + -h, --help Display help message" +} + +if [[ $1 == "-h" || $1 == "--help" ]]; then + display_help +elif [[ -z $1 ]]; then + echo -e "Please specify a path to your test or folder with tests (ex. app/code/Vendor/Module)" +else + bin/php -d xdebug.mode=coverage vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist --coverage-html ./dev/tests/unit/report /var/www/html/"$1" + echo -e "Report path: dev/tests/unit/report" +fi \ No newline at end of file diff --git a/compose/bin/test/unit-xdebug b/compose/bin/test/unit-xdebug new file mode 100755 index 000000000..873ec9620 --- /dev/null +++ b/compose/bin/test/unit-xdebug @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +display_help() { + echo -e "Description: + Run unit tests with xdebug (you need to turn on xdebug in IDE as usual) + +Usage: + bin/test/unit-xdebug + +Arguments: + Specify a path to your test or folder with tests Ex: bin/test/unit-xdebug app/code/Vendor/Module + +Options: + -h, --help Display help message" +} + + +if [[ $1 == "-h" || $1 == "--help" ]]; then + display_help +elif [[ -z $1 ]]; then + echo -e "Please specify a path to your test or folder with tests (ex. app/code/Vendor/Module)" +else + bin/php -d xdebug.start_with_request=yes vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist /var/www/html/"$1" +fi \ No newline at end of file