mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-15 18:36:13 +01:00
tea/Documentation/Running.rst
Stefan Bürk 41b44c28a4 [TASK] Avoid using testing-framework boilerplate files
typo3/testing-framework provides some template files as kickstart
for project and extension based testing. They are properly marked
to be copied and not used directly from the package. The reason
for this recommendation is, that project should make adjustments
to theire concrete setup, like coverage settings and so on.

This change clonses the corresponding template files from the
testing-framework to folders in this extension, adjusts needed
paths and ensure testing is still working. With that this best
practice example follows the recommendation and best-practice
for typo3/testing-framework usage.

Tasks

* provided cloned unit- and function test configuration and
  bootstrap files in `Build/phpunit/`
* updated cloned phpunit configuration files to be phpunit v9
  compatible, removing old coverage tag as this is done by
  cli options in this repository anyway
* add proper xml namespacing to cloned phpunit configurations
* adjustes config paths in unit and functional testing calls
  provided as composer scripts
* adjusted phpunit configuration files in documentation

Resolves #533
2022-10-16 01:55:38 +02:00

6.1 KiB

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, you can run them using composer <scriptname>. If you are working with ddev, you can run them with ddev composer <scriptname>. You do not need to start or build the containers for this as this happens automatically.

The code-quality-related Composer scripts make use of the PHIVE-installed tools. This means that for non-ddev-based development, you need to run phive install before you can use the Composer scripts.

You can run composer (or ddev composer) to display a list of all available Composer commands and scripts. For all custom Composer scripts there are descriptions in the script-description section of the composer.json.

Running code checks

You can currently run these code checks on the command line (if working locally without ddev, omit the ddev part):

Commands; composer ci

ddev composer ci

Runs all dynamic and static code checks.

Commands; composer ci:composer:normalize

ddev composer ci:composer:normalize

Checks the composer.json.

Commands; composer ci:json:lint

ddev composer ci:json:lint

Lints the JSON files.

Commands; composer ci:php

ddev composer ci:php

Runs all static checks for the PHP files.

Commands; composer ci:php:copypaste

ddev composer ci:php:copypaste

Checks for copy'n'pasted PHP code.

Commands; composer ci:php:cs-fixer

ddev composer ci:php:cs-fixer

Checks the code style with the PHP Coding Standards Fixer (PHP-CS-Fixer).

Commands; composer ci:php:lint

ddev composer ci:php:lint

Lints the PHP files for syntax errors.

Commands; composer ci:php:sniff

ddev composer ci:php:sniff

Checks the code style with PHP_CodeSniffer (PHPCS).

Commands; composer ci:php:stan

ddev composer ci:php:stan

Checks the PHP types using PHPStan.

Commands; composer ci:static

ddev composer ci:static

Runs all static code checks (syntax, style, types).

Commands; composer ci:ts:lint

ddev composer ci:ts:lint

Lints the TypoScript files.

Commands; composer ci:yaml:lint

ddev composer ci:yaml:lint

Lints the YAML files.

Commands; composer fix:php

ddev composer fix:php

Runs all fixers for the PHP code.

Commands; composer fix:php:cs

ddev composer fix:php:cs

Fixes the code style with PHP-CS-Fixer.

Commands; composer fix:php:sniff

ddev composer fix:php:sniff

Fixes the code style with PHP_CodeSniffer.

Commands; composer phpstan:baseline

ddev composer phpstan:baseline

Updates the PHPStan baseline file to match the code.

Running unit and functional tests

You can currently run these tests and coverages on the command line (if working locally without ddev, omit the ddev part):

Commands; composer ci:coverage

ddev composer ci:coverage

Runs the ci:coverage script as defined in composer.json.

Commands; composer ci:coverage:functional

ddev composer ci:coverage:functional

Generates the code coverage report for functional tests.

Commands; composer ci:coverage:merge

ddev composer ci:coverage:merge

Merges the code coverage reports for unit and functional tests.

Commands; composer ci:coverage:unit

ddev composer ci:coverage:unit

Generates the code coverage report for unit tests.

Commands; composer ci:dynamic

ddev composer ci:dynamic

Runs all PHPUnit tests (unit and functional).

Commands; composer ci:tests

ddev composer ci:tests

Runs all PHPUnit tests (unit and functional).

Commands; composer ci:tests:functional

ddev composer ci:tests:functional

Runs the functional tests.

Commands; composer ci:tests:unit

ddev composer ci:tests:unit

Runs the unit tests.

Running unit and functional tests in PHPStorm

General setup

  • Open File > Settings > PHP > Test Frameworks.
  • (*) Use Composer autoloader.
  • Path to script: select .Build/vendor/autoload.php in your project folder.

In the Run configurations, edit the PHPUnit configuration and use these settings so this configuration can serve as a template:

  • Directory: use the Tests/Unit directory in your project.
  • (*) Use alternative configuration file.
  • Use .Build/public/typo3conf/tea/Build/phpunit/UnitTests.xml in your project folder.
  • 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/Unit directory in your project

Functional tests configuration

In the Run configurations, copy the PHPUnit configuration and use these settings:

  • Directory: use the Tests/Functional directory in your project.
  • (*) Use alternative configuration file.
  • Use .Build/public/typo3conf/tea/Build/phpunit/FunctionalTests.xml.