Add extension template with PHPStan, PHPUnit and phpcs
This commit is contained in:
parent
b4c6581d4f
commit
8cd928caa9
22 changed files with 825 additions and 1 deletions
33
tests/docker-compose.yml
Normal file
33
tests/docker-compose.yml
Normal file
|
@ -0,0 +1,33 @@
|
|||
version: "3"
|
||||
services:
|
||||
civicrm:
|
||||
image: michaelmcandrew/civicrm:${CIVICRM_IMAGE_TAG:-5-drupal-php8.1}
|
||||
environment:
|
||||
- PROJECT_NAME=test
|
||||
- BASE_URL=http://localhost
|
||||
- CIVICRM_DB_NAME=test
|
||||
- CIVICRM_DB_USER=root
|
||||
- CIVICRM_DB_PASS=secret
|
||||
- CIVICRM_DB_HOST=mysql
|
||||
- CIVICRM_DB_PORT=3306
|
||||
- DRUPAL_DB_NAME=test
|
||||
- DRUPAL_DB_USER=root
|
||||
- DRUPAL_DB_PASS=secret
|
||||
- DRUPAL_DB_HOST=mysql
|
||||
- DRUPAL_DB_PORT=3306
|
||||
- PHP_DATE_TIMEZONE=UTC
|
||||
- DEBUG=ON
|
||||
- SMTP_HOST=localhost
|
||||
- SMTP_MAILDOMAIN=example.org
|
||||
volumes:
|
||||
- ../:/var/www/html/sites/default/files/civicrm/ext/de.systopia.twingle:${BIND_VOLUME_PERMISSIONS:-ro}
|
||||
- /var/www/html/sites/default/files/civicrm/ext/de.systopia.twingle/vendor
|
||||
- /var/www/html/sites/default/files/civicrm/ext/de.systopia.twingle/tools/phpunit/vendor
|
||||
# Don't start Apache HTTP Server, but keep container running
|
||||
command: ["tail", "-f", "/dev/null"]
|
||||
stop_signal: SIGKILL
|
||||
mysql:
|
||||
image: mariadb
|
||||
environment:
|
||||
MARIADB_ROOT_PASSWORD: secret
|
||||
MARIADB_DATABASE: test
|
19
tests/docker-phpunit.sh
Executable file
19
tests/docker-phpunit.sh
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
set -eu -o pipefail
|
||||
|
||||
SCRIPT_DIR=$(realpath "$(dirname "$0")")
|
||||
EXT_DIR=$(dirname "$SCRIPT_DIR")
|
||||
|
||||
cd "$EXT_DIR"
|
||||
if [ ! -e tools/phpunit/vendor/bin ]; then
|
||||
"$SCRIPT_DIR/docker-prepare.sh"
|
||||
fi
|
||||
|
||||
export XDEBUG_MODE=coverage
|
||||
# TODO: Remove when not needed, anymore.
|
||||
# In Docker container with CiviCRM 5.5? all deprecations are reported as direct
|
||||
# deprecations so "disabling" check of deprecation count is necessary for the
|
||||
# tests to pass (if baselineFile does not contain all deprecations).
|
||||
export SYMFONY_DEPRECATIONS_HELPER="max[total]=99999&baselineFile=./tests/ignored-deprecations.json"
|
||||
|
||||
composer phpunit -- --cache-result-file=/tmp/.phpunit.result.cache "$@"
|
45
tests/docker-prepare.sh
Executable file
45
tests/docker-prepare.sh
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
set -eu -o pipefail
|
||||
|
||||
EXT_DIR=$(dirname "$(dirname "$(realpath "$0")")")
|
||||
EXT_NAME=$(basename "$EXT_DIR")
|
||||
|
||||
i=0
|
||||
while ! mysql -h "$CIVICRM_DB_HOST" -P "$CIVICRM_DB_PORT" -u "$CIVICRM_DB_USER" --password="$CIVICRM_DB_PASS" -e 'SELECT 1;' >/dev/null 2>&1; do
|
||||
i=$((i+1))
|
||||
if [ $i -gt 10 ]; then
|
||||
echo "Failed to connect to database" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n .
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
export XDEBUG_MODE=off
|
||||
if mysql -h "$CIVICRM_DB_HOST" -P "$CIVICRM_DB_PORT" -u "$CIVICRM_DB_USER" --password="$CIVICRM_DB_PASS" "$CIVICRM_DB_NAME" -e 'SELECT 1 FROM civicrm_setting LIMIT 1;' >/dev/null 2>&1; then
|
||||
cv flush
|
||||
else
|
||||
# For headless tests it is required that CIVICRM_UF is defined using the corresponding env variable.
|
||||
sed -E "s/define\('CIVICRM_UF', '([^']+)'\);/define('CIVICRM_UF', getenv('CIVICRM_UF') ?: '\1');/g" \
|
||||
-i /var/www/html/sites/default/civicrm.settings.php
|
||||
civicrm-docker-install
|
||||
|
||||
# Avoid this error:
|
||||
# The autoloader expected class "Civi\ActionSchedule\Mapping" to be defined in
|
||||
# file "[...]/Civi/ActionSchedule/Mapping.php". The file was found but the
|
||||
# class was not in it, the class name or namespace probably has a typo.
|
||||
rm -f /var/www/html/sites/all/modules/civicrm/Civi/ActionSchedule/Mapping.php
|
||||
|
||||
# For headless tests these files need to exist.
|
||||
touch /var/www/html/sites/all/modules/civicrm/sql/test_data.mysql
|
||||
touch /var/www/html/sites/all/modules/civicrm/sql/test_data_second_domain.mysql
|
||||
|
||||
cv ext:enable "$EXT_NAME"
|
||||
fi
|
||||
|
||||
cd "$EXT_DIR"
|
||||
composer update --no-progress --prefer-dist --optimize-autoloader --no-dev
|
||||
composer composer-phpunit -- update --no-progress --prefer-dist
|
1
tests/ignored-deprecations.json
Normal file
1
tests/ignored-deprecations.json
Normal file
|
@ -0,0 +1 @@
|
|||
[]
|
Loading…
Add table
Add a link
Reference in a new issue