Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » PHPUnit 3.6.0 causes fatal error SilverStripe unit tests....

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2540 Views
  • vwd
    Avatar
    Community Member
    158 Posts

    PHPUnit 3.6.0 causes fatal error SilverStripe unit tests.... Link to this post

    Hi,

    I've just installed PHPUnit 5.3.6 and it seems to cause a fatal error with the Unit Testing set-up... This is whenever do either;
    - /dev/tests
    - /dev/tests/all
    - /dev/tests/startsession
    - /dev/tests/endsession

    Here is the php_error.log entry:

    [03-Nov-2011 11:55:10] PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /Users/myaccount/sapphire/dev/phpunit/PhpUnitWrapper_3_5.php on line 29
    [03-Nov-2011 11:55:10] PHP Stack trace:
    [03-Nov-2011 11:55:10] PHP 1. {main}() /Users/myaccount/index.php:0
    [03-Nov-2011 11:55:10] PHP 2. require_once() /Users/myaccount/index.php:63
    [03-Nov-2011 11:55:10] PHP 3. Director::direct() /Users/myaccount/sapphire/main.php:127
    [03-Nov-2011 11:55:10] PHP 4. Director::handleRequest() /Users/myaccount/sapphire/core/control/Director.php:125
    [03-Nov-2011 11:55:10] PHP 5. Controller->handleRequest() /Users/myaccount/sapphire/core/control/Director.php:282
    [03-Nov-2011 11:55:10] PHP 6. RequestHandler->handleRequest() /Users/myaccount/sapphire/core/control/Controller.php:147
    [03-Nov-2011 11:55:10] PHP 7. Controller->handleRequest() /Users/myaccount/sapphire/core/control/RequestHandler.php:161
    [03-Nov-2011 11:55:10] PHP 8. TestRunner->init() /Users/myaccount/sapphire/core/control/Controller.php:136
    [03-Nov-2011 11:55:10] PHP 9. sapphire_autoload() /Users/myaccount/sapphire/core/Core.php:0
    [03-Nov-2011 11:55:10] PHP 10. include_once() /Users/myaccount/sapphire/core/Core.php:213
    [03-Nov-2011 11:55:10] PHP 11. PhpUnitWrapper::has_php_unit() /Users/myaccount/sapphire/dev/phpunit/PhpUnitWrapper.php:237
    [03-Nov-2011 11:55:10] PHP 12. PhpUnitWrapper::inst() /Users/myaccount/sapphire/dev/phpunit/PhpUnitWrapper.php:161
    [03-Nov-2011 11:55:10] PHP 13. PhpUnitWrapper_3_5->init() /Users/myaccount/sapphire/dev/phpunit/PhpUnitWrapper.php:149

    Any ideas?

    Thanks.

    VWD.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: PHPUnit 3.6.0 causes fatal error SilverStripe unit tests.... Link to this post

    Hi,

    I'm not sure if this is a proper fix as I haven't had time to look at it in any length, but the following changes seem to get it going again...

    PHPUnitWrapper_3_5.php

    <?php
    /**
    * @package sapphire
    * @subpackage dev
    */

    class PhpUnitWrapper_3_5 extends PhpUnitWrapper {

    <snip>

       /**
        * Initialise the wrapper class.
        */
       public function init() {
          require_once 'PHP/CodeCoverage.php';
          require_once 'PHP/CodeCoverage/Report/HTML.php';

          require_once 'PHPUnit/Autoload.php';

          require_once 'PHP/CodeCoverage/Filter.php';
          PHP_CodeCoverage_Filter::addFileToBlacklist(__FILE__, 'PHPUNIT'); // ***VWD(20111103): removed getInstance() from this line ***
       }

    <snip>
    }
    ?>

    Really, this is a temporary hack. There needs to be a PHPUnitWrapper_3_6.php that takes into account all other PHPUnit API changes...

    Thanks,
    VWD.

  • tfliam
    Avatar
    Community Member
    20 Posts

    Re: PHPUnit 3.6.0 causes fatal error SilverStripe unit tests.... Link to this post

    Thank you VWD for your post, by removing the getInstance() has gotten mine to work fine as well. Just wondering, besides this temporarily hack, is there anyone has other solution to this?

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: PHPUnit 3.6.0 causes fatal error SilverStripe unit tests.... Link to this post

    Hi tfliam,

    No worries. No I haven't heard of any official solution to this yet. My suspicion is that not too many others experience the fatal error. Out of curiousity, what version of PHP, SilverStripe, and what OS/web server do you use?

    VWD

  • tfliam
    Avatar
    Community Member
    20 Posts

    Re: PHPUnit 3.6.0 causes fatal error SilverStripe unit tests.... Link to this post

    I just downloaded them recently, they are all up to date. The versions are as below:
    Silverstripe - 2.4.6
    Wamp 2.2a-x32 (php 5.3.8)
    OS - Window 7

  • micschk
    Avatar
    Community Member
    19 Posts

    Re: PHPUnit 3.6.0 causes fatal error SilverStripe unit tests.... Link to this post

    Just a quick note on how I got PHPUnit (3.6) to work with SilverStripe;

    If on Linux, don't install it via apt-get/aptitude (doesn't work);

    sudo aptitude purge phpunit


    If purge doesn't remove everything because you've also tried various flavours of pear, just to be sure remove everything;

    sudo rm -fr /usr/share/php/PHPUnit

    Instead; install via pear, with some additional settings;

    sudo pear upgrade PEAR
    sudo pear config-set auto_discover 1
    sudo pear install --alldeps pear.phpunit.de/PHPUnit

    Then I ran into the "require_once(PHPUnit/Framework/MockObject/Autoload.php): failed to open stream: No such file" error:

    sudo pear install --force phpunit/PHPUnit_MockObject
    (or:) sudo pear install --alldeps --force phpunit/phpunit

    Check to see what's installed now:

    sudo pear list -c phpunit

    Almost there! Now you have to update the Sapphire wrapper for PHPUnit 3.6 (like mentioned above);

    //File: sapphire/dev/phpunit/PhpUnitWrapper_3_5.php, line 29:

    PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'PHPUNIT');
    // Remove " getInstance()-> " from this line so it becomes:
    PHP_CodeCoverage_Filter::addFileToBlacklist(__FILE__, 'PHPUNIT');

    Happy (Unit) testing!

    ---
    Oh, and to add Xdebug;

    sudo pecl install xdebug

    add to php.ini

    zend_extension="/usr/lib/php5/20090626/xdebug.so"

  • frankmullenger
    Avatar
    Forum Moderator
    51 Posts

    Re: PHPUnit 3.6.0 causes fatal error SilverStripe unit tests.... Link to this post

    Thank you very much vwd!

    2540 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.