multiple tests clashing in phing
We have a Phing script that is used by Hudson to build/test our PHP site.
Some of our unit tests load the main function library; others use a mock to avoid having to do so (or to provide specific faked results for the test).
The unit tests all run perfectly when run in isolation (ie on the command line, using phpunit
). However when we run them together as a batch in Phing, we get errors.
The errors are in tests where we have written mocks for certain functions. The error says that we are declaring the function twice. It is clearly attempting to include the real function library as well as the mocks.
The tests are including code that is mutually exclusive, so they need to be run in isolation from each other; it would appear that Phing is running them all in a single process, so the includes are clashing.
The relevant part of the phing script looks like this:
<phpunit haltonfailure="true" printsummary="true">
<b开发者_开发百科atchtest>
<fileset dir="${ws}/path/to/site/root/">
<include name="*Test.php" />
<include name="*/*Test.php" />
<include name="*/*/*Test.php" />
<include name="*/*/*/*Test.php" />
</fileset>
</batchtest>
<formatter type="xml" todir="${builddir}/logs" outfile="units.xml" />
</phpunit>
Is there a way to get phing to run the tests independantly of each other, without specifying each one separately in the build script?
Well the easiest/fastest workaround seems to be "don't use the phing task but start using the 'real' phpunit output.
So running <exec command="phpunit ... "> [...]
and use --coverage-html and publish that in hudson and use --coverage-clover and the junit switch to get the coverage information into hudson. ( See jenkins-php.org or Setting up jenkins for php projects (there is a demo phpunit.xml.dist)
for reference)
But chances are you don't want to so that :/
Saidly from the Phing docs of the phpunit task
i see no way of telling phing directly to use --process-isolation
switch.
So maybe someone else has a solution for that. I don't have one that will still produce code coverage.
From the comments
I'm going to assume that you have 2 separate pieces of test code that can't be run in a single process so what would ideal is if you could say:
run 2 processes: "testsuite one do that, testsuite two do the other thing"
after that aggregate the results
Sadly i don't know how you could tell phpunit to do so. I'll investigate further but for now the only thing i know that works for sure is to use --process-isolation
each test in the whole testsuite. If there is a way to run a whole suite in one separate process i don't know about it.
Hopefully someone else has an easier solution to this :)
精彩评论