Hi Folks,
I am having trouble getting php unit to work with CTestCase, it works fine with PHPUnit_Framework_TestCase
Here is the test class: -
<?php
class DbTest extends CTestCase
{
public function testConnection()
{
$this->assertTrue(true);
}
}
Here is the error: -
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)
Anyone come across this before?
Thanks for your help
All the best,
Ash
cruzeta51
(Cruzeta80)
October 7, 2012, 11:40pm
2
Hi Folks,
I am having trouble getting php unit to work with CTestCase, it works fine with PHPUnit_Framework_TestCase
Here is the test class: -
<?php
class DbTest extends CTestCase
{
public function testConnection()
{
$this->assertTrue(true);
}
}
Here is the error: -
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)
Anyone come across this before?
Thanks for your help
All the best,
Ash
I’m having the same problem, did you find out how to fix it?
Well I got it changing some lines in CTestCase.php:
spl_autoload_unregister(array(‘YiiBase’,‘autoload’));
require_once(‘PHPUnit/Autoload.php’);
spl_autoload_register(array(‘YiiBase’,‘autoload’));
//spl_autoload_unregister(‘phpunit_autoload’);
//Yii::registerAutoloader(‘phpunit_autoload’);
cruzeta51:
I’m having the same problem, did you find out how to fix it?
Well I got it changing some lines in CTestCase.php:
spl_autoload_unregister(array(‘YiiBase’,‘autoload’));
require_once(‘PHPUnit/Autoload.php’);
spl_autoload_register(array(‘YiiBase’,‘autoload’));
//spl_autoload_unregister(‘phpunit_autoload’);
//Yii::registerAutoloader(‘phpunit_autoload’);
I had thought about changing those lines, but I was worried about dabbling in things I don’t understand
Will this cause any side-effects later on?
Thanks
Ash
Haensel
(Johannes)
October 8, 2012, 4:21pm
4
Did you add PEAR to the include path in your php.ini? I am pretty sure that this is the problem
Btw.: You should never change Yii’s core classes. Just extend them if you need to, otherwise your changes would break when you’re updating Yii.
Search for
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
and change it to
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
include_path = ".:/php/includes:/usr/lib/php/pear"
Note: This is my path (Mac OS X), this might be different depending on your OS etc.
bobafett
(Pabloarchenti)
October 9, 2012, 2:26pm
5
I had the same issue and I temporally resolved it downgrading PHPUnit to version 3.7.1.
Thanks for the help guys, sorry I haven’t had a chance to try it out this week, my day job has been very busy! Hopefully I’ll get a chance at the weekend
All the best,
ASh
thoellerl
(Thoellerl)
October 10, 2012, 7:15pm
7
It works with PhpUnit 3.7.1 for me too.
Just tried this for myself. Works fine with 3.7.1, thanks for the help guys!
All the best,
Ash
I checked in my ini file pear entry was there
include_path=".;C:\PHP\pear"
but same error. I am on PHPUnit 3.7.7…has anyone solved the problem, other than downgrading back to 3.7.1
Thanks
emix
(Michal)
October 12, 2012, 4:32pm
10
It does not work for me too with CTestCase, it works with PHPUnit_Framework_TestCase though.
Linux Debian 2.6.32-5-686
phpunit --version
PHPUnit 3.7.7 by Sebastian Bergman
Yii
latest
php --version
PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli)
include_path
.:/usr/share/php:/usr/share/php/PEAR
That sucks. I am not going to downgrade my package either.
iDexterRu
(Idexter Ru)
October 14, 2012, 12:35pm
11
Hi all. I have some problem.
I created new issue on github about this problem.
Additionally I got it changing PHPUnit "Autoload.php".
I replaced
spl_autoload_register(
function ($class){...}
);
to
function phpunit_autoload($class)
{ ... }
spl_autoload_register("phpunit_autoload");
I know, this is not so good idea to change PHPUnit files but it will works temporary as long as this bug still opened.
It worked for me after changing the autoload php file on 3.7.7 as well. Thanks for the updates.
lexand
(Dorogikh Alexander)
October 17, 2012, 3:47pm
13
Has someone posted this as issue?
my solution is
<?php
/**
* This file contains the CTestCase class.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
require_once('PHPUnit/Autoload.php');
if (version_compare('3.7.7', PHPUnit_Runner_Version::VERSION) >= 0)
{
spl_autoload_unregister('phpunit_autoload');
Yii::registerAutoloader('phpunit_autoload');
}
/**
* CTestCase is the base class for all test case classes.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @package system.test
* @since 1.1
*/
abstract class CTestCase extends PHPUnit_Framework_TestCase
{
}
msoa
October 18, 2012, 12:17am
14
Hi all. I have some problem.
I created new issue on github about this problem.
github.com/yiisoft/yii/issues/1563
Additionally I got it changing PHPUnit "Autoload.php".
I replaced
spl_autoload_register(
function ($class){...}
);
to
function phpunit_autoload($class)
{ ... }
spl_autoload_register("phpunit_autoload");
I know, this is not so good idea to change PHPUnit files but it will works temporary as long as this bug still opened.
This dont work for me. what can i do?
msoa
October 18, 2012, 8:51am
15
Wow, there is no solution for it. i have stuck
Ubuntu 12.04 - Yii 1.1.11 - PHP PHP 5.3.10 - PHPUnit 3.7.7
please help!
msoa:
Wow, there is no solution for it. i have stuck
Ubuntu 12.04 - Yii 1.1.11 - PHP PHP 5.3.10 - PHPUnit 3.7.7
please help!
Is there really a massive amount of change between 3.7.1 and 3.7.7?
msoa
October 18, 2012, 9:01am
17
When i had installed it, the version was 3.7.7. how can install or downgrade to 3.7.1?
php, phpunit, pear
I had to uninstall/reinstall selenium and dbunit too, but it was easier than I thought
msoa
October 18, 2012, 9:30am
19
phpunit --version
PHPUnit 3.7.1 by Sebastian Bergmann.
phpunit protected/tests/unit/DbTest.php
PHP Fatal error: Class 'CTestCase' not found in /var/www/trackstar/protected/tests/unit/DbTest.php on line 3
The problem is still there !
msoa
October 18, 2012, 5:22pm
20
I tired from install/remove packages and search in google. is anyone how to i can completely remove PEAR Packages? I am going to a fresh install from scratch.
PLEASE HELP
This is latest error:
phpunit unit/DbTest.php
PHP Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to open stream: No such file or directory in /var/www/yii/framework/test/CWebTestCase.php on line 12
PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Extensions/SeleniumTestCase.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/yii/framework/test/CWebTestCase.php on line 12