Phpunit Not Working With Yii Ctestcase (Phpunit_Autoload Not Found)

Solved

By downgrade to phpunit-3.7.1 solved. my instructions:

1- remove phpunit-3.7.* (with all of dependencies If required)

2- install phpunit-3.7.1 with all dependencies, make sure installed phpunit_selenium.

Goodluck




phpunit unit/DbTest.php 

PHPUnit 3.7.6 by Sebastian Bergmann.


Function 'phpunit_autoload' not found (function 'phpunit_autoload' not found or invalid function name)



You can see the issue here: github.com/yiisoft/yii/issues/1563

and fixed in: github.com/yiisoft/yii/commit/5357ebe46dc00794e6b46f54843cff897b280ef0

You need to modify yii/framework/test/CTestCase.php




require_once('PHPUnit/Runner/Version.php');

require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11

require_once('PHPUnit/Autoload.php');

if (in_array('phpunit_autoload', spl_autoload_functions())) { // PHPUnit >= 3.7 'phpunit_alutoload' was obsoleted

    spl_autoload_unregister('phpunit_autoload');

    Yii::registerAutoloader('phpunit_autoload');

}



It worked for me, thanks.

@msoa: That last one is just a missing dependency. All you have to do to fix that is install it ([color=#222222][font=arial, sans-serif][size=2]pear [/size][/font][/color]install phpunit[color=#222222][font=arial, sans-serif][size=2]/[/size][/font][/color]PHPUnit_Selenium). That being said, I really hope they come up with somekind of fix soon, because I really hate to have to modify stock code. It really messes with trying to stay up to date…

[i]

[/i]

This issue is solved by modify the files "yii/framework/test/CTestCase.php"

check this issue at github.com:




Yii 1.1.12 CTestCase doesn't work with PHPUnit 3.7.7


github.com/yiisoft/yii/issues/1563

It looks like you are in dead end, if you install PHPUnit.phar (3.7.19).

I tried this in CTestCase.php


require_once('phar://phpunit.phar/PHPUnit/Runner/Version.php');

require_once('phar://phpunit.phar/PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11

require_once('phar://phpunit.phar/PHPUnit/Autoload.php');

This works for Version.php and Filesystem.php, but fails for Autoload.php with the error:


require_once(phar://phpunit.phar/Autoload.php): failed to open stream:

Does anybody know why? And how to fix this?

Just open CTestCase.php and comment those ‘require_once’ lines:

//require_once(‘PHPUnit/Runner/Version.php’);

//require_once(‘PHPUnit/Util/Filesystem.php’); // workaround for PHPUnit <= 3.6.11

//require_once(‘PHPUnit/Autoload.php’);

For the past week I had the same problem. Commenting out these lines helped - thanks!

So are these ‘require_once’ libraries/files optional? You don’t have use them but if you’ve installed them with PHPUnit they will load.

If so shouldn’t they be commented out by default?