diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 254dd56b..41e8685e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,19 +11,24 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v4.1.5 - name: Build the docker image for keyman.com app shell: bash run: | echo "TIER_TEST" > tier.txt - ./build.sh build start + ./build.sh configure build start --debug env: fail-fast: true # # Finally, run the tests # + - name: PHP test + shell: bash + run: | + docker exec keyman-com-app sh -c "vendor/bin/phpunit --testdox" + - name: Lint shell: bash run: | diff --git a/.gitignore b/.gitignore index 2775cf5c..aa73d6cd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ cdn/deploy/ tier.txt +# unit test artifacts +blc.log +.phpunit.result.cache + vendor* /node_modules/ diff --git a/.htaccess b/.htaccess index d5c9ef4c..9ac54189 100644 --- a/.htaccess +++ b/.htaccess @@ -34,6 +34,9 @@ RewriteRule "^(macosx|macos)\b(.*)$" "/mac$2" [NC,R=301,END,QSA] # Redirect deprecated Google Plus link RewriteRule "^plus.*" "/" [NC,R=301,END,QSA] +# Redirect PHP unit tests +RewriteRule "^tests(\/.*)?" "/" [NC,R=301,END,QSA] + # /donate -> donate.keyman.com RedirectMatch 301 "^(?i)/donate(\/.*)?" "https://donate.keyman.com" diff --git a/Dockerfile b/Dockerfile index 71f0b396..e27aed1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ # syntax=docker/dockerfile:1 + +ARG BUILDER_CONFIGURATION="release" FROM php:7.4-apache@sha256:c9d7e608f73832673479770d66aacc8100011ec751d1905ff63fae3fe2e0ca6d AS composer-builder # Install Zip to use composer @@ -15,7 +17,14 @@ RUN composer self-update USER www-data WORKDIR /composer COPY composer.* /composer/ -RUN composer install +# Consume the build argment +ARG BUILDER_CONFIGURATION +RUN if [ "$BUILDER_CONFIGURATION" = "debug" ]; then \ + # composer install --dev deprecated + COMPOSER_NO_DEV=0 composer install ; \ + else \ + COMPOSER_NO_DEV=1 composer install ; \ + fi # Site FROM php:7.4-apache@sha256:c9d7e608f73832673479770d66aacc8100011ec751d1905ff63fae3fe2e0ca6d diff --git a/README.md b/README.md index e18f83f9..301133da 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,12 @@ shell, and from this folder, run: ./build.sh build ``` +If you'll be running tests locally, the Docker image will need to be built with dev dependencies: + +```sh +./build.sh build --debug +``` + #### Start the Docker container To start up the website, in bash, run: @@ -81,7 +87,11 @@ In bash, run: #### Running tests -To check for broken links and .php file conformance, when the site is running, +When the site is running, the test action will do the following: +* PHP unit tests +* Check .php file conformance +* Check for internal broken links + in bash, run: ```sh diff --git a/build.sh b/build.sh index 8076e169..a65bd489 100755 --- a/build.sh +++ b/build.sh @@ -28,11 +28,21 @@ builder_describe \ builder_parse "$@" function test_docker_container() { - # TODO: lint tests + # Note: ci.yml replicates these + echo "TIER_TEST" > tier.txt - echo "---- Testing links ----" set +e; set +o pipefail; + + builder_echo blue "---- PHP unit tests" + docker exec $KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox" + + # Lint .php files for obvious errors + builder_echo blue "---- Lint PHP files" + docker exec $KEYMAN_CONTAINER_DESC sh -c "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l" + + # NOTE: link checker runs on host rather than in docker image + builder_echo blue "---- Testing links" npx broken-link-checker http://localhost:8053/_test --recursive --ordered ---host-requests 50 -e --filter-level 3 --exclude '*/donate' | tee blc.log local BLC_RESULT=${PIPESTATUS[0]} echo ---------------------------------------------------------------------- @@ -42,7 +52,7 @@ function test_docker_container() { grep -E "BROKEN|Getting links from" | \ grep -B 1 "BROKEN"; - echo "Done checking links" + builder_echo blue "Done checking links" rm tier.txt return "${BLC_RESULT}" } @@ -50,7 +60,7 @@ function test_docker_container() { builder_run_action configure bootstrap_configure builder_run_action clean clean_docker_container $KEYMAN_IMAGE_NAME $KEYMAN_CONTAINER_NAME builder_run_action stop stop_docker_container $KEYMAN_IMAGE_NAME $KEYMAN_CONTAINER_NAME -builder_run_action build build_docker_container $KEYMAN_IMAGE_NAME $KEYMAN_CONTAINER_NAME +builder_run_action build build_docker_container $KEYMAN_IMAGE_NAME $KEYMAN_CONTAINER_NAME $BUILDER_CONFIGURATION builder_run_action start start_docker_container $KEYMAN_IMAGE_NAME $KEYMAN_CONTAINER_NAME $KEYMAN_CONTAINER_DESC $HOST_KEYMAN_COM $PORT_KEYMAN_COM $BUILDER_CONFIGURATION builder_run_action test test_docker_container diff --git a/composer.json b/composer.json index 8654659b..74e9d317 100644 --- a/composer.json +++ b/composer.json @@ -1,24 +1,12 @@ { "name": "keymanapi/keyman.com", "require": { - "sentry/sdk": "^2.1", + "sentry/sdk": "^2.1.0", "php-http/curl-client": "^2.1", - "erusev/parsedown-extra": "^0.8.1", - "erusev/parsedown": "^1.7" + "erusev/parsedown": "^1.7", + "erusev/parsedown-extra": "^0.8.1" }, "require-dev": { "phpunit/phpunit": "^9.2" - }, - "scripts": { - "test": "vendor\\bin\\phpunit --testdox", - "check-links": [ - "Composer\\Config::disableProcessTimeout", - "npx broken-link-checker http://keyman.com.localhost --ordered --recursive --host-requests 10 -e --filter-level 3 --exclude '*/donate'" - ], - "check-docker-links": [ - "Composer\\Config::disableProcessTimeout", - "npx broken-link-checker http://localhost:8053 --ordered --recursive --host-requests 10 -e --filter-level 3 --exclude '*/donate'" - ], - "lint": "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..69fc7d6b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,8 @@ + + + + + tests + + + \ No newline at end of file diff --git a/tests/InfrastructureTest.php b/tests/InfrastructureTest.php new file mode 100644 index 00000000..8b2425b3 --- /dev/null +++ b/tests/InfrastructureTest.php @@ -0,0 +1,13 @@ +assertTrue(true); + } +}