Skip to content
Snippets Groups Projects

Phpunit

Setup

Requirements for running the php unittests:

  • make bootstrap was executed
  • The following files exist at the same location (either extension/ or typo3conf/):
    • config.qfq.php
    • LocalConfiguration.php
  • The database credentials in config.qfq.php are correct
  • The database with the name DB_1_NAME followed by _phpunit exists. E.g. app_qfq_phpunit where DB_1_NAME=app_qfq

In Tests/Unit/ you may find a mockup of LocalConfiguration.php and a template for config.qfq.php.

Run unit tests from commandline

REMARK: Running the unit tests without specifying the configuration file phpunit.xml will not work. See section "Autoloader" for explanation.

From the extension folder run:

vendor/bin/phpunit --configuration phpunit.xml

Phpunit configurations

Phpunit configurations are stored in extension/phpunit.xml Running the tests without specifying these configurations will not work.

Autoloader

The test classes use the composer autoloader to reference to the source classes. The autoloader is loaded by phpunit before each test as specified in phpunit.xml by the line <phpunit bootstrap="vendor/autoload.php">

Run tests without typo3 installation (e.g. gitlab runner)

As defined in the phpunit command of projectRoot/Makefile.

The files phpunit_config.qfq.php and phpunit_LocalConfiguration.php are copied outside the extension folder by the Makefile.