Running checks & tests
Most code checks and tests can be run via Composer commands.
Table of Contents:
Composer scripts
For most development-related tasks, this extension provides Composer scripts.
If you are working locally (Composer needs to be installed on your local
machine), you can run them using
composer <scriptname>
.
You can run
composer
or
./ to
display a list of all available Composer commands and scripts. For all custom
Composer scripts there are descriptions in the script- section of
the composer..
Keep in mind that certain commands only work if you have run
composer install
or
./
before.
If you have problems with missing dependencies on your local machine, it is
recommended to execute tests with the usage of the run script.
./Build/Scripts/runTests.sh -s composer check:php:lint
This makes your life easier because you don't have to worry about local dependencies.
Note
It's always a good idea to look into the run "Examples" section to
get an idea how it works. In the "Options" section you can find all
available options.
Running code checks
You can currently run these code checks on the command line:
./Build/Scripts/runTests.sh -s composer check:composer:normalize
Checks the composer.json.
./Build/Scripts/runTests.sh -s composer check:json:lint
Lints the JSON files.
./Build/Scripts/runTests.sh -s composer check:php
Checks the code style with the PHP Coding Standards Fixer (PHP-CS-Fixer).
./Build/Scripts/runTests.sh -s composer check:php:lint
Lints the PHP files for syntax errors.
./Build/Scripts/runTests.sh -p 8.2 -t 13.4 -s phpstan
Checks the PHP types using PHPStan. The option -t selects the
PHPStan configuration and baseline for the given TYPO3 version
(13. or 14.). Use the TYPO3 version the dependencies
have been installed for.
./Build/Scripts/runTests.sh -s composer check:typoscript:lint
Lints the TypoScript files.
./Build/Scripts/runTests.sh -s composer check:xliff:normalize
Checks the formatting of the XLIFF files.
./Build/Scripts/runTests.sh -s composer check:yaml:lint
Lints the YAML files.
./Build/Scripts/runTests.sh -s fix
Runs all fixers (except for the ones that need JavaScript).
./Build/Scripts/runTests.sh -s composer fix:php
Runs all fixers for the PHP code.
./Build/Scripts/runTests.sh -s cgl
Fixes the code style with PHP-CS-Fixer. Add -n to only check the code style without changing any files.
./Build/Scripts/runTests.sh -s normalizeXliff
Normalizes the formatting of the XLIFF files. Add -n to only check
the formatting without changing any files.
./Build/Scripts/runTests.sh -p 8.2 -t 13.4 -s phpstanGenerateBaseline
Updates the PHPStan baseline file of the given TYPO3 version to match the code.
Running unit and functional tests
Note
Executing tests on Windows via run should be done within the
[Windows Subsystem for Linux (WSL 2)](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux).
Important
Before running any commands you need to install all dependencies with
./Build/Scripts/runTests.sh -s composer update
You can currently run these tests on the command line:
./Build/Scripts/runTests.sh -t 13.4 -s functional
Runs the functional tests using a database populated from the CSV files in
Tests/ folder.
Note
For executing functional tests, a database connection is needed. Therefore,
it is recommended to run the functional tests using run.
./Build/Scripts/runTests.sh -t 13.4 -s unit
Runs the unit tests.
Tip
With the option -p, you can specify which PHP version will be used to
execute the tests. If you don't specify a PHP version, the default PHP
version will be used.
./Build/Scripts/runTests.sh -p 8.2 -s unit
Tip
With the option -t (13. or 14., default
13.), you can specify the TYPO3 version the unit and the
functional tests are run for. Tests which only apply to one TYPO3 version
are skipped for the others, and a version the dependencies have not been
installed for makes the tests fail immediately. Use the same version as for
the installation.
./Build/Scripts/runTests.sh -t 14.3 -s unit
./Build/Scripts/runTests.sh -t 14.3 -s functional
Running unit and functional tests in PHPStorm
General setup
- Open File > Settings > PHP > Test Frameworks.
- (*) Use Composer autoloader.
- Path to script: select
.Build/in your project folder.vendor/ autoload. php
In the Run configurations, edit the PHPUnit configuration and use these settings so this configuration can serve as a template:
- Directory: use the
Tests/directory in your project.Unit - (*) Use alternative configuration file.
- Use
.Build/in your project folder.vendor/ typo3/ testing- framework/ Resources/ Core/ Build/ Unit Tests. xml -
Add the following environment variables:
- typo3DatabaseUsername
- typo3DatabasePassword
- typo3DatabaseHost
- typo3DatabaseName
Unit tests configuration
In the Run configurations, copy the PHPUnit configuration and use these settings:
- Directory: use the
Tests/directory in your projectUnit
Functional tests configuration
In the Run configurations, copy the PHPUnit configuration and use these settings:
- Directory: use the
Tests/directory in your project.Functional - (*) Use alternative configuration file.
- Use
.Build/.vendor/ typo3/ testing- framework/ Resources/ Core/ Build/ Functional Tests. xml