views:

108

answers:

1

I have a suite of PHPUnit tests for my extension, and I want to run them as part of the extension's Hudson build process.

So I want to run PHPUnit specifying the extension library to load at runtime, but I can't figure out how to do this.

My directory structure is as follows:

/myextension.c
/otherextensionfiles.*
/modules/myextension.so
/tests/unittests.php

I've tried running PHPUnit with an configuration XML file as follows:

<phpunit>
<php>
<ini name="extension_dir" value="../modules/"/>
<ini name="extension" value="myextension.so"/>
</php>
</phpunit>

And then running it as follows (from the tests directory):

phpunit --configuration config.xml unittests.php

But then I get Fatal error: Call to undefined function myfunction(), so it's not loading the library.

I've also tried:

phpunit -d extension_dir=../modules/ -d extension=myextension.so unittests.php 

And also dl('myextension.so') to the test setup, but no joy.

If it's relevant, this is using PHP 5.2 and PHPUnit 3.4.11.

I've cross-posted this question on the PHPUnit users mailing list.

+1  A: 

I suspect not possible to set extension_dir at runtime in PHPUnit since it has the attribute PHP_INI_SYSTEM in this chart.

That means it's not possible to it with ini_set(), so I assume it's also not possible to set it with the PHPUnit config <ini name="extension_dir" value="/mydir/">.

EDIT:

However, since PHPUnit is just another PHP script, it is possible to run PHP directly, and pass in the override commands this way!

This gets around the above issue, and the following works:

php -d extension_dir=../modules -d extension=myextension.so /usr/bin/phpunit unittests.php

The only problem with this approach is that PHPUnit will no longer be able to find any extensions that were installed in the normal directory ( eg /usr/lib/php5/20060613/ ), this can be resolved by adding symbolic links from your extension_dir to the relevant files in the default extension_dir.

therefromhere
@therefromhere what about (shudder) copying the module into the extension_dir during runtime, `dl()`ing it and (maybe) removing it in the test's `tearDown` method? Awfully kludgy but in want of better ways....
Pekka
@Pekka, yeah, that's what I was considering.
therefromhere
@Pekka - I found a solution, see above.
therefromhere
@therefromhere nice!
Pekka