Yii Unit Test Not Working !


(Snboxo) #1

Hi, I am following Agile Web Application Development with Yii 1.1 and PHP5.

In chapter 3, when I tried to go along with the unit testing example described, the following error came up in the command prompt.

C:\wamp\www\yiiprojects\demo\protected\tests>phpunit unit/MessageTest.php

PHPUnit 3.7.9 by Sebastian Bergmann.

Function ‘phpunit_autoload’ not found (function ‘phpunit_autoload’ not found or

invalid function name)

But functional test example worked well for me. I tried re-installing phpunit and other dependencies many times.still no luck.

Can someone help? thanks.


(Marek Surek) #2

Try to change the file : 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');


(Snboxo) #3

Hello Marek Surek,

Well, guess what… it worked.

Thank you so much. I was searching all over the Internet for this and your solution did work.

It prints a large amount of code like a stack trace of the error in the console window. but when the code is error free it works really fine.

thanks for the support Marek. really appreciate it.


(Resurtm) #4

Dedicated PR in the Github: https://github.com/yiisoft/yii/issues/1563 (just linking with forum topic)


(Arch) #5

This modification also works for PhPUnit 3.7.9!

Thanks Folks!