When a PHPUnit test fails normally on my dev box (Linux Mint), it causes a "Segmentation Fault" on my Continous Integration box (Centos). Both machines are running the same version of PHPUnit. My dev box is running PHP 5.3.2-1ubuntu4.9, and the CI is PHP 5.2.17. I'd rather leave upgrading the PHP as a last resort though.
As per this thread: PHPUnit gets segmentation fault I have tried deactivating / reinstalling Xdebug. I don't have inclue.so installed.
On the CI box I currently only have two extensions active: dom from php-xml (required for phpunit) and memcache (required by my framework), all the others have been turned off.
If anyone comes across this in relation to PHPunit within Laravel
It took a while to figure out what the issue was. I was going over the differences between my current code and the previous revision and through some trial and error finally got there.
I had two different models that were both including each other with the
protected $with
override.This must have been causing some kind of loop that phpunit could not deal with.
Hopefully someone finds this useful.
I kept getting a
Segmentation fault: 11
when running PHPUnit with Code coverage. After doing a stack trace of the segmentation fault, I found the following was causing the Segmentation fault error:I replaced my current
xdebug.so
in the path above with the latest version from the Komodo Remote Debugging Package the sub-folder of the corresponding downloaded package with the PHP version I have (which is 5.5 for me) and everything worked.if you have an object with property pointing to the same object, or other sort of pointer loops, you will have this message while running
And if you are a Laravel user, and you are dealing with models. And if you think, you will never have this problem, because you avoiding pointer loops by using
$hidden
property on your models, please be advised, the$hidden
property does not affectserialize
, it only affects casting toJSON
andarray
.I had this problem, when I had a model saved into a property of a
Mailable
object.fixed with
in a
__construct
method , just before the whole object is serialized.I've had an issue with PHPUnit segfaulting and had trouble finding an answer, so hopefully this helps someone with the same issue later.
PHPUnit was segfaulting, but only:
After a while I realized that it was due to failures on tests that used data providers, and specifically for data providers that passed objects with lots of recursive references. A bell finally went off and I did some digging: the problem is that when you're using data providers and a test fails, PHPUnit tries to create a string representation of the provided arguments for the failure description to tell you what failed, but this is problematic when one of the arguments has some infinite recursion. In fact, what PHPUnit does in
PHPUnit_Framework_TestCase::dataToString()
(around line 1612) is print out all the arguments provided by the data provider usingprint_r
, which causes the segfault when PHP tries to create a string representation of the infinitely recursive object.The solution I came to was:
dataToString()
in my test base class, to check for these kinds of objects in the data array (which is possible in my case because I know what these objects look like). If the object is present, I return some special value, if not I just pass it along to the parent method.This related to code not extension. In my case i had these two files
In Test Case there is method called createApplication. Just leave it empty.
In Example Test you can create the method and fill with $this->assertTrue(true)
Above is basic setup hope you can extend the requirement as you need.
I had similar problem and by disabling the garbge collactor in
Or if you are running your tests from the command line you may try adding :