PHPUnit Segmentation fault

后端 未结 13 779
故里飘歌
故里飘歌 2020-12-28 14:56

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 sam

相关标签:
13条回答
  • 2020-12-28 15:35

    This related to code not extension. In my case i had these two files

    1. Test Case
    2. Example Test

    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.

    0 讨论(0)
  • 2020-12-28 15:36

    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

    serialize($object);
    

    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 affect serialize, it only affects casting to JSON and array.

    I had this problem, when I had a model saved into a property of a Mailable object.

    fixed with

    $this->model->refresh(); 
    

    in a __construct method , just before the whole object is serialized.

    0 讨论(0)
  • 2020-12-28 15:37

    Next to what cweiske suggested, if upgrading PHP is not an option for you and you have problems to locate the source of the segfault, you can use a debugger to find out more.

    You can launch gdb this way to debug a PHPUnit session:

    gdb --args php /usr/bin/phpunit quiz_service_Test.php
    

    Then type in r to run the program and/or set environment variables first.

    set env MALLOC_CHECK_=3
    r
    

    You might also consider to install the debugging symbols for PHP on the system to get better results for debugging. gdb checks this on startup for you and leaves a notice how you can do so.

    0 讨论(0)
  • 2020-12-28 15:37

    I had similar problem and by disabling the garbge collactor in

    PHPStorm => Edit configuration => Interpreter option : -d zend.enable_gc=0

    Or if you are running your tests from the command line you may try adding :

    -d zend.enable_gc=0

    0 讨论(0)
  • 2020-12-28 15:38

    In addition to https://stackoverflow.com/a/38789046/246790 which helped me a lot:

    You can use PHP function gc_disable();

    I have placed it in my PHPUnit bootstrap code as well with ini_set('memory_limit', -1);

    0 讨论(0)
  • 2020-12-28 15:46

    I got into the same problem. I upgraded the PHPUnit to the 4.1 version (to run the tests) and it was able to show me the object, as pointed by Isaac.

    So, if you get to this very same problem, upgrade to PHPUnit >= 4.1 and you'll be able to see the error instead of getting "Segmentation fault" message.

    0 讨论(0)
提交回复
热议问题