Running phpunit tests using HHVM (HipHop)
Asked Answered
C

3

10

I am trying to run PHPUnit unit tests via HHVM on a virtual Ubuntu 12.04 (64-bit Server) install. The tests usually run using a phpunit.xml file located in my tests directory, which includes a bootstrap file to handle autoloading, and the tests run fine on an ordinary php install. However, I keep getting:

HipHop Fatal error: File not found: File/Iterator/Autoload.php in /usr/share/php/PHPUnit/Autoload.php on line 64

When running:

hhvm -f /usr/bin/phpunit /path/to/my/testsDirectory/SomeTest.php

And I haven't been able to figure out how to run phpunit under hhvm using a bootstrap or config file... Any help would be appreciated.

Cringle answered 26/9, 2013 at 15:24 Comment(2)
You have to ensure that PEAR is in your include path and you have the PEAR php-file-iterator package installed.Scalf
Without knowing your complete setup, the path comment above may indeed be correct (I have seen other SO questions that have given a similar response). For how I setup my PHPUnit testing with HHVM, you can go here: github.com/facebook/hiphop-php/wiki/…Zandrazandt
S
11

HHVM 2.4+

HHVM 2.4.0 was just released and it came with full phpunit support! Just give the full path to phpunit binary, like this:

$ hhvm /usr/bin/phpunit

Cheers!


HHVM 2.3

Tested this step by step guide from HHVM wiki and it works. Here is a simplified guide:

On your project, add the following entries to your composer.json file:

"require-dev": {
    "phpunit/phpunit": "3.7.*",
    "phpunit/php-invoker": "1.1.3",
    "phpunit/dbunit": "1.2.3",
    "phpunit/phpunit-selenium": "1.3.2",
    "phpunit/phpunit-story": "1.0.2"
}
  1. Run hhvm composer.phar install --dev. If you did a composer system wide install, run hhvm /usr/local/bin/composer install --dev, it works too.

  2. A vendor directory will be created. The phpunit "binary" will be located at vendor/bin/phpunit

  3. To run PHPUnit for your project: hhvm vendor/bin/phpunit [optional arguments]

Note: Probably in a not so distant future hhvm /usr/local/bin/phpunit [optional arguments] will work as expected, but right now this is the easiest option we have

Stalder answered 26/12, 2013 at 7:5 Comment(2)
vendor/bin/phpunit is now an sh script, so you have to run hhvm vendor/phpunit/phpunit/phpunit to make it work!Huskamp
[optional arguments] still doesn't work in PHPUnit 5.7Wesley
B
5

Just a note to add to @cabbey's asnwer: you can set the IncludeSearchPaths value using the -v option:

hhvm -v Server.IncludeSearchPaths.share=/usr/share/php/ $(which phpunit) MyTests.php
Broker answered 17/3, 2014 at 10:42 Comment(0)
L
1

A simple workaround is to configure HHVM to include the PEAR libraries in it's search paths.

I added this to my config.hdf's Server section:

    IncludeSearchPaths {
        forphpunit = /usr/lib/php/
    }

and then ran phpunit as:

hhvm -c ~/config.hdf /usr/bin/phpunit --bootstrap bootstrap.php MyTests.php
Landowner answered 2/1, 2014 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.