Translations
Info
All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

Unit Testing TYPO3

From TYPO3Wiki
Jump to: navigation, search

Unit testing TYPO3 since 6.2 and above

With TYPO3 CMS version 6.2 the unit test execution and its required setup was streamlined. See Blueprints/StandaloneUnitTests for more details.

composer should be available on the system already, see its documentation for installation details.

Setup and run tests:

shell script:
  git clone git://git.typo3.org/Packages/TYPO3.CMS.git
  cd TYPO3.CMS
  composer install
  ./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml

Functional testing

For information about functional testing see http://wiki.typo3.org/Functional_testing


Unit testing below TYPO3 CMS 6.2

1. Install the extension phpunit from TER. Alternatively you can also use git to checkout the latest version of phpunit. 2. Create a backend user name cli_phpunit to allow running task from shell.

On top of that, some systems require special PHP extensions, like xdebug which is required to generate the code coverage report.

On rpm based systems, like Fedora and RHEL, you need the packages php-process and php-posix in addition to the normal list of PHP extensions.

Integrating phpunit into your IDE

There are several IDE which can run phpunit test. Unfortunately this does not work that easy on TYPO3, because most TYPO3 functions required a fully bootstrapped framework to function. This requires to pull up TYPO3 prior to running any tests. This task is done by the extension phpunit, thus all request must be routed trough the phpunit e.g. via the cli interface.

 ./typo3/cli_dispatch.phpsh phpunit

Hints

  • If using data providers, any code in the providers should be avoided. Especially time calculations are not a good idea, if tests are grunalar to seconds or minutes. Reason for that is, that all data provider data is calculated at the very befinning of a whole run. So, if you run 4000 tests in 2 minutes, there will be time offsets. See for example issue 40515: Core - Fix scheduler tests for travis [Resolved] on that. Furthermore, if additional initialization is done in setUp(), they won't hit depending calculations in dataProviders. If for example a dataProvider uses strtotime() and setUp() sets a specific timezone, the strtotime() will be executed *before* setUp() is called, and thus not take the different timezone setting of setUp() into account.


Using PHPUnit via CLI and MAMP (or any other php binary that is not located in your default path)

Make aliases for php and phpunit (preferably place it in ~/.profile so that it will be available every time you open a terminal window

alias php="/Applications/MAMP/bin/php/php5.4.19/bin/php"
alias phpunit="typo3conf/ext/phpunit/Composer/vendor/bin/phpunit"

Then you can execute core unit or functional test just by doing (you have to be in your TYPO3 installation directory):

phpunit -c typo3/sysext/core/Build/UnitTests.xml
phpunit -c typo3/sysext/core/Build/FunctionalTests.xml

The phpunit TYPO3 extension must be located in typo3conf/ext/ for this to work of course.