Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

PHPUnit 3.6.0 causes fatal error SilverStripe unit tests....


Reply


7 Posts   2556 Views

Avatar
vwd

Community Member, 159 Posts

3 November 2011 at 2:07pm

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.

Avatar
vwd

Community Member, 159 Posts

3 November 2011 at 3:25pm

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.

Avatar
tfliam

Community Member, 20 Posts

28 January 2012 at 4:05am

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?

Avatar
vwd

Community Member, 159 Posts

28 January 2012 at 9:56pm

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

Avatar
tfliam

Community Member, 20 Posts

30 January 2012 at 12:57pm

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

Avatar
micschk

Community Member, 19 Posts

12 April 2012 at 9:03pm

Edited: 12/04/2012 9:14pm

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"

Avatar
frankmullenger

Forum Moderator, 51 Posts

14 August 2012 at 9:39am

Thank you very much vwd!