Commit d20643f6 authored by Thorsten Müller's avatar Thorsten Müller
Browse files

Merge branch 'feature/support-typo3-10' into 'master'

Add support for TYPO3 10.4

See merge request riconet-public/typo3/rico_talentstorm!29
parents a9c654eb 783b3bad
version: '2.3'
services:
#======================================================
# DB
#======================================================
mariadb10:
image: mariadb:10
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: funcp
tmpfs:
- /var/lib/mysql/:rw,noexec,nosuid
#======================================================
# Build
#======================================================
build:
image: edbizarro/gitlab-ci-pipeline-php:${PHP_VERSION}-alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
composer install;
"
#======================================================
# Lint
#======================================================
lint:
image: typo3gmbh/php72:latest
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
echo \"Lint php...\";
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
echo \"Lint Typoscript...\";
.Build/bin/typoscript-lint Configuration/TypoScript/
echo \"Lint for debug calls...\";
if grep -rnw "Resources/Private/" "Classes/" -e "debug" -e "DebuggerUtility"; then
exit 1
fi
"
#======================================================
# Quality
#======================================================
quality:
image: php:${PHP_VERSION}-alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
echo \"===============================================\";
echo \"Running phpcs...\";
.Build/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php Classes;
echo \"===============================================\";
echo \"Running php-cs-fixer...\";
.Build/bin/php-cs-fixer fix --allow-risky=yes --dry-run --diff
echo \"===============================================\";
echo \"Running phpmd...\";
.Build/bin/phpmd Classes text phpmd.xml;
echo \"===============================================\";
echo \"Running phpstan...\";
php -d memory_limit=4G .Build/bin/phpstan analyse -c phpstan.neon
echo \"===============================================\";
echo \"Running psalm...\";
.Build/bin/psalm --show-info=true
"
#======================================================
# Fix
#======================================================
fix:
image: riconet/typo3:9.5
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
echo \"Fix quality errors...\";
.Build/bin/php-cs-fixer fix --allow-risky=yes
.Build/bin/phpcbf --error-severity=1 --warning-severity=8 --extensions=php
"
#======================================================
# Functional tests
#======================================================
functional:
image: riconet/typo3:9.5
links:
- mariadb10
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
environment:
typo3DatabaseName: func_test
typo3DatabaseUsername: root
typo3DatabasePassword: funcp
typo3DatabaseHost: mariadb10
working_dir: ${ROOT_DIR}/.Build
command: >
/bin/sh -c "
echo Waiting for database start...;
while ! nc -z mariadb10 3306; do
sleep 1;
done;
echo Database is up;
bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ../Tests/Functional;
rm -rf Web/typo3temp/var/tests/func*
"
#======================================================
# Unit tests
#======================================================
unit:
image: riconet/typo3:9.5
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}/.Build
command: >
/bin/sh -c "
php bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/UnitTests.xml ${EXTRA_TEST_OPTIONS} ../Tests/Unit;
"
#!/usr/bin/env bash
# TYPO3 core test runner based on docker and docker-compose.
# Function to write a .env file in Build/docker
# This is read by docker-compose and vars defined here are
# used in .ci/docker/docker-compose.yml
# Function to write a .env file in Build/testing-docker
setUpDockerComposeDotEnv() {
[ -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
# 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
}
# Function to get the real path on mac os.
......@@ -35,16 +37,14 @@ Options:
-s <...>
Specifies which test suite to run
- build: Builds the project (composer)
- lint: Lints the php files
- functional: functional tests
- lint: Lints php and typoscript files. Also finds usages of debug calls.
- unit (default): PHP unit tests
- quality: executes code quality checks (phpstan, phpcs, phpmd)
- find-debugs: Finds usages of debug calls.
- fix: Fixes some quality errors automatically.
-p <7.2|7.3>
-p <7.2>
Specifies the PHP minor version to be used
- 7.2 (default): use PHP 7.2
- 7.3: use PHP 7.3
-e "<phpunit options>"
Only with -s functional|unit
......@@ -58,7 +58,7 @@ Options:
Examples:
# Run unit tests
./Build/Scripts/runTests.sh
.ci/scripts/console.sh -s build
EOF
# Test if docker-compose exists, else exit out with error
......@@ -73,10 +73,9 @@ 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
cd ../testing-docker || exit 1
cd ../docker || exit 1
# Option defaults
EXTENSION_KEY="$(basename $(realpath $PWD"/../../"))"
ROOT_DIR=$(realpath $PWD"/../../")
TEST_SUITE="unit"
PHP_VERSION="7.2"
......@@ -126,14 +125,11 @@ fi
# 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="${ROOT_DIR}/${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"
TEST_FILE="${ROOT_DIR}/tests/Unit"
;;
esac
fi
......@@ -152,27 +148,27 @@ lint)
SUITE_EXIT_CODE=$?
docker-compose down
;;
functional)
quality)
setUpDockerComposeDotEnv
docker-compose run functional
docker-compose run quality
SUITE_EXIT_CODE=$?
docker-compose down
;;
unit)
fix)
setUpDockerComposeDotEnv
docker-compose run unit
docker-compose run fix
SUITE_EXIT_CODE=$?
docker-compose down
;;
quality)
unit)
setUpDockerComposeDotEnv
docker-compose run quality
docker-compose run unit
SUITE_EXIT_CODE=$?
docker-compose down
;;
find-debugs)
functional)
setUpDockerComposeDotEnv
docker-compose run debugUsageCallCheck
docker-compose run functional
SUITE_EXIT_CODE=$?
docker-compose down
;;
......
; top-most EditorConfig file
root = true
; Unix-style newlines
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
[*.{php,html,typoscript,yml,yaml,xml}]
indent_style = space
indent_size = 4
max_line_length = 120
[*.{yml,yaml}]
indent_size = 2
[*.md]
max_line_length = 120
[COMMIT_EDITMSG]
max_line_length = 0
......@@ -9,4 +9,12 @@ yarn-error.log
.Build
Build/testing-docker/.env
Build/testing-docker/.database
.php_cs.cache
\ No newline at end of file
.php_cs.cache
.sass-cache
/yarn.lock
.Build/
.ci/docker/.env
.ci/docker/.database
var/
node_modules/
package-lock.json
......@@ -60,6 +60,16 @@ phpmd:
- master
allow_failure: true
psalm:
image: php:7.2-alpine
stage: quality
script:
- .Build/bin/psalm
only:
- merge_requests
- master
allow_failure: true
debug_call_usages:
image: php:7.2-alpine
stage: quality
......@@ -97,4 +107,4 @@ functionaltests:
.Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml "" .Build/Web/typo3conf/ext/${CI_PROJECT_NAME}/Tests/Functional
only:
- merge_requests
- master
\ No newline at end of file
- master
<?php
$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/Classes/',
__DIR__ . '/Tests/',
__DIR__ . '/Configuration/TCA/'
])
->exclude(__DIR__ . '/.Build/');
$header = <<<EOF
This file is part of the "rico_talentstorm" Extension for TYPO3 CMS.
For the full copyright and license information, please read the
LICENSE.txt file that was distributed with this source code.
(c) 2021 PSVneo
EOF;
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'@Symfony' => true,
'header_comment' => [
'header' => $header,
'location' => 'after_open',
'separate' => 'both',
'commentType' => 'PHPDoc',
],
'no_useless_else' => true,
'no_useless_return' => true,
'no_unused_imports' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'blank_line_after_opening_tag' => false,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => true,
'declare_strict_types' => true,
'psr4' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'semicolon_after_instruction' => true,
'align_multiline_comment' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ["author", "package"]],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
])
->setFinder($finder);
version: '2.3'
services:
#======================================================
# DB
#======================================================
db:
image: mysql:5.7
command: mysqld --character-set-server=utf8
environment:
MYSQL_ROOT_PASSWORD: funcp
volumes:
- .database:/var/lib/mysql
#======================================================
# Build
#======================================================
build:
image: composer:1.6.5
user: ${HOST_UID}
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 "
composer install;
"
#======================================================
# 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}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
if grep -rnw "Resources/Private/" "Classes/" -e "debug" -e "DebuggerUtility"; then
exit 1
fi
"
#======================================================
# Functional tests
#======================================================
functional:
image: riconet/typo3:9.5
user: ${HOST_UID}
links:
- db
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
- ${HOST_HOME}:${HOST_HOME}
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
environment:
typo3DatabaseName: func_test
typo3DatabaseUsername: root
typo3DatabasePassword: funcp
typo3DatabaseHost: db
working_dir: ${ROOT_DIR}/.Build
command: >
/bin/sh -c "
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: riconet/typo3:9.5
user: ${HOST_UID}
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
- ${HOST_HOME}:${HOST_HOME}
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
working_dir: ${ROOT_DIR}/.Build
command: >
/bin/sh -c "
php bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
"
\ No newline at end of file
File mode changed from 100644 to 100755
<?php
/**
* This file is part of the "rico_talentstorm" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2019 Wolf Utz <utz@riconet.de>, Hees riconet GmbH
* (c) 2021 PSVneo
*/
declare(strict_types=1);
......@@ -13,52 +14,31 @@ declare(strict_types=1);
namespace Riconet\RicoTalentstorm\Cache;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* This class provides an easy api to access the TYPO3 cache API.
*
* @author Wolf Utz <utz@riconet.de>
*
* @since 0.1.0
*/
class CacheProvider
class CacheProvider implements CacheProviderInterface
{
const DEFAULT_CACHE_LIFE_TIME = 86400;
/**
* @var CacheManager
*/
protected $cacheManager;
public function __construct(CacheManager $cacheManager)
{
$this->cacheManager = $cacheManager;
}
/**
* Gets an existing entry of the cache.
*
* @param string $cacheName
* @param string $identifier
*
* @return mixed
*
* @throws NoSuchCacheException
*
* @since 0.1.0
*/
public function getEntry(string $cacheName, string $identifier)
{
$cache = $this->getCache($cacheName);
$cache = $this->cacheManager->getCache($cacheName);
return $cache->get($identifier);
}
/**
* Sets a new cache entry.
*
* @param string $cacheName
* @param string $identifier
* @param mixed $entry
* @param array $tags
* @param int $lifetime
*
* @throws NoSuchCacheException
*
* @since 0.1.0
* @param mixed $entry
*/
public function setEntry(
string $cacheName,
......@@ -67,26 +47,7 @@ class CacheProvider
array $tags = [],
int $lifetime = self::DEFAULT_CACHE_LIFE_TIME
): void {
$cache = $this->getCache($cacheName);
$cache = $this->cacheManager->getCache($cacheName);
$cache->set($identifier, $entry, $tags, $lifetime);
}
/**
* Gets the cache object.
*
* @param string $cacheName
*
* @return FrontendInterface
*
* @throws NoSuchCacheException
*
* @since 0.1.0
*/
protected function getCache(string $cacheName): FrontendInterface
{
/** @var CacheManager $cacheManager */
$cacheManager = GeneralUtility::makeInstance(CacheManager::class);
return $cacheManager->getCache($cacheName);
}
}
<?php
/**
* This file is part of the "rico_talentstorm" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2021 PSVneo
*/
declare(strict_types=1);
namespace Riconet\RicoTalentstorm\Cache;
interface CacheProviderInterface
{
public const DEFAULT_CACHE_LIFE_TIME = 86400;
/**
* @return mixed
*/
public function getEntry(string $cacheName, string $identifier);
/**
* @param mixed $entry
*/
public function setEntry(
string $cacheName,
string $identifier,
$entry,
array $tags = [],
int $lifetime = self::DEFAULT_CACHE_LIFE_TIME
): void;
}
<?php
/**
* This file is part of the "rico_talentstorm" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2019 Wolf Utz <utz@riconet.de>, Hees riconet GmbH
* (c) 2021 PSVneo
*/
declare(strict_types=1);
namespace Riconet\RicoTalentstorm;
/**
* Constant class to receive magic constant values from.
*
* @author Wolf Utz <utz@riconet.de>
*