Some tests encountered in phing

We have a Phing script that is used by Hudson to build / test our PHP site.

Some of our unit tests load a library of core functions; others use the layout to avoid having to do this (or provide specific fake test results).

Unit testing is performed perfectly when performed in isolation (ie, the command line, using phpunit ). However, when we run them together as a package in Phing, we get errors.

Errors in tests where we wrote mocks for certain functions. The error says that we declare the function twice. Obviously, he is trying to include a real function library as well as mocks.

Tests include code that is mutually exclusive, so they must be run in isolation from each other; It would seem that Phing runs them all in one process, therefore they are inclusive in conflict.

The relevant part of the phing script looks like this:

 <phpunit haltonfailure="true" printsummary="true"> <batchtest> <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 force phing to run tests independently, without specifying each separately in the build script?

+4
source share
1 answer

Well, the easiest / fastest workaround is to "not use the phing task, but start using the" real "phpunit output.

So run <exec command="phpunit ... "> [...]

and use -coverage-html and publish this to hudson and use the --coverage-clover and junit switch to get coverage information in hudson. (See jenkins-php.org or Setting up jenkins for php projects (there is a demo phpunit.xml.dist) for help)


But most likely you do not want: /

At the same time, from the Phing docs of the phpunit task I see no way to tell phing directly to use the --process-isolation switch.

So maybe someone has a solution for this. I don't have one that will still play the code.

From the comments

I’m going to assume that you have 2 separate pieces of test code that cannot be run in the same process, and that would be ideal if you could say:

 run 2 processes: "testsuite one do that, testsuite two do the other thing" after that aggregate the results 

Unfortunately, I do not know how you could tell phpunit. I will investigate further, but for now, the only thing I know that works for sure is to use --process-isolation each test in the whole testuite. If there is a way to run the whole package in one separate process, I do not know about it.


Hope someone has an easier solution :)

+1
source

Source: https://habr.com/ru/post/1344304/


All Articles