Running TYPO3 CMS on HHVM (part2)
27.04.2014 HHVM TYPO3 PHP

A lot of things have happened since my last blog post about TYPO3 and HHVM. So it's time to make an update on what has changed regarding TYPO3 and HHVM compatibility.

HHVM changes:

  • New version of HHVM (3.1) was released and the new language - Hack was born. Read more on hhvm.com.
  • HipHop team did great progress on the framework compatibility. Now unit tests from over 20 different PHP frameworks are running green on HHVM
  • my pull request to HHVM was accepted, and now vfsStream unit tests are included in the framework partiy test suite 

TYPO3 changes:

  • TYPO3 Team did also impressive work and the new version of the TYPO3 CMS was released on March 25th.
  • TYPO3 6.2 is also a LTS version, so it will stay with us for some time. It contains lots of interesting improvements. Check out the "What's new" slides for details.
  • The issue about incompatible interfaces I reported, was already fixed (see previous blog post for the details)
  • Unit tests were heavily refactored (mostly thanks to Christian Kuhn). Just to name a few most important changes:

    • Unit tests do not require a database connection any more. This opens a way to include TYPO3 CMS unit tests in HHVM framework parity check.
    • Unit tests setup is now much simpler and require less dependencies
    • Dependencies like PHPUnit  or vfsstream are now configured in composer
    • Vanilla  PHPUnit  can be used instead of TYPO3 phpunit extension

Let's hack

I finished my last blog post with statement that TYPO3 unit tests are crashing somewhere around 51% when running on HHVM. 

I've spend some time on debugging why TYPO3 are crashing so badly.
It was caused by the fact that  HHVM doesn't support calling array functions like key() on objects. Actually it is documented here as known Zend incompatibility. This behaviour is not going to change on HHVM, so I proposed a simple patch for TYPO3.

You can review it and vote on https://review.typo3.org/#/c/29508/.

After applying this patch and a workaround for the incompatible interfaces I described in the previous post, the whole test suite went through.

Here are the results - 95.57% tests are green:

vagrant@vagrant-ubuntu-saucy-64:~/www/TYPO3.CMS$ hhvm ./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml 
PHPUnit 3.7.35 by Sebastian Bergmann.

Configuration read from /home/vagrant/www/TYPO3.CMS/typo3/sysext/core/Build/UnitTests.xml

...............................................EEFEEEEEEEE.EE 61 / 6458 ( 0%)
FFFFFFFFFFFFFFFFFFFFFFFF............FFFFFFFFFFFFFFFFFFFFFFFFE 122 / 6458 ( 1%)
EEEEE.EESSSSSSSSSSSSSS...............SSSSSSSSSSSSSSSSSSSSSSSS 183 / 6458 ( 2%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS............................ 244 / 6458 ( 3%)
.........SSSSSSSSSSSSSSSSSSSSSSSSSS.......................... 305 / 6458 ( 4%)
...............S...S....S.................................... 366 / 6458 ( 5%)
.......................FFFFF......FFFF....................... 427 / 6458 ( 6%)
...........................................................E. 488 / 6458 ( 7%)
............................................................. 549 / 6458 ( 8%)
............................................................. 610 / 6458 ( 9%)
....................EEE..EEEEEEEEEEEEEEEEE..E.............E.. 671 / 6458 ( 10%)
............................................................. 732 / 6458 ( 11%)
............................................................. 793 / 6458 ( 12%)
....................................Destructor raised a fatal error: Unexpected object type Unknown.

......................... 854 / 6458 ( 13%)
............................................................. 915 / 6458 ( 14%)
............................................F................ 976 / 6458 ( 15%)
............................................................. 1037 / 6458 ( 16%)
............................EE............................... 1098 / 6458 ( 17%)
..........................................S...........SSSSSSS 1159 / 6458 ( 17%)
............................................SSSSSS........... 1220 / 6458 ( 18%)
...SSSS.SSSS..S.............................................. 1281 / 6458 ( 19%)
...........................................F................. 1342 / 6458 ( 20%)
............................................................. 1403 / 6458 ( 21%)
.............................FFF............................. 1464 / 6458 ( 22%)
............................................................. 1525 / 6458 ( 23%)
............................................................. 1586 / 6458 ( 24%)
............................................................. 1647 / 6458 ( 25%)
............................................................. 1708 / 6458 ( 26%)
............................................................. 1769 / 6458 ( 27%)
............................................................. 1830 / 6458 ( 28%)
............................................................. 1891 / 6458 ( 29%)
............................................................. 1952 / 6458 ( 30%)
............................................................. 2013 / 6458 ( 31%)
..................F.F......................................S. 2074 / 6458 ( 32%)
....SSS.....................F................................ 2135 / 6458 ( 33%)
............................................................. 2196 / 6458 ( 34%)
............................................................. 2257 / 6458 ( 34%)
............................................................. 2318 / 6458 ( 35%)
............................................................. 2379 / 6458 ( 36%)
...................................F......................... 2440 / 6458 ( 37%)
............................................................. 2501 / 6458 ( 38%)
...S......................................................... 2562 / 6458 ( 39%)
............................................................. 2623 / 6458 ( 40%)
............................................................. 2684 / 6458 ( 41%)
............................................................. 2745 / 6458 ( 42%)
........................................S.................... 2806 / 6458 ( 43%)
............................................................. 2867 / 6458 ( 44%)
............................................................. 2928 / 6458 ( 45%)
............................................................. 2989 / 6458 ( 46%)
............................................................. 3050 / 6458 ( 47%)
............................................................. 3111 / 6458 ( 48%)
............................................................. 3172 / 6458 ( 49%)
............................................................. 3233 / 6458 ( 50%)
............................................................. 3294 / 6458 ( 51%)
............................................................. 3355 / 6458 ( 51%)
............................................................. 3416 / 6458 ( 52%)
............................................................. 3477 / 6458 ( 53%)
............................................................. 3538 / 6458 ( 54%)
............................................................. 3599 / 6458 ( 55%)
............................................................. 3660 / 6458 ( 56%)
............................................................. 3721 / 6458 ( 57%)
............................................................. 3782 / 6458 ( 58%)
....................................................S........ 3843 / 6458 ( 59%)
........S.................................................... 3904 / 6458 ( 60%)
............................................................. 3965 / 6458 ( 61%)
............................................................. 4026 / 6458 ( 62%)
.................................S........................... 4087 / 6458 ( 63%)
.....................................F....................... 4148 / 6458 ( 64%)
............................................................. 4209 / 6458 ( 65%)
............................................................. 4270 / 6458 ( 66%)
............................................................. 4331 / 6458 ( 67%)
............................................................. 4392 / 6458 ( 68%)
........................................................S.... 4453 / 6458 ( 68%)
............................................................. 4514 / 6458 ( 69%)
............................................................. 4575 / 6458 ( 70%)
............................................................. 4636 / 6458 ( 71%)
............................................................. 4697 / 6458 ( 72%)
............................................................. 4758 / 6458 ( 73%)
....................S........................................ 4819 / 6458 ( 74%)
..................................S..................SS...... 4880 / 6458 ( 75%)
............................................................. 4941 / 6458 ( 76%)
............................................................. 5002 / 6458 ( 77%)
............................................................. 5063 / 6458 ( 78%)
............................................................. 5124 / 6458 ( 79%)
............................................................. 5185 / 6458 ( 80%)
............................................................. 5246 / 6458 ( 81%)
............................................................. 5307 / 6458 ( 82%)
............................................................. 5368 / 6458 ( 83%)
............................................................. 5429 / 6458 ( 84%)
.......................................................S..... 5490 / 6458 ( 85%)
............................................................. 5551 / 6458 ( 85%)
..................SS..............................F.......... 5612 / 6458 ( 86%)
............................................................. 5673 / 6458 ( 87%)
............................................................. 5734 / 6458 ( 88%)
............................................................. 5795 / 6458 ( 89%)
............................................................. 5856 / 6458 ( 90%)
IIIIIIIIIIIIIIIII............................................ 5917 / 6458 ( 91%)
............................................................. 5978 / 6458 ( 92%)
............................................................. 6039 / 6458 ( 93%)
.............................................SSSSSSSSSSS...S. 6100 / 6458 ( 94%)
S............................................................ 6161 / 6458 ( 95%)
FF........................................................... 6222 / 6458 ( 96%)
............................................................. 6283 / 6458 ( 97%)
............................................................. 6344 / 6458 ( 98%)
............................................................. 6405 / 6458 ( 99%)
.....................................................

Time: 1.31 minutes, Memory: 1509.55Mb

FAILURES!
Tests: 6458, Assertions: 10675, Failures: 71, Errors: 45, Incomplete: 17, Skipped: 153.

This means that 95.57% tests were green, 1.1% failed,  0.7% finished with error, 0.26% were incomplete and 2.37% were skipped.

That's pretty good result for me, especially when having in mind that most of the failing tests are red because of the vfsStream incompatibility.

You can check out full test results on https://gist.github.com/tmotyl/11366474

Incompatible interfaces

Let me make a short note about incompatible interfaces problem. Unit tests were failing with error like: 

Declaration of Mock_PackageManager_f139390c::initialize() must be compatible 
with that of TYPO3\Flow\Package\PackageManagerInterface::initialize()

The strange thing is that both method (in the interface and in the implementation class) ARE compatible. They both take one argument \TYPO3\Flow\Core\Bootstrap $bootstrap.

After little investigation I found out that the code PHPUnit generates (and evals) to create this mock, has different method signature then the original code. The argument type was TYPO3\CMS\Core\Core\Bootstrap instead of \TYPO3\Flow\Core\Bootstrap.

PHPUnit uses reflection to build up a mock class. For this method parameter ReflectionParameter::getClass() returned the class from TYPO3\CMS namespace. However ReflectionParameter::__toString() returned correct value:

Parameter #0 [ <required> TYPO3\Flow\Core\Bootstrap $bootstrap ]</required>

This kept me thinking how does PHP know that it should use \TYPO3\CMS\Core\Core\Bootstrap instead of \TYPO3\Flow\Core\Bootstrap.

The answer was in the \TYPO3\CMS\Core\Core\Bootstrap class which in the static getInstance() method set an alias for the class.

class_alias(get_class(static::$instance), 'TYPO3\\Flow\\Core\\Bootstrap');

So after all, it was correct for PHPUnit to use different class name in the mock. I also found and issue on HHVM bug tracker regarding this problem. 

So for the time being, as a workaround, I just comment out PackageManagerInterface::initialize and PackageInterface::boot methods.

Try it yourself

I've already mentioned that setting up TYPO3 for running PHPUnit tests on HHVM is much simpler now. So here are the steps currently needed to get things running.

Install HHVM nightly package 

see http://hhvm.com/blog/3203/nightly-packages

Install and setup TYPO3

get TYPO3

git clone --depth=50 --branch=master git://github.com/TYPO3/TYPO3.CMS.git TYPO3/TYPO3.CMS
cd TYPO3/TYPO3.CMS
mkdir -p uploads typo3temp typo3conf/ext

get composer and install

curl -sS https://getcomposer.org/installer | php
composer --dev install

patch TYPO3 (array access patch from review.typo3.org )

git fetch git://git.typo3.org/Packages/TYPO3.CMS refs/changes/08/29508/2 && git cherry-pick FETCH_HEAD

Apply patch for incompatible interfaces problem from here

gist.github.com/tmotyl/11365191

Run tests:

hhvm ./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml 

Used software versions

TYPO3

6.2 commit 9991d2c4bd03f35157686306f4456476f2d48f20

HHVM 

HipHop VM 3.1.0-dev+2014.04.18 (rel)
Compiler: heads/master-0-gccf06d57ebf7da5f9cab87dcdfa1439494a7e34b
Repo schema: 612222bbdfacd77d127e829b0e7e928b04905850

OS

Ubuntu Saucy 13.10