Just ran across an issue where my PHP unit tests were throwing several “Constant … already defined” errors and couldn’t figure out why. When upgrading the unit tests I had no problem, it was only when I was trying to integrate into CruiseControl that this was happening. Well after some time, I finally figured out the issue was the “ant” command to execute the unit tests was passing the –process-isolation flag to phpunit. Apparently this flag causes everything to be called twice, including the bootstrap file, so if you don’t wrap your “define(CONST, ‘value’)” definitions with an “(!is_defined)” check, you will get the “Constant … already defined” errors.

The simple fix? To simply remove the –process-isolation flag from the command line call.