Commit 4302ed4b authored by Felix Herrmann's avatar Felix Herrmann
Browse files

Merge branch 'feature/add-9.5-compatibility' into 'master'

Feature/add 9.5 compatibility

See merge request riconet-public/typo3/rico_talentstorm!18
parents 7a3e556d 1c94be61
......@@ -5,9 +5,8 @@ cache:
stages:
- build
- code_quallity
- quality
- test
- merge_requests
composer:
image: composer:1.6.5
......@@ -19,50 +18,72 @@ composer:
paths:
- .Build/
only:
- merge_requests
- master
lint:
image: php:7.2-alpine
stage: quality
script:
- php -v | grep '^PHP';
- find . -name \\*.php ! -path "./.Build/\\*" -print0 | xargs -0 -n1 -P4 php -n -c /etc/php/cli-no-xdebug/php.ini -l >/dev/null;
only:
- merge_requests
- master
phpstan:
image: php:7.0
stage: code_quallity
image: php:7.2-alpine
stage: quality
script:
- .Build/bin/phpstan analyse -l 1 Classes Tests
- .Build/bin/phpstan analyse -c phpstan.neon -l max Classes
only:
- master
- merge_requests
- master
allow_failure: true
codesniffer:
image: php:7.0
stage: code_quallity
image: php:7.2-alpine
stage: quality
script:
- .Build/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php Classes Tests
- .Build/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php Classes
only:
- master
- merge_requests
- master
allow_failure: true
phpmd:
image: php:7.0
stage: code_quallity
image: php:7.2-alpine
stage: quality
script:
- .Build/bin/phpmd Classes,Tests text phpmd.xml
- .Build/bin/phpmd Classes text phpmd.xml
only:
- master
- merge_requests
- master
allow_failure: true
debug_call_usages:
image: php:7.2-alpine
stage: quality
script:
- |
if grep -rnw "Resources/Private/" "Classes/" -e "debug" -e "DebuggerUtility"
then
exit 1;
fi
only:
- merge_requests
- master
unittests:
image: typo3gmbh/php70
image: riconet/typo3:9.5
stage: test
script:
.Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml "" .Build/Web/typo3conf/ext/${CI_PROJECT_NAME}/Tests/Unit
only:
- master
- merge_requests
- master
functionaltests:
image: typo3gmbh/php70
image: riconet/typo3:9.5
stage: test
variables:
MYSQL_ROOT_PASSWORD: funcp
......@@ -75,5 +96,5 @@ functionaltests:
script:
.Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml "" .Build/Web/typo3conf/ext/${CI_PROJECT_NAME}/Tests/Functional
only:
- master
- merge_requests
\ No newline at end of file
- merge_requests
- master
\ No newline at end of file
#!/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
# Function to write a .env file in Build/testing-docker
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 "DOCKER_PHP_IMAGE=${DOCKER_PHP_IMAGE}" >> .env
echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}" >> .env
echo "SCRIPT_VERBOSE=${SCRIPT_VERBOSE}" >> .env
ECHO "EXTENSION_KEY=${EXTENSION_KEY}" >> .env
[ -e .env ] && rm .env
echo "TEST_FILE=${TEST_FILE}" >>.env
echo "ROOT_DIR=${ROOT_DIR}" >>.env
echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}" >>.env
echo "EXTENSION_KEY=${EXTENSION_KEY}" >>.env
echo "PHP_VERSION=${PHP_VERSION}" >>.env
echo "HOST_USER=${USER}" >>.env
echo "HOST_HOME=${HOME}" >>.env
echo "HOST_UID=$(id -u)" >>.env
}
# Function to get the realpath on mac os.
# Function to get the real path on mac os.
realpath() {
if ! pushd $1 &> /dev/null; then
pushd ${1##*/} &> /dev/null
echo $( pwd -P )/${1%/*}
else
pwd -P
fi
popd > /dev/null
if ! pushd $1 &>/dev/null; then
pushd ${1##*/} &>/dev/null
echo $(pwd -P)/${1%/*}
else
pwd -P
fi
popd >/dev/null
}
# Load help text into $HELP
read -r -d '' HELP <<EOF
Extension test runner. Execute unit test suite and some other details.
Successfully tested with docker version 18.06.1-ce and docker-compose 1.21.2.
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", handy if host has no PHP, uses composer cache of users home
- composerValidate: "composer validate"
- build: Builds the project (composer)
- lint: Lints the php files
- functional: functional tests
- unit (default): PHP unit tests
- code-quality: executes code quality checks (phpstan, phpcs, phpmd).
- quality: executes code quality checks (phpstan, phpcs, phpmd)
- find-debugs: Finds usages of debug calls.
-p <7.2|7.3>
Specifies the PHP minor version to be used
......@@ -73,45 +53,23 @@ Options:
Example -e "-v --filter canRetrieveValueWithGP" to enable verbose output AND filter tests
named "canRetrieveValueWithGP"
-x
Only with -s functional|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
# Run unit tests
./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
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 )"
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
......@@ -121,130 +79,109 @@ cd ../testing-docker || exit 1
EXTENSION_KEY="$(basename $(realpath $PWD"/../../"))"
ROOT_DIR=$(realpath $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=();
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}
;;
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
case ${OPT} in
s)
TEST_SUITE=${OPTARG}
;;
p)
PHP_VERSION=${OPTARG}
;;
e)
EXTRA_TEST_OPTIONS=${OPTARG}
;;
h)
echo "${HELP}"
exit 0
;;
\?)
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
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/${EXTENSION_KEY}/${1}"
TEST_FILE="Web/typo3conf/ext/${EXTENSION_KEY}/${1}"
else
case ${TEST_SUITE} in
functional)
TEST_FILE="Web/typo3conf/ext/${EXTENSION_KEY}/Tests/Functional"
;;
unit)
TEST_FILE="Web/typo3conf/ext/${EXTENSION_KEY}/Tests/Unit"
;;
esac
fi
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
set -x
case ${TEST_SUITE} in
functional)
TEST_FILE="Web/typo3conf/ext/${EXTENSION_KEY}/Tests/Functional"
;;
unit)
TEST_FILE="Web/typo3conf/ext/${EXTENSION_KEY}/Tests/Unit"
;;
esac
fi
# Suite execution
case ${TEST_SUITE} in
composerInstall)
setUpDockerComposeDotEnv
docker-compose run composer_install
SUITE_EXIT_CODE=$?
docker-compose down
;;
composerValidate)
setUpDockerComposeDotEnv
docker-compose run composer_validate
SUITE_EXIT_CODE=$?
docker-compose down
;;
functional)
setUpDockerComposeDotEnv
docker-compose run functional_mariadb10
SUITE_EXIT_CODE=$?
docker-compose down
;;
unit)
setUpDockerComposeDotEnv
docker-compose run unit
SUITE_EXIT_CODE=$?
docker-compose down
;;
code-quality)
${ROOT_DIR}/.Build/bin/phpstan analyse --autoload-file=${ROOT_DIR}/.Build/vendor/autoload.php -l 1 ${ROOT_DIR}/Classes ${ROOT_DIR}/Tests
${ROOT_DIR}/.Build/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php ${ROOT_DIR}/Classes ${ROOT_DIR}/Tests
${ROOT_DIR}/.Build/bin/phpmd ${ROOT_DIR}/Classes,${ROOT_DIR}/Tests text ${ROOT_DIR}/phpmd.xml
;;
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
build)
setUpDockerComposeDotEnv
docker-compose run build
SUITE_EXIT_CODE=$?
docker-compose down
;;
lint)
setUpDockerComposeDotEnv
docker-compose run lint
SUITE_EXIT_CODE=$?
docker-compose down
;;
functional)
setUpDockerComposeDotEnv
docker-compose run functional
SUITE_EXIT_CODE=$?
docker-compose down
;;
unit)
setUpDockerComposeDotEnv
docker-compose run unit
SUITE_EXIT_CODE=$?
docker-compose down
;;
quality)
setUpDockerComposeDotEnv
docker-compose run quality
SUITE_EXIT_CODE=$?
docker-compose down
;;
find-debugs)
setUpDockerComposeDotEnv
docker-compose run debugUsageCallCheck
SUITE_EXIT_CODE=$?
docker-compose down
;;
*)
echo "Invalid -s option argument ${TEST_SUITE}" >&2
echo >&2
echo "${HELP}" >&2
exit 1
;;
esac
exit $SUITE_EXIT_CODE
\ No newline at end of file
exit $SUITE_EXIT_CODE
version: '2.3'
services:
mariadb10:
image: mariadb:10
#======================================================
# DB
#======================================================
db:
image: mysql:5.7
command: mysqld --character-set-server=utf8
environment:
MYSQL_ROOT_PASSWORD: funcp
volumes:
- .database:/var/lib/mysql
composer_install:
image: typo3gmbh/${DOCKER_PHP_IMAGE}:latest
#======================================================
# Build
#======================================================
build:
image: composer:1.6.5
user: ${HOST_UID}
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
......@@ -18,34 +24,60 @@ services:
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
set -x
fi
composer install;
composer install;
"
composer_validate:
image: typo3gmbh/${DOCKER_PHP_IMAGE}:latest
user: ${HOST_UID}
#======================================================
# Lint
#======================================================
lint:
image: typo3gmbh/php72:latest
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
php -v | grep '^PHP';
find . -name \\*.php ! -path "./.Build/\\*" -print0 | xargs -0 -n1 -P4 php -n -c /etc/php/cli-no-xdebug/php.ini -l >/dev/null
"
#======================================================
# Quality
#======================================================
quality:
image: php:${PHP_VERSION}-alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
echo \"Running phpcs...\";
.Build/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php Classes;
echo \"Running phpmd...\";
.Build/bin/phpmd Classes text phpmd.xml;
echo \"Running phpstan...\";
.Build/bin/phpstan analyse -c phpstan.neon --autoload-file=.Build/vendor/autoload.php -l max Classes
"
#======================================================
# Debug usage call check
#======================================================
debugUsageCallCheck:
image: php:${PHP_VERSION}-alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
- ${HOST_HOME}:${HOST_HOME}
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
set -x
fi
composer validate;
if grep -rnw "Resources/Private/" "Classes/" -e "debug" -e "DebuggerUtility"; then
exit 1
fi
"
functional_mariadb10:
image: typo3gmbh/${DOCKER_PHP_IMAGE}:latest
#======================================================
# Functional tests
#======================================================
functional:
image: riconet/typo3:9.5
user: ${HOST_UID}
links:
- mariadb10
- db
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
- ${HOST_HOME}:${HOST_HOME}
......@@ -55,32 +87,22 @@ services:
typo3DatabaseName: func_test
typo3DatabaseUsername: root
typo3DatabasePassword: funcp
typo3DatabaseHost: mariadb10
typo3DatabaseHost: db
working_dir: ${ROOT_DIR}/.Build
command: >
/bin/sh -c "
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
set -x
fi
echo Waiting for database start...;
while ! nc -z mariadb10 3306; do
sleep 1;
done;
echo Database is up;
php -v | grep '^PHP'
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
php -n -c /etc/php/cli-no-xdebug/php.ini \
bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
else
DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
XDEBUG_CONFIG=\"remote_port=${PHP_XDEBUG_PORT} remote_enable=1 remote_host=$${DOCKER_HOST}\" \
bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
fi
echo Waiting for database start...;
while ! nc -z db 3306; do
sleep 1;
done;
echo Database is up;
php bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
"
#======================================================
# Unit tests
#======================================================
unit:
image: typo3gmbh/${DOCKER_PHP_IMAGE}:latest
image: riconet/typo3:9.5
user: ${HOST_UID}
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
......@@ -90,16 +112,5 @@ services:
working_dir: ${ROOT_DIR}/.Build
command: >
/bin/sh -c "
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
set -x
fi
php -v | grep '^PHP'
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
php -n -c /etc/php/cli-no-xdebug/php.ini \
bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
else
DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
XDEBUG_CONFIG=\"remote_port=${PHP_XDEBUG_PORT} remote_enable=1 remote_host=$${DOCKER_HOST}\" \
bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
fi
php bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
"
\ No newline at end of file
......@@ -8,6 +8,8 @@
* (c) 2019 Wolf Utz <utz@riconet.de>, Hees riconet GmbH
*/
declare(strict_types=1);
namespace Riconet\RicoTalentstorm\Cache;
use TYPO3\CMS\Core\Cache\CacheManager;
......@@ -29,8 +31,8 @@ class CacheProvider
/**
* Gets an existing entry of the cache.
*
* @param $cacheName
* @param $identifier