Using runTests.sh

What is runTests.sh?

This is a shell script which is included in the TYPO3 Core git repository. It used to supply commands for running tests, but has since evolved to include other commands as well for checking, fixing, building etc. It will be used for a number of tasks and will be a vital part during your Core contribution workflow.

The script uses Docker (also supporting podman) and several Docker images to run the tasks - using the correct versions (of PHP, Node/NPM etc.) for the current branch of your TYPO3 repository.

Show help

It is recommended to use the -h option (help) to show the help output and especially look at the beginning of the output for a description and the listing of dependencies. The listing in section -s shows available commands, and the bottom lists several examples you can copy+paste to try.

Show help:

shell command
Build/Scripts/runTests.sh -h
Copied!

Prerequisites

See the listed options/commands in the help output.

Options

-h
show help
-s
choose the command to run (if omitted, unit tests are run)
-p
PHP version (if omitted, the default version is used)
-b
choose podman (default) or docker for image execution
-d
Database type (sqlite, mariadb, mysql, postgres)
-i
Database version in conjunction with -d, for example -d mariadb -i 11.4 for MariaDB 11.4
-x
Enable xdebug usage
-u
Update docker image versions

For more options, see the help (-h).

We will quickly go over each type of command next.

Output example:

Options:
 -s <...>
     Specifies which test suite to run
         - acceptance: main application acceptance tests
         - acceptanceInstall: installation acceptance tests, only with -d mariadb|postgres|sqlite
         - buildCss: execute scss to css builder
         - buildJavascript: execute typescript to javascript builder
         - cgl: test and fix all core php files
...
Copied!

Commands

We categorize the commands and show some examples here. It is recommended to use -h as described previously to view the help output and examples. The trailing * is used as wildcard to indicate that there are further commands which start with the same string.

Commands for building:

  • -s composerInstall (composer*)
  • -s buildCss: build CSS assets
  • -s buildJavascript
  • ...

Checks and fixes, run static analyzer, lint etc:

  • -s cglGit : check (and fix!) the CGL issues in the files which are in the most recent git commit
  • -s cgl (cgl*)
  • -s lintPhp
  • -s lintScss (lint*)
  • -s phpstan (phpstan*)
  • -s checkComposer (check*)
  • ...

Commands for running tests:

  • -s unit (unit*)
  • -s functional (functional*)
  • -s acceptance (acceptance*)
  • ...

Cleanup, clear cache:

  • -s clean (clean*)
  • ...

Dispatchers:

  • -s npm -- [npm command]
  • -s composer -- [composer command]

Additional setup

Be sure to exclude the typo3temp and .cache directory from indexing in your IDE (e.g. PhpStorm) before starting the acceptance tests.

Also, if you are using DDEV for example with Mutagen performing filesystem synchronization, it is vital that you configure the typo3temp and .cache directory to be excluded in your file .ddev/mutagen/mutagen.yml like this:

sync:
  defaults:
    mode: "two-way-resolved"
    stageMode: "neighboring"
    ignore:
      paths:
        # ...
        - "typo3temp/"
        - "public/typo3temp"
        - ".cache"
        # ...
Copied!

Due to the testing framework and involved components like PHPstan, PHPUnit and Composer writing many, many small files this can make your tests several HUNDREDS percent slower, especially on macOS.

Examples

All examples expect to be executed from a git cloned working directory of TYPO3 CMS main branch (as described in TYPO3 Contribution Guide - Core Development).

composer install

Run composer install:

shell command
Build/Scripts/runTests.sh -s composerInstall
Copied!

CGL check and fix

Perform checks on Coding Guidelines and fix them.

This applies the command only to the files in the latest commit:

shell command
Build/Scripts/runTests.sh -s cglGit
Copied!

If you only want to see possible fixes being applied, you can execute the command in "dry-run" mode:

shell command
Build/Scripts/runTests.sh -s cglGit -n
Copied!

Run all unit tests

shell command
Build/Scripts/runTests.sh
Copied!

Run unit tests with xdebug (uses default port 9000)

shell command
./Build/Scripts/runTests.sh -x
Copied!

Run specific unit tests with xdebug

shell command
Build/Scripts/runTests.sh -x <directory or file>
Copied!

Example:

Build/Scripts/runTests.sh -x typo3/sysext/core/Tests/Unit/LinkHandling/
Copied!

Run functional tests

shell command
./Build/Scripts/runTests.sh -s functional
Copied!

Run functional tests with PostgreSQL

shell command
./Build/Scripts/runTests.sh -s functional -d postgres
Copied!

Run acceptance tests

shell command
./Build/Scripts/runTests.sh -s acceptance
Copied!

Depending on the power of your local machine you can expect about 30 minutes or more for the acceptance tests.

Troubleshooting

Before diagnosing problems in the script, make sure to check if Docker is running smoothly on your system.

A quick test is to run the docker hello-world image:

shell command
docker run hello-world
Copied!

You should see something like this message:

result
Hello from Docker!
This message shows that your installation appears to be working correctly.
Copied!

See Get Started, Part 1: Orientation and setup

Also, see docker troubleshooting pages for more in-depth information, such as Docker for Mac: Logs and troubleshooting

There is no built-in debugging to the runTests.sh script. It can happen that (docker or other) command execution needs to be debugged.

For this you need to get your hands dirty and inspect the file. Most commands are performed like this:

runTests.sh (excerpt)
lintScss)
    COMMAND="cd Build; npm ci || exit 1; node_modules/grunt/bin/grunt stylelint"
    ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name lint-css-${SUFFIX} -e HOME=${CORE_ROOT}/.cache ${IMAGE_NODEJS} /bin/sh -c "${COMMAND}"
    SUITE_EXIT_CODE=$?
    ;;
Copied!

to debug this, you can add an "echo" statement to reveal $COMMAND and also put an echo before the ${CONTAINER_BIN} statement, like this:

runTests.sh (excerpt)
lintScss)
    COMMAND="cd Build; npm ci || exit 1; node_modules/grunt/bin/grunt stylelint"
    CONTAINER_COMMAND="${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name lint-css-${SUFFIX} -e HOME=${CORE_ROOT}/.cache ${IMAGE_NODEJS} /bin/sh -c ${COMMAND}"
    echo "EXECUTE:"
    echo $COMMAND
    echo $CONTAINER_COMMAND
    SUITE_EXIT_CODE=$?
    ;;
Copied!

Then when you execute the script, instead of the command being executed, you can see what is used. Copy+paste that execution to your local shell and see if you can spot specific errors. You may want to add options like -v to the $COMMAND to see, why that command may fail.

Results

All results will be displayed on the screen. The script should exit with standard exit codes:

  • 0 means all is ok
  • != 0 means error

Reports of the acceptance tests will be stored in typo3temp/var/tests/AcceptanceReports with screenshots from the remotely controlled browser.

Direct commands without Docker

If you have problems with docker, you can run some of the lowlevel scripts and commands directly. However it does depend on your system, whether they run successfully (due to PHP, composer and other dependencies). The docker / runTests.sh method gives us the possibility to have a controlled environment where the tests run in. That also means, the databases that the functional tests require are already created automatically. That is not the case, if you run the tests locally on your current system.

That being said, running the tests directly is not being officially supported, but you can try this out yourself.

You can look in the source of Build/Scripts/runTests.sh to see which commands the runTests.sh script calls and run these directly (also see the "Troubleshooting" section above). Not everything will work, because there may be dependencies, that are only available in the docker container.

Also, you can run some of the scripts in Build/Scripts directly, which are otherwise just dispatched from within a docker container.

Examples:

Run all unit tests

shell command
bin/phpunit -c vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml
Copied!

Run specific unit tests

shell command
bin/phpunit -c vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml <directory or file>
Copied!

Example:

bin/phpunit -c vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml typo3/sysext/core/Tests/Unit/LinkHandling/

Copied!

Run all functional tests

shell command
bin/phpunit -c vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml
Copied!

Check for Coding Guidelines

The cgl checking commands / scripts not only check, they repair as well! They can also be utilized from GIT hooks.

Mac / Linux:

shell command
Build/Scripts/cglFixMyCommit.sh
Copied!

Windows:

shell command
Build/Scripts/cglFixMyCommit.bat
Copied!

More information

  • More details about the test system, test strategies, execution and set up can be found in TYPO3 explained.