Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--debug needed so Docker will build with dev dependencies

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: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ cdn/deploy/

tier.txt

# unit test artifacts
blc.log
.phpunit.result.cache

vendor*
/node_modules/

Expand Down
3 changes: 3 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------------------------------
Expand All @@ -42,15 +52,15 @@ 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}"
}

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This passes in the BUILDER_CONFIGURATION parameter for keymanapp/shared-sites#84

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
18 changes: 3 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
13 changes: 13 additions & 0 deletions tests/InfrastructureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace Keyman\Site\com\keyman\tests;

use PHPUnit\Framework\TestCase;

final class InfrastructureTest extends TestCase
{
public function testTestsAreWorking(): void
{
$this->assertTrue(true);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from help.keyman.com

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should .htaccess block the /tests folder? Otherwise, I get this error

Fatal error: Uncaught Error: Class 'PHPUnit\Framework\TestCase' not found in /var/www/html/tests/InfrastructureTest.php:7 Stack trace: #0 {main} thrown in /var/www/html/tests/InfrastructureTest.php on line 7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added redirect in c3f1c8a

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, unsure, probably fine?