From 23e1a28286948d7b0bc4a8d7ca50461c4681d154 Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Thu, 15 Aug 2024 10:17:22 +0200 Subject: [PATCH 1/9] [TASK] Prepare version constraints for v13 --- composer.json | 8 +++++--- ext_emconf.php | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index b5b00b3..935ce13 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "sitegeist/image-jack", "type": "typo3-cms-extension", "homepage": "https://github.com/sitegeist/image-jack", + "version": "0.11.0", "license": [ "GPL-2.0-or-later" ], @@ -30,11 +31,12 @@ "issues": "https://github.com/sitegeist/image-jack/issues" }, "require": { - "php": ">=7.4.0", - "typo3/cms-core": "^11.5 || ^12.4" + + "php": ">=8.1.0", + "typo3/cms-core": "^12.4 || ^13.2" }, "require-dev": { - "typo3/testing-framework": "^6.0 || dev-main", + "typo3/testing-framework": "^8.0 || dev-main", "squizlabs/php_codesniffer": "^3.0", "editorconfig-checker/editorconfig-checker": "^10.0", "phpspec/prophecy-phpunit": "^2.0" diff --git a/ext_emconf.php b/ext_emconf.php index aeb4cda..9c23d1f 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,11 +9,11 @@ 'state' => 'beta', 'uploadfolder' => false, 'clearCacheOnLoad' => true, - 'version' => '0.10.0', + 'version' => '0.11.0', 'constraints' => [ 'depends' => [ - 'typo3' => '11.5.0-12.9.99', - 'php' => '7.4.0-8.2.99' + 'typo3' => '12.4.0-13.9.99', + 'php' => '8.1.0-8.3.99' ], 'conflicts' => [ ], From 1c3bb4976982fd18173719b8824452658371de55 Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Fri, 16 Aug 2024 07:14:12 +0200 Subject: [PATCH 2/9] [TASK] Add fixes for breaking changes in v13 --- .gitignore | 3 +- Classes/Command/ProcessQueueCommand.php | 6 ++-- Classes/EventListener/MimeTypeCacheParams.php | 36 +++++++++++++++++++ Classes/Templates/AvifTemplate.php | 20 +++++++---- Classes/Templates/JpegTemplate.php | 2 +- Classes/Templates/PngTemplate.php | 2 +- Classes/Templates/WebpTemplate.php | 19 ++++++---- ext_emconf.php | 2 +- ext_localconf.php | 9 +++-- 9 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 Classes/EventListener/MimeTypeCacheParams.php diff --git a/.gitignore b/.gitignore index 6a66962..39e123a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ composer.lock /var /Build/.phpunit.result.cache -/Build/testing-docker/.env \ No newline at end of file +/Build/testing-docker/.env +/vendor diff --git a/Classes/Command/ProcessQueueCommand.php b/Classes/Command/ProcessQueueCommand.php index 8b58f22..971729e 100644 --- a/Classes/Command/ProcessQueueCommand.php +++ b/Classes/Command/ProcessQueueCommand.php @@ -35,8 +35,10 @@ protected function configure() } /** - * @throws DBALException - * @throws Exception + * @param InputInterface $input + * @param OutputInterface $output + * @return int + * @throws \Doctrine\DBAL\Exception */ protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/Classes/EventListener/MimeTypeCacheParams.php b/Classes/EventListener/MimeTypeCacheParams.php new file mode 100644 index 0000000..ec9b806 --- /dev/null +++ b/Classes/EventListener/MimeTypeCacheParams.php @@ -0,0 +1,36 @@ +getRequest(); + $params = $event->getPageCacheIdentifierParameters(); + if ($request->hasHeader('accept')) { + $templates = array_filter($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['image_jack']['templates'], function ($template) { + return in_array(ConverterInterface::class, class_implements($template)); + }); + foreach ($templates as $template) { + $targetMimeType = $template::getTargetMimeType(); + if (RequestHelper::checkForMimeTypeInAcceptHeader($request, $targetMimeType)) { + $params['hashParameters']['accepts'][$targetMimeType] = true; + } + } + + $event->setPageCacheIdentifierParameters($params); + } + } +} diff --git a/Classes/Templates/AvifTemplate.php b/Classes/Templates/AvifTemplate.php index 949d6df..ea3a8ac 100644 --- a/Classes/Templates/AvifTemplate.php +++ b/Classes/Templates/AvifTemplate.php @@ -5,9 +5,11 @@ use TYPO3\CMS\Core\Imaging\GraphicalFunctions; use Psr\Log\LogLevel; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Resource\DuplicationBehavior; use TYPO3\CMS\Core\Utility\CommandUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Imaging\GifBuilder; class AvifTemplate extends AbstractTemplate implements TemplateInterface, ConverterInterface { @@ -72,7 +74,7 @@ public function processFile(): void try { $this->storage->addFile( $targetFile, - $this->image->getParentFolder(), + $this->image->getParentFolder(), /* @phpstan-ignore-line */ $this->image->getName() . '.avif', DuplicationBehavior::REPLACE ); @@ -108,14 +110,20 @@ protected function convertImageUsingIm(string $options, string $targetFile): str protected function convertImageUsingGd(string $quality, string $targetFile): bool { if (function_exists('imageavif') && defined('IMG_AVIF') && (imagetypes() & IMG_AVIF) === IMG_AVIF) { - $graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class); - $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath); + /** @var Typo3Version $version */ + $version = GeneralUtility::makeInstance(Typo3Version::class); + if ($version->getMajorVersion() == 13) { + $graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);/* @phpstan-ignore-line */ + } else { + $graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class); + } + $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);/* @phpstan-ignore-line */ // Convert CMYK to RGB - if (!imageistruecolor($image)) {/* @phpstan-ignore-line */ - imagepalettetotruecolor($image);/* @phpstan-ignore-line */ + if (!imageistruecolor($image)) { + imagepalettetotruecolor($image); } - return imageavif($image, $targetFile, (int)$quality);/* @phpstan-ignore-line */ + return imageavif($image, $targetFile, (int)$quality); } else { $this->logger->writeLog('Avif is not supported by your GD version', LogLevel::ERROR); } diff --git a/Classes/Templates/JpegTemplate.php b/Classes/Templates/JpegTemplate.php index 06b245e..edfa51d 100644 --- a/Classes/Templates/JpegTemplate.php +++ b/Classes/Templates/JpegTemplate.php @@ -43,7 +43,7 @@ public function processFile(): void try { $this->storage->addFile( $this->imagePath, - $this->image->getParentFolder(), + $this->image->getParentFolder(), /* @phpstan-ignore-line */ $this->image->getName(), DuplicationBehavior::REPLACE ); diff --git a/Classes/Templates/PngTemplate.php b/Classes/Templates/PngTemplate.php index a208623..71e22e4 100644 --- a/Classes/Templates/PngTemplate.php +++ b/Classes/Templates/PngTemplate.php @@ -43,7 +43,7 @@ public function processFile(): void try { $this->storage->addFile( $this->imagePath, - $this->image->getParentFolder(), + $this->image->getParentFolder(), /* @phpstan-ignore-line */ $this->image->getName(), DuplicationBehavior::REPLACE ); diff --git a/Classes/Templates/WebpTemplate.php b/Classes/Templates/WebpTemplate.php index 067492d..ad15257 100644 --- a/Classes/Templates/WebpTemplate.php +++ b/Classes/Templates/WebpTemplate.php @@ -5,9 +5,11 @@ use TYPO3\CMS\Core\Imaging\GraphicalFunctions; use Psr\Log\LogLevel; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Resource\DuplicationBehavior; use TYPO3\CMS\Core\Utility\CommandUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Imaging\GifBuilder; class WebpTemplate extends AbstractTemplate implements TemplateInterface, ConverterInterface { @@ -72,7 +74,7 @@ public function processFile(): void try { $this->storage->addFile( $targetFile, - $this->image->getParentFolder(), + $this->image->getParentFolder(), /* @phpstan-ignore-line */ $this->image->getName() . '.webp', DuplicationBehavior::REPLACE ); @@ -108,14 +110,19 @@ protected function convertImageUsingIm(string $options, string $targetFile): str protected function convertImageUsingGd(string $quality, string $targetFile): bool { if (function_exists('imagewebp') && defined('IMG_WEBP') && (imagetypes() & IMG_WEBP) === IMG_WEBP) { - $graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class); - $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath); + $version = GeneralUtility::makeInstance(Typo3Version::class); + if ($version->getMajorVersion() == 13) { + $graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);/* @phpstan-ignore-line */ + } else { + $graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class); + } + $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);/* @phpstan-ignore-line */ // Convert CMYK to RGB - if (!imageistruecolor($image)) {/* @phpstan-ignore-line */ - imagepalettetotruecolor($image);/* @phpstan-ignore-line */ + if (!imageistruecolor($image)) { + imagepalettetotruecolor($image); } - return imagewebp($image, $targetFile, (int)$quality);/* @phpstan-ignore-line */ + return imagewebp($image, $targetFile, (int)$quality); } else { $this->logger->writeLog('Webp is not supported by your GD version', LogLevel::ERROR); } diff --git a/ext_emconf.php b/ext_emconf.php index 9c23d1f..bbef0fe 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,5 +1,5 @@ 'Image Jack', 'description' => 'Jack of all trades concerning image optimization. Also introduces the usage of next-gen-image-formats', 'category' => 'misc', diff --git a/ext_localconf.php b/ext_localconf.php index 057f088..caa0973 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -8,7 +8,9 @@ use Sitegeist\ImageJack\Templates\AvifTemplate; use Sitegeist\ImageJack\Xclass\AmazonS3Driver; use Sitegeist\ImageJack\Xclass\LocalDriver; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Log\Writer\FileWriter; +use TYPO3\CMS\Core\Utility\GeneralUtility; defined('TYPO3') || die(); @@ -54,7 +56,10 @@ ]; } - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = - TsfeHook::class . '->postProcessHashBase'; + $version = GeneralUtility::makeInstance(Typo3Version::class); + if ($version->getMajorVersion() < 13) { + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = + TsfeHook::class . '->postProcessHashBase'; + } } }); From 052dd04dff7f367e2167fcc704247dcff083120a Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Fri, 16 Aug 2024 07:14:36 +0200 Subject: [PATCH 3/9] [TASK] Refactor coda quality check --- .ecrc | 46 +-- .github/workflows/test.yml | 153 ++-------- Build/Scripts/runTests.sh | 304 ------------------- Build/Testing/FunctionalTests.xml | 28 -- Build/Testing/FunctionalTestsBootstrap.php | 20 -- Build/Testing/UnitTests.xml | 30 -- Build/Testing/UnitTestsBootstrap.php | 75 ----- Build/Testing/phpstan.neon | 5 +- Build/testing-docker/docker-compose.yml | 332 --------------------- composer.json | 32 +- 10 files changed, 69 insertions(+), 956 deletions(-) delete mode 100755 Build/Scripts/runTests.sh delete mode 100644 Build/Testing/FunctionalTests.xml delete mode 100644 Build/Testing/FunctionalTestsBootstrap.php delete mode 100644 Build/Testing/UnitTests.xml delete mode 100644 Build/Testing/UnitTestsBootstrap.php delete mode 100644 Build/testing-docker/docker-compose.yml diff --git a/.ecrc b/.ecrc index 07fbac9..f5b89c7 100644 --- a/.ecrc +++ b/.ecrc @@ -1,22 +1,28 @@ { - "Verbose": false, - "Debug": false, - "IgnoreDefaults": false, - "SpacesAftertabs": false, - "NoColor": false, - "Exclude": [ - ".Build", - ".git", - ".DS_Store", - ".xsd", - "var/" - ], - "AllowedContentTypes": [], - "PassedFiles": [], - "Disable": { - "EndOfLine": false, - "Indentation": false, - "InsertFinalNewline": false, - "TrimTrailingWhitespace": false - } + "Verbose": false, + "Debug": false, + "IgnoreDefaults": false, + "SpacesAftertabs": false, + "NoColor": false, + "Exclude": [ + "\\.git", + "\\.sql$", + "\\.DS_Store", + "\\.rst", + "\\.idea", + "\\.vscode", + "\\.phar$", + "\\.php_cs\\.cache", + "\\.json", + "vendor", + ".composer_cache" + ], + "AllowedContentTypes": [], + "PassedFiles": [], + "Disable": { + "EndOfLine": false, + "Indentation": false, + "InsertFinalNewline": false, + "TrimTrailingWhitespace": false + } } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8365754..f986afe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,142 +3,37 @@ name: tests on: [ push, pull_request ] jobs: -# phpstan: -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v2 -# - uses: php-actions/composer@v5 -# -# - name: PHPStan Static Analysis -# uses: php-actions/phpstan@master -# with: -# path: Classes/ + phpstan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: php-actions/composer@v6 + - uses: php-actions/phpstan@v3 + with: + configuration: ./Build/Testing/phpstan.neon + path: . phpcs: name: phpcs runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Validate composer.json - run: Build/Scripts/runTests.sh -s composerValidate + - name: Composer install + uses: php-actions/composer@v6 - - name: Cache composer dependencies - uses: actions/cache@v1 + - name: PHP Code Sniffer + uses: php-actions/phpcs@v1 with: - path: ~/.composer/cache - key: composer - - - name: Install composer dependencies - run: Build/Scripts/runTests.sh -s composerInstall - - - name: PHP Linting - run: Build/Scripts/runTests.sh -s lintPhp + php_version: 8.1 + ignore: /vendor/ + path: . + standard: PSR2 + extensions: php + warning_severity: 6 editorconfig: - name: editorconfig - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 - - - name: Validate composer.json - run: Build/Scripts/runTests.sh -s composerValidate - - - name: Cache composer dependencies - uses: actions/cache@v1 - with: - path: ~/.composer/cache - key: composer - - - name: Install composer dependencies - run: Build/Scripts/runTests.sh -s composerInstall - - - name: Editorconfig Linting - run: Build/Scripts/runTests.sh -s lintEditorconfig - - -# unittest: -# runs-on: ubuntu-latest -# -# strategy: -# max-parallel: 2 -# matrix: -# php-versions: [7.4, 8.0, 8.1] -# typo3-versions: [10, 11, 12] -# exclude: -# - -# php-versions: '8.0' -# typo3-versions: 10 -# - -# php-versions: '8.1' -# typo3-versions: 10 -# - -# php-versions: '7.4' -# typo3-versions: 12 -# -# name: Unit (PHP ${{ matrix.php-versions }}, TYPO3 ${{ matrix.typo3-versions }}) -# steps: -# - -# uses: actions/checkout@v2 -# -# - -# name: Validate composer.json -# run: Build/Scripts/runTests.sh -p ${{ matrix.php-versions }} -t ${{ matrix.typo3-versions }} -s composerValidate -# -# - -# name: Cache composer dependencies -# uses: actions/cache@v1 -# with: -# path: ~/.composer/cache -# key: php-${{ matrix.php-versions }}-typo3-${{ matrix.typo3-versions }} -# -# - -# name: Install composer dependencies -# run: Build/Scripts/runTests.sh -p ${{ matrix.php-versions }} -t ${{ matrix.typo3-versions }} -s composerInstall -# -# - -# name: Automated Unit Testing -# run: Build/Scripts/runTests.sh -p ${{ matrix.php-versions }} -t ${{ matrix.typo3-versions }} -s unit -# -# -# functionaltest: -# runs-on: ubuntu-latest -# -# strategy: -# max-parallel: 2 -# matrix: -# php-versions: [ 7.4, 8.0, 8.1 ] -# typo3-versions: [ 10, 11, 12 ] -# exclude: -# - -# php-versions: '8.0' -# typo3-versions: 10 -# - -# php-versions: '8.1' -# typo3-versions: 10 -# - -# php-versions: '7.4' -# typo3-versions: 12 -# -# name: Functional (PHP ${{ matrix.php-versions }}, TYPO3 ${{ matrix.typo3-versions }}) -# steps: -# - -# uses: actions/checkout@v2 -# -# - -# name: Validate composer.json -# run: Build/Scripts/runTests.sh -p ${{ matrix.php-versions }} -t ${{ matrix.typo3-versions }} -s composerValidate -# -# - -# name: Cache composer dependencies -# uses: actions/cache@v1 -# with: -# path: ~/.composer/cache -# key: php-${{ matrix.php-versions }}-typo3-${{ matrix.typo3-versions }} -# -# - -# name: Install composer dependencies -# run: Build/Scripts/runTests.sh -p ${{ matrix.php-versions }} -t ${{ matrix.typo3-versions }} -s composerInstall -# -# - -# name: Automated Functional Testing -# run: Build/Scripts/runTests.sh -p ${{ matrix.php-versions }} -t ${{ matrix.typo3-versions }} -s functional + - uses: actions/checkout@v4 + - uses: editorconfig-checker/action-editorconfig-checker@main + - run: editorconfig-checker diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh deleted file mode 100755 index 30a8c8b..0000000 --- a/Build/Scripts/runTests.sh +++ /dev/null @@ -1,304 +0,0 @@ -#!/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 -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 "PHP_VERSION=${PHP_VERSION}" >> .env - echo "TYPO3_VERSION=${TYPO3_VERSION}" >> .env - echo "DOCKER_PHP_IMAGE=${DOCKER_PHP_IMAGE}" >> .env - echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}" >> .env - echo "SCRIPT_VERBOSE=${SCRIPT_VERBOSE}" >> .env -} - -# Load help text into $HELP -read -r -d '' HELP < - Specifies which test suite to run - - composerInstall: "composer install" - - composerInstallMax: "composer update", with no platform.php config. - - composerInstallMin: "composer update --prefer-lowest", with platform.php set to PHP version x.x.0. - - composerValidate: "composer validate" - - lintPhp: PHP linting - - lintEditorconfig: Editorconfig linting - - unit (default): PHP unit tests - - functional: functional tests - - -d - Only with -s functional - Specifies on which DBMS tests are performed - - mariadb (default): use mariadb - - mssql: use mssql microsoft sql server - - postgres: use postgres - - sqlite: use sqlite - - -p <7.4|8.0|8.1> - Specifies the PHP minor version to be used - - 7.4: use PHP 7.4 - - 8.0: use PHP 8.0 - - 8.1 (default): use PHP 8.1 - - -t <10|11|12> - Specifies the TYPO3 version to be used - - 10: use TYPO3 10 - - 11 (default): use TYPO3 11 - - 12: use TYPO3 12 - - -e "" - Only with -s functional|unit - Additional options to send to phpunit tests. - For phpunit, options starting with "--" must be added after options starting with "-". - Example -e "-v --filter canRetrieveValueWithGP" to enable verbose output AND filter tests - named "canRetrieveValueWithGP" - - -x - Only with -s 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 9003. A different port - can be selected with -y - - -y - Send xdebug information to a different port than default 9003 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.4 - ./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 - 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 )" -cd "$THIS_SCRIPT_DIR" || exit 1 - -# Go to directory that contains the local docker-compose.yml file -cd ../testing-docker || exit 1 - -# Option defaults -if ! command -v realpath &> /dev/null; then - echo "Consider installing realpath for properly resolving symlinks" >&2 - ROOT_DIR="${PWD}/../../" -else - ROOT_DIR=`realpath ${PWD}/../../` -fi -TEST_SUITE="unit" -DBMS="mariadb" -PHP_VERSION="8.1" -TYPO3_VERSION="11" -PHP_XDEBUG_ON=0 -PHP_XDEBUG_PORT=9003 -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=(); -# Simple option parsing based on getopts (! not getopt) -while getopts ":s:d:p:e:t:xy:huv" OPT; do - case ${OPT} in - s) - TEST_SUITE=${OPTARG} - ;; - d) - DBMS=${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 - ;; - t) - TYPO3_VERSION=${OPTARG} - ;; - \?) - 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 -fi - -# Move "7.4" to "php74", 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/image_jack/${1}" -fi - -if [ ${SCRIPT_VERBOSE} -eq 1 ]; then - set -x -fi - -# Suite execution -case ${TEST_SUITE} in - composerInstall) - setUpDockerComposeDotEnv - docker-compose run composer_install - SUITE_EXIT_CODE=$? - docker-compose down - ;; - composerInstallMax) - setUpDockerComposeDotEnv - docker-compose run composer_install_max - SUITE_EXIT_CODE=$? - docker-compose down - ;; - composerInstallMin) - setUpDockerComposeDotEnv - docker-compose run composer_install_min - SUITE_EXIT_CODE=$? - docker-compose down - ;; - composerValidate) - setUpDockerComposeDotEnv - docker-compose run composer_validate - SUITE_EXIT_CODE=$? - docker-compose down - ;; - functional) - setUpDockerComposeDotEnv - case ${DBMS} in - mariadb) - docker-compose run functional_mariadb10 - SUITE_EXIT_CODE=$? - ;; - mssql) - docker-compose run functional_mssql2019latest - SUITE_EXIT_CODE=$? - ;; - postgres) - docker-compose run functional_postgres10 - SUITE_EXIT_CODE=$? - ;; - sqlite) - # sqlite has a tmpfs as .Build/Web/typo3temp/var/tests/functional-sqlite-dbs/ - # Since docker is executed as root (yay!), the path to this dir is owned by - # root if docker creates it. Thank you, docker. We create the path beforehand - # to avoid permission issues. - mkdir -p ${ROOT_DIR}/.Build/Web/typo3temp/var/tests/functional-sqlite-dbs/ - docker-compose run functional_sqlite - SUITE_EXIT_CODE=$? - ;; - *) - echo "Invalid -d option argument ${DBMS}" >&2 - echo >&2 - echo "${HELP}" >&2 - exit 1 - esac - docker-compose down - ;; - lintPhp) - setUpDockerComposeDotEnv - docker-compose run lint_php - SUITE_EXIT_CODE=$? - docker-compose down - ;; - lintEditorconfig) - setUpDockerComposeDotEnv - docker-compose run lint_editorconfig - SUITE_EXIT_CODE=$? - docker-compose down - ;; - unit) - setUpDockerComposeDotEnv - docker-compose run unit - SUITE_EXIT_CODE=$? - docker-compose down - ;; - update) - # pull typo3/core-testing-*:latest versions of those ones that exist locally - docker images typo3/core-testing-*:latest --format "{{.Repository}}:latest" | xargs -I {} docker pull {} - # remove "dangling" typo3/core-testing-* images (those tagged as ) - docker images typo3/core-testing-* --filter "dangling=true" --format "{{.ID}}" | xargs -I {} docker rmi {} - ;; - *) - echo "Invalid -s option argument ${TEST_SUITE}" >&2 - echo >&2 - echo "${HELP}" >&2 - exit 1 -esac - -exit $SUITE_EXIT_CODE diff --git a/Build/Testing/FunctionalTests.xml b/Build/Testing/FunctionalTests.xml deleted file mode 100644 index ded3940..0000000 --- a/Build/Testing/FunctionalTests.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - ../../Tests/Functional/ - - - - - - - - diff --git a/Build/Testing/FunctionalTestsBootstrap.php b/Build/Testing/FunctionalTestsBootstrap.php deleted file mode 100644 index 443197d..0000000 --- a/Build/Testing/FunctionalTestsBootstrap.php +++ /dev/null @@ -1,20 +0,0 @@ -defineOriginalRootPath(); - $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests'); - $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient'); -}); diff --git a/Build/Testing/UnitTests.xml b/Build/Testing/UnitTests.xml deleted file mode 100644 index d71bb3f..0000000 --- a/Build/Testing/UnitTests.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - ../../Tests/Unit/ - - - - - - - - diff --git a/Build/Testing/UnitTestsBootstrap.php b/Build/Testing/UnitTestsBootstrap.php deleted file mode 100644 index b3d535e..0000000 --- a/Build/Testing/UnitTestsBootstrap.php +++ /dev/null @@ -1,75 +0,0 @@ -getWebRoot(), '/')); - } - if (!getenv('TYPO3_PATH_WEB')) { - putenv('TYPO3_PATH_WEB=' . rtrim($testbase->getWebRoot(), '/')); - } - - $testbase->defineSitePath(); - - $requestType = \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE | \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI; - \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(0, $requestType); - - $testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3conf/ext'); - $testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/assets'); - $testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/tests'); - $testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/transient'); - - // Retrieve an instance of class loader and inject to core bootstrap - $classLoader = require $testbase->getPackagesPath() . '/autoload.php'; - \TYPO3\CMS\Core\Core\Bootstrap::initializeClassLoader($classLoader); - - // Initialize default TYPO3_CONF_VARS - $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager(); - $GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration(); - - $cache = new \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend( - 'core', - new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production', []) - ); - - // Set all packages to active - if (interface_exists(\TYPO3\CMS\Core\Package\Cache\PackageCacheInterface::class)) { - $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager( - \TYPO3\CMS\Core\Package\UnitTestPackageManager::class, - \TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache) - ); - } else { - // v10 compatibility layer - $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager( - \TYPO3\CMS\Core\Package\UnitTestPackageManager::class, - $cache - ); - } - - \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager); - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager); - - $testbase->dumpClassLoadingInformation(); - - \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances(); -}); diff --git a/Build/Testing/phpstan.neon b/Build/Testing/phpstan.neon index d834c0a..056631c 100644 --- a/Build/Testing/phpstan.neon +++ b/Build/Testing/phpstan.neon @@ -1,5 +1,5 @@ includes: - - ../../.Build/vendor/saschaegerer/phpstan-typo3/extension.neon + - ../../vendor/saschaegerer/phpstan-typo3/extension.neon parameters: level: 5 @@ -7,3 +7,6 @@ parameters: - */.Build/* - */Tests/* - */node_modules/* + - */vendor/* + - */Classes/Xclass/AmazonS3Driver.php + - */Classes/EventListener/MimeTypeCacheParams.php diff --git a/Build/testing-docker/docker-compose.yml b/Build/testing-docker/docker-compose.yml deleted file mode 100644 index e368254..0000000 --- a/Build/testing-docker/docker-compose.yml +++ /dev/null @@ -1,332 +0,0 @@ -version: '2.3' -services: - mariadb10: - image: mariadb:10 - environment: - MYSQL_ROOT_PASSWORD: funcp - tmpfs: - - /var/lib/mysql/:rw,noexec,nosuid - - mssql2019latest: - image: typo3/core-testing-mssql2019:latest - environment: - ACCEPT_EULA: Y - SA_PASSWORD: "Test1234!" - MSSQL_PID: Developer - - postgres10: - image: postgres:10-alpine - environment: - POSTGRES_PASSWORD: funcp - POSTGRES_USER: ${HOST_USER} - tmpfs: - - /var/lib/postgresql/data:rw,noexec,nosuid - - composer_install: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - 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 " - if [ ${SCRIPT_VERBOSE} -eq 1 ]; then - set -x - fi - composer config allow-plugins.typo3/class-alias-loader true - composer config allow-plugins.typo3/cms-composer-installers true - composer require typo3/minimal "^${TYPO3_VERSION}" --prefer-dist --no-progress --no-suggest - composer install --no-progress --no-interaction; - " - composer_install_max: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - 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 " - if [ ${SCRIPT_VERBOSE} -eq 1 ]; then - set -x - fi - composer config allow-plugins.typo3/class-alias-loader true - composer config allow-plugins.typo3/cms-composer-installers true - composer req typo3/cms-core:"^${TYPO3_VERSION}" \ - typo3/cms-backend:"^${TYPO3_VERSION}" \ - typo3/cms-frontend:"^${TYPO3_VERSION}" \ - typo3/cms-extbase:"^${TYPO3_VERSION}" \ - typo3/cms-fluid:"^${TYPO3_VERSION}" \ - typo3/cms-recordlist:"^${TYPO3_VERSION}" \ - typo3/cms-install:"^${TYPO3_VERSION}" - composer config --unset platform.php; - composer update --no-progress --no-interaction; - composer dumpautoload; - " - - composer_install_min: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - 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 " - if [ ${SCRIPT_VERBOSE} -eq 1 ]; then - set -x - fi - composer config allow-plugins.typo3/class-alias-loader true - composer config allow-plugins.typo3/cms-composer-installers true - composer req typo3/cms-core:"^${TYPO3_VERSION}" \ - typo3/cms-backend:"^${TYPO3_VERSION}" \ - typo3/cms-frontend:"^${TYPO3_VERSION}" \ - typo3/cms-extbase:"^${TYPO3_VERSION}" \ - typo3/cms-fluid:"^${TYPO3_VERSION}" \ - typo3/cms-recordlist:"^${TYPO3_VERSION}" \ - typo3/cms-install:"^${TYPO3_VERSION}" - composer config platform.php ${PHP_VERSION}.0; - composer update --prefer-lowest --no-progress --no-interaction; - composer dumpautoload; - " - - composer_validate: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - 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 " - if [ ${SCRIPT_VERBOSE} -eq 1 ]; then - set -x - fi - composer validate; - " - - functional_mariadb10: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - user: ${HOST_UID} - links: - - mariadb10 - 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: mariadb10 - 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 - XDEBUG_MODE=\"off\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; - else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; - fi - " - - functional_mssql2019latest: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - user: ${HOST_UID} - links: - - mssql2019latest - volumes: - - ${ROOT_DIR}:${ROOT_DIR} - - ${HOST_HOME}:${HOST_HOME} - - /etc/passwd:/etc/passwd:ro - - /etc/group:/etc/group:ro - environment: - typo3DatabaseDriver: sqlsrv - typo3DatabaseName: func - typo3DatabasePassword: "Test1234!" - typo3DatabaseUsername: SA - typo3DatabasePort: 1433 - typo3DatabaseCharset: utf-8 - typo3DatabaseHost: mssql2019latest - 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 mssql2019latest 1433; do - sleep 1; - done; - sleep 5; - echo Database is up; - php -v | grep '^PHP'; - if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-mssql ${TEST_FILE}; - else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-mssql ${TEST_FILE}; - fi - " - - functional_postgres10: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - user: ${HOST_UID} - links: - - postgres10 - volumes: - - ${ROOT_DIR}:${ROOT_DIR} - - ${HOST_HOME}:${HOST_HOME} - - /etc/passwd:/etc/passwd:ro - - /etc/group:/etc/group:ro - environment: - typo3DatabaseDriver: pdo_pgsql - typo3DatabaseName: bamboo - typo3DatabaseUsername: ${HOST_USER} - typo3DatabaseHost: postgres10 - typo3DatabasePassword: funcp - 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 postgres10 5432; do - sleep 1; - done; - echo Database is up; - php -v | grep '^PHP'; - if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-postgres ${TEST_FILE}; - else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-postgres ${TEST_FILE}; - fi - " - - functional_sqlite: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - user: ${HOST_UID} - volumes: - - ${ROOT_DIR}:${ROOT_DIR} - - ${HOST_HOME}:${HOST_HOME} - - /etc/passwd:/etc/passwd:ro - - /etc/group:/etc/group:ro - tmpfs: - - ${ROOT_DIR}/.Build/Web/typo3temp/var/tests/functional-sqlite-dbs/:rw,noexec,nosuid,uid=${HOST_UID} - environment: - typo3DatabaseDriver: pdo_sqlite - 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 - XDEBUG_MODE=\"off\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-sqlite ${TEST_FILE}; - else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-sqlite ${TEST_FILE}; - fi - " - - lint_php: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - user: ${HOST_UID} - volumes: - - ${ROOT_DIR}:${ROOT_DIR} - - /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 - php -v | grep '^PHP'; - .Build/bin/phpcs --version; - .Build/bin/phpcs -p --standard=PSR2 --extensions=php --exclude=Generic.Files.LineLength --ignore=.Build,Tests,ext_emconf.php . - " - - lint_editorconfig: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - user: ${HOST_UID} - volumes: - - ${ROOT_DIR}:${ROOT_DIR} - - /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 - php -v | grep '^PHP'; - echo -n 'ec version: '; - .Build/bin/ec -version; - .Build/bin/ec -exclude .phpunit.result.cache . - " - - unit: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - 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 " - if [ ${SCRIPT_VERBOSE} -eq 1 ]; then - set -x - fi - php -v | grep '^PHP' - if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; - else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ - bin/phpunit -c Web/typo3conf/ext/image_jack/Build/Testing/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; - fi - " diff --git a/composer.json b/composer.json index 935ce13..d7b79d7 100644 --- a/composer.json +++ b/composer.json @@ -31,29 +31,21 @@ "issues": "https://github.com/sitegeist/image-jack/issues" }, "require": { - "php": ">=8.1.0", "typo3/cms-core": "^12.4 || ^13.2" }, "require-dev": { - "typo3/testing-framework": "^8.0 || dev-main", - "squizlabs/php_codesniffer": "^3.0", - "editorconfig-checker/editorconfig-checker": "^10.0", - "phpspec/prophecy-phpunit": "^2.0" + "editorconfig-checker/editorconfig-checker": "*", + "phpstan/phpstan": "^1.10", + "saschaegerer/phpstan-typo3": "^1.9", + "squizlabs/php_codesniffer": "*" }, "autoload": { "psr-4": { "Sitegeist\\ImageJack\\": "Classes" } }, - "autoload-dev": { - "psr-4": { - "Sitegeist\\ImageJack\\Tests\\": "Tests" - } - }, "config": { - "vendor-dir": ".Build/vendor", - "bin-dir": ".Build/bin", "allow-plugins": { "typo3/cms-composer-installers": true, "typo3/class-alias-loader": true @@ -62,17 +54,23 @@ "extra": { "typo3/cms": { "cms-package-dir": "{$vendor-dir}/typo3/cms", - "app-dir": ".Build", - "web-dir": ".Build/Web", "extension-key": "image_jack" } }, "scripts": { - "post-autoload-dump": [ - "TYPO3\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare" - ], "prepare-release": [ "rm -r .github .ecrc .editorconfig .gitattributes .gitignore Build Tests" + ], + "lint": [ + "@lint:php", + "@lint:editorconfig" + ], + "lint:php": [ + "php -d memory_limit=-1 ./vendor/bin/phpstan analyse --configuration=./Build/Testing/phpstan.neon .", + "phpcs --standard=PSR2 --extensions=php --warning-severity=6 --ignore=/vendor/ ." + ], + "lint:editorconfig": [ + "ec ." ] } } From 59eca5fd0287213de52a613a3e5e82efa4555a28 Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Fri, 16 Aug 2024 07:27:32 +0200 Subject: [PATCH 4/9] [TASK] Add php-cs-fixer --- Build/Testing/.php_cs.php | 75 +++++++++++++++++++++++++++++++++++++++ composer.json | 13 ++++++- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Build/Testing/.php_cs.php diff --git a/Build/Testing/.php_cs.php b/Build/Testing/.php_cs.php new file mode 100644 index 0000000..3d59b19 --- /dev/null +++ b/Build/Testing/.php_cs.php @@ -0,0 +1,75 @@ +in(__DIR__ . '/../../'); + +// Return a Code Sniffing configuration using +// all sniffers needed for PSR-2 +// and additionally: +// - Remove leading slashes in use clauses. +// - PHP single-line arrays should not have trailing comma. +// - Single-line whitespace before closing semicolon are prohibited. +// - Remove unused use statements in the PHP source code +// - Ensure Concatenation to have at least one whitespace around +// - Remove trailing whitespace at the end of blank lines. +return (new PhpCsFixer\Config) + ->setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + '@DoctrineAnnotation' => true, + 'no_leading_import_slash' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_unused_imports' => true, + 'concat_space' => ['spacing' => 'one'], + 'no_whitespace_in_blank_line' => true, + 'ordered_imports' => true, + 'single_quote' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'phpdoc_no_package' => true, + 'phpdoc_scalar' => true, + 'no_blank_lines_after_phpdoc' => true, + 'array_syntax' => ['syntax' => 'short'], + 'whitespace_after_comma_in_array' => true, + 'function_typehint_space' => true, + 'single_line_comment_style' => true, + 'no_alias_functions' => true, + 'lowercase_cast' => true, + 'no_leading_namespace_whitespace' => true, + 'native_function_casing' => true, + 'no_short_bool_cast' => true, + 'no_unneeded_control_parentheses' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_trim' => true, + 'no_superfluous_elseif' => true, + 'no_useless_else' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], + 'return_type_declaration' => ['space_before' => 'none'], + 'cast_spaces' => ['space' => 'none'], + 'declare_equal_normalize' => ['space' => 'single'], + 'dir_constant' => true, + ]) + ->setFinder($finder); diff --git a/composer.json b/composer.json index d7b79d7..e733c5f 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "editorconfig-checker/editorconfig-checker": "*", "phpstan/phpstan": "^1.10", "saschaegerer/phpstan-typo3": "^1.9", - "squizlabs/php_codesniffer": "*" + "squizlabs/php_codesniffer": "*", + "friendsofphp/php-cs-fixer": "^3.62" }, "autoload": { "psr-4": { @@ -71,6 +72,16 @@ ], "lint:editorconfig": [ "ec ." + ], + "fix": [ + "@fix:php", + "@fix:editorconfig" + ], + "fix:php": [ + "php-cs-fixer fix --diff --config ./Build/Testing/.php_cs.php" + ], + "fix:editorconfig": [ + "ec --auto-fix --exclude 'Resources\\/Public\\/|package-lock.json|mask.json|LICENSE' ." ] } } From b24d082e20c1d14b7baaa0535da7eac50fbe19b3 Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Fri, 16 Aug 2024 07:29:07 +0200 Subject: [PATCH 5/9] [TASK] Some minor code improvements --- Classes/Command/ProcessQueueCommand.php | 4 +--- Classes/EventListener/MimeTypeCacheParams.php | 2 +- Classes/Processor/ImageJackProcessor.php | 3 ++- Classes/Runner/TemplateRunner.php | 4 ++-- Classes/Templates/AbstractTemplate.php | 2 +- Classes/Templates/AvifTemplate.php | 15 +++++++-------- Classes/Templates/ConverterInterface.php | 2 +- Classes/Templates/JpegTemplate.php | 6 +++--- Classes/Templates/PngTemplate.php | 4 ++-- Classes/Templates/TemplateInterface.php | 2 +- Classes/Templates/WebpTemplate.php | 15 +++++++-------- Classes/Utility/LoggerUtility.php | 3 +-- ext_localconf.php | 2 +- 13 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Classes/Command/ProcessQueueCommand.php b/Classes/Command/ProcessQueueCommand.php index 971729e..28c9d6f 100644 --- a/Classes/Command/ProcessQueueCommand.php +++ b/Classes/Command/ProcessQueueCommand.php @@ -1,10 +1,8 @@ getTargetFile(); + /** @var TemplateRunner $templateRunner */ $templateRunner = GeneralUtility::makeInstance(TemplateRunner::class, $processedFile); $templateRunner->run(); diff --git a/Classes/Runner/TemplateRunner.php b/Classes/Runner/TemplateRunner.php index fc31e57..75f4ad7 100644 --- a/Classes/Runner/TemplateRunner.php +++ b/Classes/Runner/TemplateRunner.php @@ -1,10 +1,10 @@ image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive()); + return in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive(); } public function getSupportedMimeTypes(): array @@ -74,7 +74,7 @@ public function processFile(): void try { $this->storage->addFile( $targetFile, - $this->image->getParentFolder(), /* @phpstan-ignore-line */ + $this->image->getParentFolder(), // @phpstan-ignore-line $this->image->getName() . '.avif', DuplicationBehavior::REPLACE ); @@ -113,20 +113,19 @@ protected function convertImageUsingGd(string $quality, string $targetFile): boo /** @var Typo3Version $version */ $version = GeneralUtility::makeInstance(Typo3Version::class); if ($version->getMajorVersion() == 13) { - $graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);/* @phpstan-ignore-line */ + $graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);// @phpstan-ignore-line } else { $graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class); } - $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);/* @phpstan-ignore-line */ + $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);// @phpstan-ignore-line // Convert CMYK to RGB if (!imageistruecolor($image)) { imagepalettetotruecolor($image); } return imageavif($image, $targetFile, (int)$quality); - } else { - $this->logger->writeLog('Avif is not supported by your GD version', LogLevel::ERROR); } + $this->logger->writeLog('Avif is not supported by your GD version', LogLevel::ERROR); return false; } diff --git a/Classes/Templates/ConverterInterface.php b/Classes/Templates/ConverterInterface.php index 3703653..8c1eb25 100644 --- a/Classes/Templates/ConverterInterface.php +++ b/Classes/Templates/ConverterInterface.php @@ -1,5 +1,5 @@ image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive()); + return in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive(); } public function getSupportedMimeTypes(): array @@ -43,7 +43,7 @@ public function processFile(): void try { $this->storage->addFile( $this->imagePath, - $this->image->getParentFolder(), /* @phpstan-ignore-line */ + $this->image->getParentFolder(), // @phpstan-ignore-line $this->image->getName(), DuplicationBehavior::REPLACE ); diff --git a/Classes/Templates/PngTemplate.php b/Classes/Templates/PngTemplate.php index 71e22e4..8eb1fec 100644 --- a/Classes/Templates/PngTemplate.php +++ b/Classes/Templates/PngTemplate.php @@ -1,5 +1,5 @@ storage->addFile( $this->imagePath, - $this->image->getParentFolder(), /* @phpstan-ignore-line */ + $this->image->getParentFolder(), // @phpstan-ignore-line $this->image->getName(), DuplicationBehavior::REPLACE ); diff --git a/Classes/Templates/TemplateInterface.php b/Classes/Templates/TemplateInterface.php index ae2f63a..18cf0fa 100644 --- a/Classes/Templates/TemplateInterface.php +++ b/Classes/Templates/TemplateInterface.php @@ -1,5 +1,5 @@ image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive()); + return in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive(); } public function getSupportedMimeTypes(): array @@ -74,7 +74,7 @@ public function processFile(): void try { $this->storage->addFile( $targetFile, - $this->image->getParentFolder(), /* @phpstan-ignore-line */ + $this->image->getParentFolder(), // @phpstan-ignore-line $this->image->getName() . '.webp', DuplicationBehavior::REPLACE ); @@ -112,20 +112,19 @@ protected function convertImageUsingGd(string $quality, string $targetFile): boo if (function_exists('imagewebp') && defined('IMG_WEBP') && (imagetypes() & IMG_WEBP) === IMG_WEBP) { $version = GeneralUtility::makeInstance(Typo3Version::class); if ($version->getMajorVersion() == 13) { - $graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);/* @phpstan-ignore-line */ + $graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);// @phpstan-ignore-line } else { $graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class); } - $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);/* @phpstan-ignore-line */ + $image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);// @phpstan-ignore-line // Convert CMYK to RGB if (!imageistruecolor($image)) { imagepalettetotruecolor($image); } return imagewebp($image, $targetFile, (int)$quality); - } else { - $this->logger->writeLog('Webp is not supported by your GD version', LogLevel::ERROR); } + $this->logger->writeLog('Webp is not supported by your GD version', LogLevel::ERROR); return false; } diff --git a/Classes/Utility/LoggerUtility.php b/Classes/Utility/LoggerUtility.php index 82b4aae..730b994 100644 --- a/Classes/Utility/LoggerUtility.php +++ b/Classes/Utility/LoggerUtility.php @@ -1,5 +1,5 @@ Date: Fri, 16 Aug 2024 07:36:45 +0200 Subject: [PATCH 6/9] [TASK] Add intl extension to composer action --- .github/workflows/test.yml | 8 +++++++- .gitignore | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f986afe..dd62b80 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: php-actions/composer@v6 + with: + php_version: 8.2 + php_extensions: intl - uses: php-actions/phpstan@v3 with: configuration: ./Build/Testing/phpstan.neon @@ -20,11 +23,14 @@ jobs: - name: Composer install uses: php-actions/composer@v6 + with: + php_version: 8.2 + php_extensions: intl - name: PHP Code Sniffer uses: php-actions/phpcs@v1 with: - php_version: 8.1 + php_version: 8.2 ignore: /vendor/ path: . standard: PSR2 diff --git a/.gitignore b/.gitignore index 39e123a..e61477d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.lock /Build/.phpunit.result.cache /Build/testing-docker/.env /vendor +.php-cs-fixer.cache From 9a9a8886d10234bd1250082224e328daebab61a5 Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Fri, 16 Aug 2024 09:19:38 +0200 Subject: [PATCH 7/9] [TASK] Only use hash event listener when fallback option is active --- Classes/EventListener/MimeTypeCacheParams.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Classes/EventListener/MimeTypeCacheParams.php b/Classes/EventListener/MimeTypeCacheParams.php index b05679d..f999ba6 100644 --- a/Classes/EventListener/MimeTypeCacheParams.php +++ b/Classes/EventListener/MimeTypeCacheParams.php @@ -17,20 +17,22 @@ { public function __invoke(BeforePageCacheIdentifierIsHashedEvent $event): void { - $request = $event->getRequest(); - $params = $event->getPageCacheIdentifierParameters(); - if ($request->hasHeader('accept')) { - $templates = array_filter($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['image_jack']['templates'], function ($template) { - return in_array(ConverterInterface::class, class_implements($template)); - }); - foreach ($templates as $template) { - $targetMimeType = $template::getTargetMimeType(); - if (RequestHelper::checkForMimeTypeInAcceptHeader($request, $targetMimeType)) { - $params['hashParameters']['accepts'][$targetMimeType] = true; + if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['image_jack']['useFallbackDriver'])) { + $request = $event->getRequest(); + $params = $event->getPageCacheIdentifierParameters(); + if ($request->hasHeader('accept')) { + $templates = array_filter($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['image_jack']['templates'], function ($template) { + return in_array(ConverterInterface::class, class_implements($template)); + }); + foreach ($templates as $template) { + $targetMimeType = $template::getTargetMimeType(); + if (RequestHelper::checkForMimeTypeInAcceptHeader($request, $targetMimeType)) { + $params['hashParameters']['accepts'][$targetMimeType] = true; + } } - } - $event->setPageCacheIdentifierParameters($params); + $event->setPageCacheIdentifierParameters($params); + } } } } From 81cf8f1fc231f6cad6434ba7585ae76206347fcc Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Fri, 16 Aug 2024 09:19:58 +0200 Subject: [PATCH 8/9] [TASK] Minor improvements when using gd --- .ecrc | 3 ++- .gitignore | 1 + Classes/Templates/AvifTemplate.php | 2 +- Classes/Templates/WebpTemplate.php | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.ecrc b/.ecrc index f5b89c7..7193122 100644 --- a/.ecrc +++ b/.ecrc @@ -15,7 +15,8 @@ "\\.php_cs\\.cache", "\\.json", "vendor", - ".composer_cache" + ".composer_cache", + ".php-cs-fixer.cache" ], "AllowedContentTypes": [], "PassedFiles": [], diff --git a/.gitignore b/.gitignore index e61477d..03a75a8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ composer.lock /Build/testing-docker/.env /vendor .php-cs-fixer.cache +public diff --git a/Classes/Templates/AvifTemplate.php b/Classes/Templates/AvifTemplate.php index bf534a4..8f88b31 100644 --- a/Classes/Templates/AvifTemplate.php +++ b/Classes/Templates/AvifTemplate.php @@ -59,7 +59,7 @@ public function processFile(): void switch ($converter) { case 'gd': - $buffer = $this->convertImageUsingGd($options, $targetFile); + $buffer = (string)$this->convertImageUsingGd($options, $targetFile); break; case 'ext': diff --git a/Classes/Templates/WebpTemplate.php b/Classes/Templates/WebpTemplate.php index 9fecf4f..f9924e3 100644 --- a/Classes/Templates/WebpTemplate.php +++ b/Classes/Templates/WebpTemplate.php @@ -59,7 +59,7 @@ public function processFile(): void switch ($converter) { case 'gd': - $buffer = $this->convertImageUsingGd($options, $targetFile); + $buffer = (string)$this->convertImageUsingGd($options, $targetFile); break; case 'ext': From 8c505b45420dae919f5a3c18ef5209eaaed4069a Mon Sep 17 00:00:00 2001 From: Benjamin Tammling Date: Wed, 25 Sep 2024 11:26:10 +0200 Subject: [PATCH 9/9] [TASK] Add new icon --- Resources/Public/Icons/Extension.svg | 33 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Resources/Public/Icons/Extension.svg b/Resources/Public/Icons/Extension.svg index 369594c..92ab30b 100644 --- a/Resources/Public/Icons/Extension.svg +++ b/Resources/Public/Icons/Extension.svg @@ -1,6 +1,29 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +