From fa504f18c8a8bc21b0e9f3c8d3cd84fc8202948b Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Thu, 12 Nov 2026 14:51:11 +0100 Subject: [PATCH 1/2] [TASK] Refactor tests to Build/Scripts directory The tests should be executable for local testing and GitHub Actions with nearly the same context. The composer scripts, the nix-shell commands and the CI workflow now call the same scripts in Build/Scripts, which also lift the PHP memory limit. The composer scripts use the same project:* names as in the main branch and the other cart extensions. The old test:* scripts for cgl, lint, phpstan and phpunit are removed, some of them referenced phpunit configurations that no longer exist. The unit and functional tests in the CI workflow no longer need nix and run in a php-version matrix. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 45 +++++++++++++++---------------- Build/Scripts/cgl.sh | 20 ++++++++++++++ Build/Scripts/common.sh | 35 ++++++++++++++++++++++++ Build/Scripts/lint-php.sh | 11 ++++++++ Build/Scripts/phpstan.sh | 12 +++++++++ Build/Scripts/phpunit.sh | 57 +++++++++++++++++++++++++++++++++++++++ composer.json | 36 +++++-------------------- shell.nix | 18 ++++++++----- 8 files changed, 175 insertions(+), 59 deletions(-) create mode 100755 Build/Scripts/cgl.sh create mode 100644 Build/Scripts/common.sh create mode 100755 Build/Scripts/lint-php.sh create mode 100755 Build/Scripts/phpstan.sh create mode 100755 Build/Scripts/phpunit.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3cddf79..912ca25 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,7 @@ jobs: tools: composer:v2 - name: PHP lint - run: "find *.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l" + run: Build/Scripts/lint-php.sh documentation-rendering: runs-on: ubuntu-latest @@ -60,7 +60,7 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Coding Guideline - run: .Build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --using-cache=no --path-mode=intersection ./ + run: Build/Scripts/cgl.sh code-quality: runs-on: ubuntu-latest @@ -92,42 +92,41 @@ jobs: run: .Build/bin/codecept build - name: Code Quality (by PHPStan) - run: .Build/bin/phpstan analyse -c Build/phpstan.neon + run: Build/Scripts/phpstan.sh - test-php: + tests-unit-and-functional: runs-on: ubuntu-latest needs: - coding-guideline - code-quality + strategy: + matrix: + php-version: + - 8.2 + - 8.3 + - 8.4 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v31 + - name: Install PHP + uses: shivammathur/setup-php@v2 with: - nix_path: nixpkgs=channel:nixos-26.05 - - - name: Run Unit Tests PHP8.2 - run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-unit - - - name: Run Unit Tests PHP8.3 - run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-unit - - - name: Run Unit Tests PHP8.4 - run: nix-shell --arg phpVersion \"php84\" --pure --run project-test-unit + php-version: "${{ matrix.php-version }}" + tools: composer:v2 - - name: Run Functional Tests PHP8.2 - run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-functional + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest - - name: Run Functional Tests PHP8.3 - run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-functional + - name: Run unit tests + run: Build/Scripts/phpunit.sh unit - - name: Run Functional Tests PHP8.4 - run: nix-shell --arg phpVersion \"php84\" --pure --run project-test-functional + - name: Run functional tests + run: Build/Scripts/phpunit.sh functional test-acceptance: runs-on: ubuntu-latest needs: - - test-php + - tests-unit-and-functional steps: - uses: actions/checkout@v3 diff --git a/Build/Scripts/cgl.sh b/Build/Scripts/cgl.sh new file mode 100755 index 0000000..460cd7e --- /dev/null +++ b/Build/Scripts/cgl.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# +# Checks the coding guidelines with php-cs-fixer. +# +# Usage: +# Build/Scripts/cgl.sh check only, fails on violations +# Build/Scripts/cgl.sh --fix fix the violations in place + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary php-cs-fixer + +FIXER_ARGS=(--config=Build/.php-cs-fixer.dist.php --using-cache=no) +if [ "${1:-}" = "--fix" ]; then + shift +else + FIXER_ARGS+=(-v --dry-run --diff) +fi + +runPhp "${BIN_DIR}/php-cs-fixer" fix "${FIXER_ARGS[@]}" "$@" diff --git a/Build/Scripts/common.sh b/Build/Scripts/common.sh new file mode 100644 index 0000000..9220642 --- /dev/null +++ b/Build/Scripts/common.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Shared setup for all scripts in Build/Scripts. +# +# This file is sourced, not executed. It changes to the project root, so every +# script behaves the same no matter from where it has been called, and it +# provides the defaults all scripts rely on. +# +# Environment variables used as overrides: +# PHP_BIN php binary to use, defaults to "php" +# PHP_MEMORY_LIMIT memory_limit for all php calls, defaults to "-1" + +set -euo pipefail + +PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +readonly PROJECT_ROOT +cd "${PROJECT_ROOT}" + +PHP_BIN="${PHP_BIN:-php}" +PHP_MEMORY_LIMIT="${PHP_MEMORY_LIMIT:--1}" +BIN_DIR="${PROJECT_ROOT}/.Build/bin" +readonly PHP_BIN PHP_MEMORY_LIMIT BIN_DIR + +# Runs php with the configured memory limit, independent of the php.ini in use. +runPhp() { + "${PHP_BIN}" -d memory_limit="${PHP_MEMORY_LIMIT}" "$@" +} + +# Fails with a readable message if composer install has not been run yet. +requireBinary() { + if [ ! -f "${BIN_DIR}/$1" ]; then + echo "Missing ${BIN_DIR}/$1, please run \"composer install\" first." >&2 + exit 1 + fi +} diff --git a/Build/Scripts/lint-php.sh b/Build/Scripts/lint-php.sh new file mode 100755 index 0000000..1b86352 --- /dev/null +++ b/Build/Scripts/lint-php.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# +# Lints all php files of the extension for syntax errors. +# +# Usage: +# Build/Scripts/lint-php.sh + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +find ./*.php Classes Configuration Tests -name '*.php' -print0 \ + | xargs -0 -n 1 -P 4 "${PHP_BIN}" -l diff --git a/Build/Scripts/phpstan.sh b/Build/Scripts/phpstan.sh new file mode 100755 index 0000000..6f06604 --- /dev/null +++ b/Build/Scripts/phpstan.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# +# Runs the static code analysis with phpstan. +# +# Usage: +# Build/Scripts/phpstan.sh [additional phpstan arguments] + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary phpstan + +runPhp "${BIN_DIR}/phpstan" analyse -c Build/phpstan.neon "$@" diff --git a/Build/Scripts/phpunit.sh b/Build/Scripts/phpunit.sh new file mode 100755 index 0000000..2636b97 --- /dev/null +++ b/Build/Scripts/phpunit.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# +# Runs the phpunit tests. +# +# Usage: +# Build/Scripts/phpunit.sh [testsuite] [additional phpunit arguments] +# +# Without a testsuite every suite defined in Build/phpunit.xml.dist is run, +# each one in its own phpunit process. They cannot share a process, the +# functional bootstrap leaks global state into the unit tests. The first +# argument is taken as the testsuite name unless it starts with a dash. +# +# Environment variables used as overrides: +# typo3DatabaseDriver database driver to test against, defaults to "pdo_sqlite" + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary phpunit + +export typo3DatabaseDriver="${typo3DatabaseDriver:-pdo_sqlite}" + +runSuite() { + local suite="$1" + shift + + runPhp "${BIN_DIR}/phpunit" \ + -c Build/phpunit.xml.dist \ + --testsuite "${suite}" \ + --display-warnings \ + --display-deprecations \ + --display-errors \ + --display-notices \ + "$@" +} + +if [ $# -gt 0 ] && [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then + TESTSUITE="$1" + shift + runSuite "${TESTSUITE}" "$@" + exit $? +fi + +mapfile -t SUITES < <(runPhp "${BIN_DIR}/phpunit" -c Build/phpunit.xml.dist --list-suites \ + | sed -n 's/^ - \(.*\) ([0-9]\{1,\} tests\{0,1\})$/\1/p') + +if [ ${#SUITES[@]} -eq 0 ]; then + echo "No testsuites found in Build/phpunit.xml.dist." >&2 + exit 1 +fi + +STATUS=0 +for suite in "${SUITES[@]}"; do + echo "Running testsuite \"${suite}\" ..." + runSuite "${suite}" "$@" || STATUS=$? +done + +exit "${STATUS}" diff --git a/composer.json b/composer.json index f4d977c..1aaac4e 100644 --- a/composer.json +++ b/composer.json @@ -76,24 +76,12 @@ "typo3/testing-framework": "^8.0" }, "scripts": { - "test:cgl": [ - ".Build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --using-cache=no --path-mode=intersection ./" - ], - "test:cgl:dry-run": [ - ".Build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --using-cache=no --path-mode=intersection ./" - ], - "test:php:lint": [ - "find *.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l" - ], - "test:php:unit": [ - ".Build/bin/phpunit -c Build/UnitTests.xml" - ], - "test:php:functional": [ - "typo3DatabaseDriver=\"pdo_sqlite\" .Build/bin/phpunit -c Build/FunctionalTests.xml" - ], - "test:phpstan:analyse": [ - ".Build/bin/phpstan analyse -c Build/phpstan.neon" - ], + "project:cgl": "Build/Scripts/cgl.sh", + "project:cgl:fix": "Build/Scripts/cgl.sh --fix", + "project:lint:php": "Build/Scripts/lint-php.sh", + "project:phpstan": "Build/Scripts/phpstan.sh", + "project:test:unit": "Build/Scripts/phpunit.sh unit", + "project:test:functional": "Build/Scripts/phpunit.sh functional", "test:rector:process": [ ".Build/bin/rector process" ], @@ -102,18 +90,6 @@ ], "test:typoscript:lint": [ ".Build/bin/typoscript-lint -c Build/typoscriptlint.yaml Configuration" - ], - "test:php": [ - "@test:php:lint", - "@test:php:unit", - "@test:php:functional" - ], - "test:all": [ - "@test:phpstan:analyse", - "@test:rector:process", - "@test:cgl", - "@test:typoscript:lint", - "@test:php" ] }, "suggest": { diff --git a/shell.nix b/shell.nix index e71aa87..907c054 100644 --- a/shell.nix +++ b/shell.nix @@ -37,11 +37,12 @@ let name = "project-cgl"; runtimeInputs = [ + composer php ]; text = '' - ./.Build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --diff + "$PROJECT_ROOT/Build/Scripts/cgl.sh" ''; }; @@ -49,11 +50,12 @@ let name = "project-cgl-fix"; runtimeInputs = [ + composer php ]; text = '' - ./.Build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php + "$PROJECT_ROOT/Build/Scripts/cgl.sh" --fix ''; }; @@ -61,11 +63,12 @@ let name = "project-lint"; runtimeInputs = [ + composer php ]; text = '' - find ./*.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l + "$PROJECT_ROOT/Build/Scripts/lint-php.sh" ''; }; @@ -73,35 +76,38 @@ let name = "project-phpstan"; runtimeInputs = [ + composer php ]; text = '' - ./.Build/bin/phpstan analyse -c Build/phpstan.neon --memory-limit 256M + "$PROJECT_ROOT/Build/Scripts/phpstan.sh" ''; }; projectTestUnit = pkgs.writeShellApplication { name = "project-test-unit"; runtimeInputs = [ + composer php projectInstall ]; text = '' project-install - ./.Build/bin/phpunit -c Build/phpunit.xml.dist --testsuite unit --display-warnings --display-deprecations --display-errors + "$PROJECT_ROOT/Build/Scripts/phpunit.sh" unit ''; }; projectTestFunctional = pkgs.writeShellApplication { name = "project-test-functional"; runtimeInputs = [ + composer php projectInstall ]; text = '' project-install - ./.Build/bin/phpunit -c Build/phpunit.xml.dist --testsuite functional --display-warnings --display-deprecations --display-errors + "$PROJECT_ROOT/Build/Scripts/phpunit.sh" functional ''; }; From d48e392b11f15764a858fb81f351f1cbb8818ad0 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Thu, 12 Nov 2026 15:14:22 +0100 Subject: [PATCH 2/2] [TASK] Run acceptance tests via Build/Scripts The acceptance tests were only executable via nix-shell. They now use Build/Scripts/acceptance.sh like the other tests. The script is called by the new composer script project:test:acceptance, the nix-shell command project-test-acceptance and the CI workflow. The CI workflow no longer needs nix and runs the acceptance tests in a php-version matrix. On failure the acceptance reports are uploaded as artifact. The script stops the php webserver and geckodriver on exit, even if the tests fail. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 34 ++++++++++++++++++++-------- Build/Scripts/acceptance.sh | 45 +++++++++++++++++++++++++++++++++++++ composer.json | 4 ++++ shell.nix | 16 ++++--------- 4 files changed, 78 insertions(+), 21 deletions(-) create mode 100755 Build/Scripts/acceptance.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 912ca25..a3a20f1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -127,18 +127,34 @@ jobs: runs-on: ubuntu-latest needs: - tests-unit-and-functional + strategy: + fail-fast: false + matrix: + php-version: + - 8.2 + - 8.3 + - 8.4 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v31 + - name: Install PHP + uses: shivammathur/setup-php@v2 with: - nix_path: nixpkgs=channel:nixos-26.05 + php-version: "${{ matrix.php-version }}" + tools: composer:v2 - - name: Run Acceptance Tests PHP8.2 - run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-acceptance + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Show browser versions + run: firefox --version && geckodriver --version - - name: Run Acceptance Tests PHP8.3 - run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-acceptance + - name: Run acceptance tests + run: Build/Scripts/acceptance.sh - - name: Run Acceptance Tests PHP8.4 - run: nix-shell --arg phpVersion \"php84\" --pure --run project-test-acceptance + - name: Upload acceptance reports + if: failure() + uses: actions/upload-artifact@v4 + with: + name: acceptance-reports-php${{ matrix.php-version }} + path: .Build/public/typo3temp/var/tests/acceptance-reports diff --git a/Build/Scripts/acceptance.sh b/Build/Scripts/acceptance.sh new file mode 100755 index 0000000..6555e46 --- /dev/null +++ b/Build/Scripts/acceptance.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# Runs the acceptance tests with codeception. +# +# Usage: +# Build/Scripts/acceptance.sh [test] [additional codecept run arguments] +# +# The tests run in the "acceptance" suite, so the first argument can be a +# single Cest, e.g. "AddEventDateToCartCest". +# +# Requirements: +# - firefox and geckodriver available in PATH +# - php with pdo_sqlite +# +# The codeception RunProcess extension starts geckodriver and the php built-in +# webserver. Both are stopped when this script exits, even on failure. + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary codecept + +for tool in firefox geckodriver; do + if ! command -v "${tool}" > /dev/null 2>&1; then + echo "Missing \"${tool}\" in PATH, it is required for the acceptance tests." >&2 + exit 1 + fi +done + +TESTS_PATH="${PROJECT_ROOT}/.Build/public/typo3temp/var/tests" +mkdir -p \ + "${TESTS_PATH}/acceptance" \ + "${TESTS_PATH}/acceptance-logs" \ + "${TESTS_PATH}/acceptance-reports" \ + "${TESTS_PATH}/acceptance-sqlite-dbs" + +export INSTANCE_PATH="${TESTS_PATH}/acceptance" + +cleanup() { + pkill -f "php -S 127.0.0.1:8080" || true + pkill -f "geckodriver" || true +} +trap cleanup EXIT + +runPhp "${BIN_DIR}/codecept" build +runPhp "${BIN_DIR}/codecept" run acceptance "$@" diff --git a/composer.json b/composer.json index 1aaac4e..0afbb93 100644 --- a/composer.json +++ b/composer.json @@ -82,6 +82,10 @@ "project:phpstan": "Build/Scripts/phpstan.sh", "project:test:unit": "Build/Scripts/phpunit.sh unit", "project:test:functional": "Build/Scripts/phpunit.sh functional", + "project:test:acceptance": [ + "Composer\\Config::disableProcessTimeout", + "Build/Scripts/acceptance.sh" + ], "test:rector:process": [ ".Build/bin/rector process" ], diff --git a/shell.nix b/shell.nix index 907c054..3477e27 100644 --- a/shell.nix +++ b/shell.nix @@ -135,18 +135,7 @@ let ]; text = '' project-install - - mkdir -p "$PROJECT_ROOT/.Build/public/typo3temp/var/tests/acceptance" - mkdir -p "$PROJECT_ROOT/.Build/public/typo3temp/var/tests/acceptance-logs" - mkdir -p "$PROJECT_ROOT/.Build/public/typo3temp/var/tests/acceptance-reports" - mkdir -p "$PROJECT_ROOT/.Build/public/typo3temp/var/tests/acceptance-sqlite-dbs" - - export INSTANCE_PATH="$PROJECT_ROOT/.Build/public/typo3temp/var/tests/acceptance" - - ./.Build/bin/codecept run - - pgrep -f "php -S" | xargs -r kill - pgrep -f "geckodriver" | xargs -r kill + "$PROJECT_ROOT/Build/Scripts/acceptance.sh" "$@" ''; }; @@ -154,6 +143,9 @@ in pkgs.mkShellNoCC { name = "TYPO3 Extension extcode/cart-products"; buildInputs = [ pkgs.cacert + pkgs.firefox + pkgs.geckodriver + pkgs.procps php composer projectInstall