-
Notifications
You must be signed in to change notification settings - Fork 2
Unittest #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dikastes
wants to merge
7
commits into
slub:main
Choose a base branch
from
dikastes:unittest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Unittest #5
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
81f36ba
Prepare Unit Testing
7b539c0
Fix typo in test
claussni 625f35b
Update README
claussni 3ee32d0
Add empty argument test
claussni f1e9524
Fix error when parsing empty array
811db5d
Add Function Tests
10d327b
Merge branch 'main' into unittest
dikastes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| /vendor/ | ||
| .vscode | ||
| .Build/ | ||
| .idea/ | ||
| Build/testing-docker/.env | ||
| composer.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,284 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # | ||
| # TYPO3 core test runner based on docker and docker-compose. | ||
| # | ||
|
|
||
| # Function to write a .env file in Build/testing-docker/local | ||
| # This is read by docker-compose and vars defined here are | ||
| # used in Build/testing-docker/local/docker-compose.yml | ||
| setUpDockerComposeDotEnv() { | ||
| # Delete possibly existing local .env file if exists | ||
| [ -e .env ] && rm .env | ||
| # Set up a new .env file for docker-compose | ||
| echo "COMPOSE_PROJECT_NAME=local" >> .env | ||
| # To prevent access rights of files created by the testing, the docker image later | ||
| # runs with the same user that is currently executing the script. docker-compose can't | ||
| # use $UID directly itself since it is a shell variable and not an env variable, so | ||
| # we have to set it explicitly here. | ||
| echo "HOST_UID=`id -u`" >> .env | ||
| # Your local home directory for composer and npm caching | ||
| echo "HOST_HOME=${HOME}" >> .env | ||
| # Your local user | ||
| echo "ROOT_DIR"=${ROOT_DIR} >> .env | ||
| echo "HOST_USER=${USER}" >> .env | ||
| echo "TEST_FILE=${TEST_FILE}" >> .env | ||
| echo "PHP_XDEBUG_ON=${PHP_XDEBUG_ON}" >> .env | ||
| echo "PHP_XDEBUG_PORT=${PHP_XDEBUG_PORT}" >> .env | ||
| echo "PHP_VERSION=${PHP_VERSION}" >> .env | ||
| echo "DOCKER_PHP_IMAGE=${DOCKER_PHP_IMAGE}" >> .env | ||
| echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}" >> .env | ||
| echo "SCRIPT_VERBOSE=${SCRIPT_VERBOSE}" >> .env | ||
| } | ||
|
|
||
| # Load help text into $HELP | ||
| read -r -d '' HELP <<EOF | ||
| publisher_db test runner. Execute unit test suite and some other details. | ||
| Also used by github actions for test execution. | ||
|
|
||
| Usage: $0 [options] [file] | ||
|
|
||
| No arguments: Run all unit tests with PHP 7.2 | ||
|
|
||
| Options: | ||
| -s <...> | ||
| Specifies which test suite to run | ||
| - composerInstall: "composer install" | ||
| - composerInstallMax: "composer update", with no platform.php config. | ||
| - composerInstallMin: "composer update --prefer-lowest", with platform.php set to PHP version x.x.0. | ||
| - composerValidate: "composer validate" | ||
| - lint: PHP linting | ||
| - unit (default): PHP unit tests | ||
| - functional: functional tests | ||
|
|
||
| -d <mariadb|mssql|postgres|sqlite> | ||
| Only with -s functional | ||
| Specifies on which DBMS tests are performed | ||
| - mariadb (default): use mariadb | ||
| - mssql: use mssql microsoft sql server | ||
| - postgres: use postgres | ||
| - sqlite: use sqlite | ||
|
|
||
| -p <7.2|7.3|7.4> | ||
| Specifies the PHP minor version to be used | ||
| - 7.2 (default): use PHP 7.2 | ||
| - 7.3: use PHP 7.3 | ||
|
|
||
| -e "<phpunit options>" | ||
| Only with -s functional|unit | ||
| Additional options to send to phpunit tests. | ||
| For phpunit, options starting with "--" must be added after options starting with "-". | ||
| Example -e "-v --filter canRetrieveValueWithGP" to enable verbose output AND filter tests | ||
| named "canRetrieveValueWithGP" | ||
|
|
||
| -x | ||
| Only with -s unit | ||
| Send information to host instance for test or system under test break points. This is especially | ||
| useful if a local PhpStorm instance is listening on default xdebug port 9000. A different port | ||
| can be selected with -y | ||
|
|
||
| -y <port> | ||
| Send xdebug information to a different port than default 9000 if an IDE like PhpStorm | ||
| is not listening on default port. | ||
|
|
||
| -u | ||
| Update existing typo3gmbh/phpXY:latest docker images. Maintenance call to docker pull latest | ||
| versions of the main php images. The images are updated once in a while and only the youngest | ||
| ones are supported by core testing. Use this if weird test errors occur. Also removes obsolete | ||
| image versions of typo3gmbh/phpXY. | ||
|
|
||
| -v | ||
| Enable verbose script output. Shows variables and docker commands. | ||
|
|
||
| -h | ||
| Show this help. | ||
|
|
||
| Examples: | ||
| # Run unit tests using PHP 7.2 | ||
| ./Build/Scripts/runTests.sh | ||
|
|
||
| # Run unit tests using PHP 7.3 | ||
| ./Build/Scripts/runTests.sh -p 7.3 | ||
| EOF | ||
|
|
||
| # Test if docker-compose exists, else exit out with error | ||
| if ! type "docker-compose" > /dev/null; then | ||
| echo "This script relies on docker and docker-compose. Please install" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Go to the directory this script is located, so everything else is relative | ||
| # to this dir, no matter from where this script is called. | ||
| THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" | ||
| cd "$THIS_SCRIPT_DIR" || exit 1 | ||
|
|
||
| # Go to directory that contains the local docker-compose.yml file | ||
| cd ../testing-docker || exit 1 | ||
|
|
||
| # Option defaults | ||
| ROOT_DIR=`readlink -f ${PWD}/../../` | ||
| TEST_SUITE="unit" | ||
| DBMS="mariadb" | ||
| PHP_VERSION="7.2" | ||
| PHP_XDEBUG_ON=0 | ||
| PHP_XDEBUG_PORT=9000 | ||
| EXTRA_TEST_OPTIONS="" | ||
| SCRIPT_VERBOSE=0 | ||
|
|
||
| # Option parsing | ||
| # Reset in case getopts has been used previously in the shell | ||
| OPTIND=1 | ||
| # Array for invalid options | ||
| INVALID_OPTIONS=(); | ||
| # Simple option parsing based on getopts (! not getopt) | ||
| while getopts ":s:d:p:e:xy:huv" OPT; do | ||
| case ${OPT} in | ||
| s) | ||
| TEST_SUITE=${OPTARG} | ||
| ;; | ||
| d) | ||
| DBMS=${OPTARG} | ||
| ;; | ||
| p) | ||
| PHP_VERSION=${OPTARG} | ||
| ;; | ||
| e) | ||
| EXTRA_TEST_OPTIONS=${OPTARG} | ||
| ;; | ||
| x) | ||
| PHP_XDEBUG_ON=1 | ||
| ;; | ||
| y) | ||
| PHP_XDEBUG_PORT=${OPTARG} | ||
| ;; | ||
| h) | ||
| echo "${HELP}" | ||
| exit 0 | ||
| ;; | ||
| u) | ||
| TEST_SUITE=update | ||
| ;; | ||
| v) | ||
| SCRIPT_VERBOSE=1 | ||
| ;; | ||
| \?) | ||
| INVALID_OPTIONS+=(${OPTARG}) | ||
| ;; | ||
| :) | ||
| INVALID_OPTIONS+=(${OPTARG}) | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # Exit on invalid options | ||
| if [ ${#INVALID_OPTIONS[@]} -ne 0 ]; then | ||
| echo "Invalid option(s):" >&2 | ||
| for I in "${INVALID_OPTIONS[@]}"; do | ||
| echo "-"${I} >&2 | ||
| done | ||
| echo >&2 | ||
| echo "${HELP}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Move "7.2" to "php72", the latter is the docker container name | ||
| DOCKER_PHP_IMAGE=`echo "php${PHP_VERSION}" | sed -e 's/\.//'` | ||
|
|
||
| # Set $1 to first mass argument, this is the optional test file or test directory to execute | ||
| shift $((OPTIND - 1)) | ||
| if [ -n "${1}" ]; then | ||
| TEST_FILE="Web/typo3conf/ext/publisher_db/${1}" | ||
| else | ||
| case ${TEST_SUITE} in | ||
| functional) | ||
| TEST_FILE="Web/typo3conf/ext/publisher_db/Tests/Functional" | ||
| ;; | ||
| unit) | ||
| TEST_FILE="Web/typo3conf/ext/publisher_db/Tests/Unit" | ||
| ;; | ||
| esac | ||
| fi | ||
|
|
||
| if [ ${SCRIPT_VERBOSE} -eq 1 ]; then | ||
| set -x | ||
| fi | ||
|
|
||
| # Suite execution | ||
| case ${TEST_SUITE} in | ||
| composerInstall) | ||
| setUpDockerComposeDotEnv | ||
| docker-compose run composer_install | ||
| SUITE_EXIT_CODE=$? | ||
| docker-compose down | ||
| ;; | ||
| composerInstallMax) | ||
| setUpDockerComposeDotEnv | ||
| docker-compose run composer_install_max | ||
| SUITE_EXIT_CODE=$? | ||
| docker-compose down | ||
| ;; | ||
| composerInstallMin) | ||
| setUpDockerComposeDotEnv | ||
| docker-compose run composer_install_min | ||
| SUITE_EXIT_CODE=$? | ||
| docker-compose down | ||
| ;; | ||
| composerValidate) | ||
| setUpDockerComposeDotEnv | ||
| docker-compose run composer_validate | ||
| SUITE_EXIT_CODE=$? | ||
| docker-compose down | ||
| ;; | ||
| functional) | ||
| setUpDockerComposeDotEnv | ||
| case ${DBMS} in | ||
| mariadb) | ||
| docker-compose run functional_mariadb10 | ||
| SUITE_EXIT_CODE=$? | ||
| ;; | ||
| mssql) | ||
| docker-compose run functional_mssql2019latest | ||
| SUITE_EXIT_CODE=$? | ||
| ;; | ||
| postgres) | ||
| docker-compose run functional_postgres10 | ||
| SUITE_EXIT_CODE=$? | ||
| ;; | ||
| sqlite) | ||
| docker-compose run functional_sqlite | ||
| SUITE_EXIT_CODE=$? | ||
| ;; | ||
| *) | ||
| echo "Invalid -d option argument ${DBMS}" >&2 | ||
| echo >&2 | ||
| echo "${HELP}" >&2 | ||
| exit 1 | ||
| esac | ||
| docker-compose down | ||
| ;; | ||
| lint) | ||
| setUpDockerComposeDotEnv | ||
| docker-compose run lint | ||
| SUITE_EXIT_CODE=$? | ||
| docker-compose down | ||
| ;; | ||
| unit) | ||
| setUpDockerComposeDotEnv | ||
| docker-compose run unit | ||
| SUITE_EXIT_CODE=$? | ||
| docker-compose down | ||
| ;; | ||
| update) | ||
| # pull typo3gmbh/phpXY:latest versions of those ones that exist locally | ||
| docker images typo3gmbh/php*:latest --format "{{.Repository}}:latest" | xargs -I {} docker pull {} | ||
| # remove "dangling" typo3gmbh/phpXY images (those tagged as <none>) | ||
| docker images typo3gmbh/php* --filter "dangling=true" --format "{{.ID}}" | xargs -I {} docker rmi {} | ||
| ;; | ||
| *) | ||
| echo "Invalid -s option argument ${TEST_SUITE}" >&2 | ||
| echo >&2 | ||
| echo "${HELP}" >&2 | ||
| exit 1 | ||
| esac | ||
|
|
||
| exit $SUITE_EXIT_CODE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| # slub_find_flexibleviews | ||
| Flexible Views for the SLUB find catalog | ||
|
|
||
| ## Running the Unit Tests | ||
|
|
||
| PHPUnit is required for running the unit tests. It comes with the DEV requirement `typo3/testing-framework` | ||
|
|
||
| ### Running outside a TYPO3 environment | ||
|
|
||
| ```.Build/bin/phpunit Tests/``` | ||
|
|
||
| ### Running within a TYPO3 environment | ||
|
|
||
| ```./vendor/bin/phpunit public/typo3conf/ext/slub_find_flexibleviews/Tests``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are really using this script? If yes, it should be mentioned in the README.