From cf83eb900417926cf61db2c6f837d1ed271abb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Fri, 1 May 2026 14:24:35 +0200 Subject: [PATCH] [TASK] Add basic unit and functional tests This change adds following tests: * `Tests/Functional/ExtensionLoadedTest.php` to verify that extension is detected as loaded with expected extension key and composer package name. On top it tests against expected TYPO3 core versions using group excludes, which helps to simpler detect if tests for one core version are executed with the other version installed. * `Tests/Unit/VersionCompatTest.php` tests against expected TYPO3 core versions using group excludes, which helps to simpler detect if tests for one core version are executed with the other version installed. In general these two tests can act as first tests for any extension to have unit and functional test infrastructure added. Having at least the functional tests helps detecting DI container compile issues or automatic TCA migrations and related deprecations early - even if no other thats are added. For example, if `12.4` has been used to install the dependencies and the unit/functional tests are executed giving the `-t 13.4` option these tests will fail and indicates this - other failures can than be early ruled out and avoids wasting debug time `ci.yaml` is modified to call unit and functional test with the same TYPO3 version used to setup the system. > [!NOTE] > Existing similar tests are removed in favour of the new ones, > and having them on the lowest level makes them easy findable. --- .github/workflows/ci.yml | 4 +- Build/Scripts/runTests.sh | 8 +-- .../Functional/Environment/ExtensionTest.php | 25 -------- Tests/Functional/ExtensionLoadedTest.php | 62 +++++++++++++++++++ Tests/Unit/Environment/ExtensionTest.php | 25 -------- Tests/Unit/VersionCompatTest.php | 42 +++++++++++++ composer.json | 4 +- 7 files changed, 112 insertions(+), 58 deletions(-) delete mode 100644 Tests/Functional/Environment/ExtensionTest.php create mode 100644 Tests/Functional/ExtensionLoadedTest.php delete mode 100644 Tests/Unit/Environment/ExtensionTest.php create mode 100644 Tests/Unit/VersionCompatTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8922f604e..95a63ba45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -212,7 +212,7 @@ jobs: ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -t ${{matrix.typo3-version}} -s composerUpdate${{matrix.composer-dependencies}} - name: Run unit tests run: | - ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -s unit + ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -t ${{matrix.typo3-version}} -s unit strategy: fail-fast: false matrix: @@ -263,7 +263,7 @@ jobs: ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -t ${{matrix.typo3-version}} -s composerUpdate${{matrix.composer-dependencies}} - name: Run functional tests run: | - ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -d ${{ matrix.dbms }} -s functional + ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -t ${{matrix.typo3-version}} -d ${{ matrix.dbms }} -s functional strategy: fail-fast: false matrix: diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 3f2a30359..2bb8b3bfe 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# shellcheck disable=SC2086,SC2046,SC2128,SC2178,SC2206 +# shellcheck disable=SC2086,SC2046,SC2128,SC2178,SC2206,SC2054 # Uncomment for debugging # set -x @@ -599,7 +599,7 @@ case ${TEST_SUITE} in SUITE_EXIT_CODE=$? ;; functional) - COMMAND=(.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml --exclude-group not-${DBMS} "$@") + COMMAND=(.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml --exclude-group not-${DBMS},not-core-${CORE_VERSION} "$@") case ${DBMS} in mariadb) echo "Using driver: ${DATABASE_DRIVER}" @@ -712,11 +712,11 @@ case ${TEST_SUITE} in SUITE_EXIT_CODE=$? ;; unit) - ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name unit-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_PHP} .Build/bin/phpunit -c Build/phpunit/UnitTests.xml "$@" + ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name unit-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_PHP} .Build/bin/phpunit -c Build/phpunit/UnitTests.xml --exclude-group not-core-${CORE_VERSION} "$@" SUITE_EXIT_CODE=$? ;; unitRandom) - ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name unit-random-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_PHP} .Build/bin/phpunit -c Build/phpunit/UnitTests.xml --order-by=random ${PHPUNIT_RANDOM} "$@" + ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name unit-random-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_PHP} .Build/bin/phpunit -c Build/phpunit/UnitTests.xml --exclude-group not-core-${CORE_VERSION} --order-by=random ${PHPUNIT_RANDOM} "$@" SUITE_EXIT_CODE=$? ;; update) diff --git a/Tests/Functional/Environment/ExtensionTest.php b/Tests/Functional/Environment/ExtensionTest.php deleted file mode 100644 index 3ca1b5752..000000000 --- a/Tests/Functional/Environment/ExtensionTest.php +++ /dev/null @@ -1,25 +0,0 @@ -getMajorVersion(), self::ALLOWED_MAJOR_VERSIONS); + } + + #[Group('not-core-13.4')] + #[Test] + public function verifyCore12(): void + { + self::assertSame(12, (new Typo3Version())->getMajorVersion()); + } + + #[Group('not-core-12.4')] + #[Test] + public function verifyCore13(): void + { + self::assertSame(13, (new Typo3Version())->getMajorVersion()); + } +} diff --git a/Tests/Unit/Environment/ExtensionTest.php b/Tests/Unit/Environment/ExtensionTest.php deleted file mode 100644 index e2bc4bbc2..000000000 --- a/Tests/Unit/Environment/ExtensionTest.php +++ /dev/null @@ -1,25 +0,0 @@ -getMajorVersion(); - self::assertContains( - $currentVersion, - $supportedVersions - ); - } -} diff --git a/Tests/Unit/VersionCompatTest.php b/Tests/Unit/VersionCompatTest.php new file mode 100644 index 000000000..b3ffb4f99 --- /dev/null +++ b/Tests/Unit/VersionCompatTest.php @@ -0,0 +1,42 @@ +getMajorVersion(), self::ALLOWED_MAJOR_VERSIONS); + } + + #[Group('not-core-13.4')] + #[Test] + public function verifyCore12(): void + { + self::assertSame(12, (new Typo3Version())->getMajorVersion()); + } + + #[Group('not-core-12.4')] + #[Test] + public function verifyCore13(): void + { + self::assertSame(13, (new Typo3Version())->getMajorVersion()); + } +} diff --git a/composer.json b/composer.json index 35d2069a6..6105a28c5 100644 --- a/composer.json +++ b/composer.json @@ -123,7 +123,7 @@ "check:coverage:functional": [ "@check:tests:create-directories", "@coverage:create-directories", - "phpunit -c Build/phpunit/FunctionalTests.xml --coverage-php=build/coverage/functional.cov" + "phpunit -c Build/phpunit/FunctionalTests.xml --exclude-group not-core-13.4 --coverage-php=build/coverage/functional.cov" ], "check:coverage:merge": [ "@coverage:create-directories", @@ -131,7 +131,7 @@ ], "check:coverage:unit": [ "@coverage:create-directories", - "phpunit -c Build/phpunit/UnitTests.xml --coverage-php=build/coverage/unit.cov" + "phpunit -c Build/phpunit/UnitTests.xml --exclude-group not-core-13.4 --coverage-php=build/coverage/unit.cov" ], "check:json:lint": "find . ! -path '*/.cache/*' ! -path '*/.Build/*' ! -path '*/node_modules/*' -name '*.json' | xargs -r php .Build/bin/jsonlint -q", "check:php": [