Ménage à trois: TYPO3 Flow, PHPUnit, Composer

The introduction of Composer support in TYPO3 Flow has caused some confusion when it comes to installing and using PHPUnit. In the past, PHPUnit was usually installed using PEAR and available as a system-wide command.

Now there are additional options: installation through Composer and as a standalone PHAR archive, each of them posing some issues.

PHPUnit installed via PEAR

Installing PHPUnit via PEAR is described in the PHPUnit manual, and besides the usual issues people seem to be having with PEAR in general, there is not much to say. If you have the phpunit command running, testing TYPO3 Flow applications boils down to

phpunit -c Build/buildessentials/PhpUnit/UnitTests.xml
phpunit -c Build/buildessentials/PhpUnit/FunctionalTests.xml

PHPUnit installed via Composer

Installing PHPUnit via Composer is easy. Just edit the composer.json file at the top level of your project and require phpunit next to the vfsstream dependency:

"require-dev": {
    "typo3/kickstart": "dev-master",
    "typo3/buildessentials": "dev-master",
    "phpunit/phpunit": "3.7.*",
    "mikey179/vfsstream": "1.1.*"

Afterwards, the installation can be done with

composer update --dev phpunit/phpunit

You will end up with a PHPUnit binary at bin/phpunit and can thus run

bin/phpunit -c Build/buildessentials/PhpUnit/UnitTests.xml
bin/phpunit -c Build/buildessentials/PhpUnit/FunctionalTests.xml

Attention (former) PEAR users: if you have PHPUnit installed globally and PEAR libraries are still in your include path, this may lead to very weird results. Just imagine PHPUnit from the composer install being used, but some parts of it are loaded from the PEAR path, possibly with mismatching versions…

So, if you use Composer to install PHPUnit, make sure no other version(s) of PHPUnit clutter your system.

PHPUnit standalone archive

Using the PHPUnit standalone archive is currently not possible. The problem is caused by the Flow bootstrap code and manifests in this error:

PHP Warning:  require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in …/TYPO3/Flow/Core/Bootstrap.php on line 92

Since the class loading in the archive seems to be handled differently (it might well be that adding the archive to the include_path would help), our assumption that this file exists breaks (some) tests.


If you have PHPUnit installed via PEAR, there is currently no reason to change that. We might at some point make PHPUnit a (dev) requirement for TYPO3 Flow, but until then it's your choice.

If you do not have PHPUnit installed right now, using Composer is the easiest choice.


Unknown said...

if you decide to use PHPUnit via Composer and run into issues running tests with PhpStorm afterwards, make sure to vote on this issue

The issue also contains a workaround: setting the autoload.php file for your project via configuration. That is a solution until the issue is officially resolved.

Manchester United said...

Große Post würde Ich mag Ihnen danken für die Anstrengungen, die Sie beim Schreiben dieses interessanten und sachkundigen Artikel gemacht haben. apotheke

Tanika Co Valda said...

I have read your blog its very attractive and impressive. I like it your blog.

PHP 7 Training in chennai | PHP 7 Training Course

PHP 7 Training in chennai | Online PHP 7 Course

Radley Co Tad said...

Great Article

PHP Based Projects for Final Year Students
Final Year Project Centers in Chennai

Spring Training in Chennai
Spring Training in Chennai