bye bye Travis
[plcapi.git] / tests / ci / vm.sh
old mode 100644 (file)
new mode 100755 (executable)
index 8344ac8..1cef916
@@ -1,20 +1,21 @@
 #!/bin/sh
 
-# @todo support getting the 2 vars as cli args as well as via env vars?
+# @todo support getting the 2 vars as cli options as well as via env vars?
 
 set -e
 
 ACTION="${1}"
 
-# Valid values: 'default', 5.6, 7.0 .. 7.4, 8.0
+# Valid values: 'default', 5.6, 7.0 .. 7.4, 8.0 .. 8.1
 export PHP_VERSION=${PHP_VERSION:-default}
 # Valid values: precise (12), trusty (14), xenial (16), bionic (18), focal (20)
-# We default to the same version we use on Travis
-export UBUNTU_VERSION=${UBUNTU_VERSION:-xenial}
+export UBUNTU_VERSION=${UBUNTU_VERSION:-bionic}
 
+CONTAINER_USER=docker
+CONTAINER_BUILD_DIR="/home/${CONTAINER_USER}/build"
+ROOT_DIR="$(dirname -- "$(dirname -- "$(dirname -- "$(readlink -f "$0")")")")"
 IMAGE_NAME=phpxmlrpc:${UBUNTU_VERSION}-${PHP_VERSION}
 CONTAINER_NAME=phpxmlrpc_${UBUNTU_VERSION}_${PHP_VERSION}
-ROOT_DIR="$(dirname -- "$(dirname -- "$(dirname -- "$(readlink -f "$0")")")")"
 
 cd "$(dirname -- "$(readlink -f "$0")")"
 
@@ -25,15 +26,23 @@ Manages the Test Environment Docker Stack
 
 Commands:
     build             build or rebuild the containers and set up the test env
+    cleanup           removes the docker containers and their images
     enter             enter the test container
-    #exec \$cmd         execute a single shell command in the test container
-    #runtests [\$suite] execute the test suite using the test container (or a single test scenario eg. Tests/1ParsingBugsTest.php)
+    inspect
+    logs
+    ps
+    runtests [\$suite] execute the test suite using the test container (or a single test scenario eg. tests/1ParsingBugsTest.php)
+    runcoverage       execute the test suite and generate a code coverage report (in build/coverage)
     start             start the containers
-    #status
     stop              stop containers
+    top
 
 Options:
     -h                print help
+
+Environment variables: to be set before the 'build' action
+    PHP_VERSION       default value: 'default', ie. the stock php version from the Ubuntu version in use. Other possible values: 5.6, 7.0 .. 8.1
+    UBUNTU_VERSION    default value: bionic. Other possible values: xenial, focal
 "
 }
 
@@ -46,9 +55,10 @@ build() {
     docker run -d \
         -p 80:80 -p 443:443 -p 8080:8080 \
         --name "${CONTAINER_NAME}" \
-        --env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) --env TESTS_ROOT_DIR=/home/test \
-        --env LOCALSERVER=localhost \
-        --env URI=/demo/server/server.php \
+        --env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) \
+        --env TESTS_ROOT_DIR=${CONTAINER_BUILD_DIR} \
+        --env HTTPSERVER=localhost \
+        --env HTTPURI=/demo/server/server.php \
         --env HTTPSSERVER=localhost \
         --env HTTPSURI=/demo/server/server.php \
         --env PROXYSERVER=localhost:8080 \
@@ -56,7 +66,8 @@ build() {
         --env HTTPSIGNOREPEER=1 \
         --env SSLVERSION=0 \
         --env DEBUG=0 \
-        -v "${ROOT_DIR}":/home/test "${IMAGE_NAME}"
+        -v "${ROOT_DIR}":"${CONTAINER_BUILD_DIR}" \
+         "${IMAGE_NAME}"
 }
 
 start() {
@@ -86,9 +97,11 @@ case "${ACTION}" in
         ;;
 
     enter | shell | cli)
-        docker exec -it "${CONTAINER_NAME}" su test
+        # @todo allow login as root
+        docker exec -it "${CONTAINER_NAME}" su "${CONTAINER_USER}"
         ;;
 
+    # @todo implement
     #exec)
     #    ;;
 
@@ -97,8 +110,17 @@ case "${ACTION}" in
         start
         ;;
 
-    #runtests)
-    #    ;;
+    runcoverage)
+        # @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache
+        if [ ! -d build ]; then mkdir build; fi
+        docker exec -t "${CONTAINER_NAME}" /home/${CONTAINER_USER}/build/tests/ci/setup/setup_code_coverage.sh enable
+        docker exec -it "${CONTAINER_NAME}" su "${CONTAINER_USER}" -c "./vendor/bin/phpunit --coverage-html build/coverage -v tests"
+        docker exec -t "${CONTAINER_NAME}" /home/${CONTAINER_USER}/build/tests/ci/setup/setup_code_coverage.sh disable
+        ;;
+
+    runtests)
+        docker exec -it "${CONTAINER_NAME}" su "${CONTAINER_USER}" -c "./vendor/bin/phpunit -v tests"
+        ;;
 
     start)
         start