Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/.github/ export-ignore
/Build/ export-ignore
/Tests/ export-ignore
/.gitattributes export-ignore
/.gitlab-ci.yml export-ignore
/.gitignore export-ignore
/codeception.dist.yml export-ignore
/crowdin.yml export-ignore
/rector.php export-ignore
/shell.nix export-ignore
72 changes: 44 additions & 28 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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

coding-guideline:
runs-on: ubuntu-latest
Expand All @@ -49,7 +49,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
Expand Down Expand Up @@ -77,55 +77,71 @@ jobs:
&& composer install --no-progress --no-ansi --no-interaction

- name: Build codeception tester
run: .build/bin/codecept build
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-unit-and-functional:
runs-on: ubuntu-latest
needs:
- coding-guideline
- code-quality
strategy:
matrix:
php-version:
- 8.2
- 8.3
- 8.4
- 8.5
steps:
- uses: actions/checkout@v5

- 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
php-version: "${{ matrix.php-version }}"
tools: composer:v2

- name: Run Unit Tests PHP8.4
run: nix-shell --arg phpVersion \"php84\" --pure --run project-test-unit
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run Unit Tests PHP8.5
run: nix-shell --arg phpVersion \"php85\" --pure --run project-test-unit
- name: Run unit tests
run: Build/Scripts/phpunit.sh unit

test-acceptance:
runs-on: ubuntu-latest
needs:
- test-unit-and-functional
strategy:
fail-fast: false
matrix:
php-version:
- 8.2
- 8.3
- 8.4
- 8.5
steps:
- uses: actions/checkout@v5

- uses: cachix/install-nix-action@v31
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Run Acceptance Tests PHP8.2
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-acceptance
php-version: "${{ matrix.php-version }}"
tools: composer:v2

- name: Run Acceptance Tests PHP8.3
run: nix-shell --arg phpVersion \"php83\" --pure --run project-test-acceptance
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run Acceptance Tests PHP8.4
run: nix-shell --arg phpVersion \"php84\" --pure --run project-test-acceptance
- name: Show browser versions
run: firefox --version && geckodriver --version

- name: Run Acceptance Tests PHP8.5
run: nix-shell --arg phpVersion \"php85\" --pure --run project-test-acceptance
- name: Run acceptance tests
run: Build/Scripts/acceptance.sh

- 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.build
.Build
composer.lock
var

Expand Down
45 changes: 45 additions & 0 deletions Build/Scripts/acceptance.sh
Original file line number Diff line number Diff line change
@@ -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. "AddSimpleProductWithoutStockHandlingToCartCest".
#
# 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 "$@"
20 changes: 20 additions & 0 deletions Build/Scripts/cgl.sh
Original file line number Diff line number Diff line change
@@ -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[@]}" "$@"
35 changes: 35 additions & 0 deletions Build/Scripts/common.sh
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions Build/Scripts/lint-php.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions Build/Scripts/phpstan.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
57 changes: 57 additions & 0 deletions Build/Scripts/phpunit.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 1 addition & 1 deletion Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ parameters:
path: ../Configuration/TCA/Overrides/tx_cart_domain_model_order_product.php

-
message: '#^Parameter \#1 \$dataSet of method Codappix\\Typo3PhpDatasets\\PhpDataSet\:\:import\(\) expects array\<string, array\<array\<string, string\>\>\>, mixed given\.$#'
message: '#^Parameter \#1 \$dataSet of method Codappix\\Typo3PhpDatasets\\PhpDataSet\:\:import\(\) expects array\<string, array\<int\|string, array\<int\|string, DateTimeInterface\|int\|string\|null\>\>\>, mixed given\.$#'
identifier: argument.type
count: 1
path: ../Tests/Acceptance/Support/Environment.php
Expand Down
2 changes: 1 addition & 1 deletion Build/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="../.build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnDeprecation="true"
Expand Down
6 changes: 3 additions & 3 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace: 'Extcode\CartBooks\Tests\Acceptance\Support'
paths:
tests: 'Tests/Acceptance'
data: 'Tests/Acceptance/Data'
output: '.build/public/typo3temp/var/tests/acceptance-reports'
output: '.Build/public/typo3temp/var/tests/acceptance-reports'
support: 'Tests/Acceptance/Support'

settings:
Expand All @@ -13,8 +13,8 @@ extensions:
enabled:
-
'Codeception\Extension\RunProcess':
- 'geckodriver > .build/public/typo3temp/var/tests/acceptance-logs/geckodriver.log 2>&1'
- 'TYPO3_PATH_APP="$INSTANCE_PATH" TYPO3_PATH_ROOT="$INSTANCE_PATH" php -S 127.0.0.1:8080 -t "$INSTANCE_PATH" > .build/public/typo3temp/var/tests/acceptance-logs/php.log 2>&1'
- 'geckodriver > .Build/public/typo3temp/var/tests/acceptance-logs/geckodriver.log 2>&1'
- 'TYPO3_PATH_APP="$INSTANCE_PATH" TYPO3_PATH_ROOT="$INSTANCE_PATH" php -S 127.0.0.1:8080 -t "$INSTANCE_PATH" > .Build/public/typo3temp/var/tests/acceptance-logs/php.log 2>&1'
-
'Codeception\Extension\Recorder'
-
Expand Down
18 changes: 15 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
}
},
"config": {
"bin-dir": ".build/bin",
"vendor-dir": ".build/vendor",
"bin-dir": ".Build/bin",
"vendor-dir": ".Build/vendor",
"allow-plugins": {
"typo3/cms-composer-installers": true,
"typo3/class-alias-loader": true,
Expand All @@ -46,7 +46,7 @@
"extra": {
"typo3/cms": {
"extension-key": "cart_books",
"web-dir": ".build/public"
"web-dir": ".Build/public"
}
},
"require": {
Expand Down Expand Up @@ -76,5 +76,17 @@
"typo3/cms-fluid-styled-content": "^14.1",
"typo3/cms-install": "^14.1",
"ssch/typo3-rector": "^3.11"
},
"scripts": {
"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",
"project:test:acceptance": [
"Composer\\Config::disableProcessTimeout",
"Build/Scripts/acceptance.sh"
]
}
}
Loading
Loading