Yii Framework Forum: Phpunit Not Working With Yii Ctestcase (Phpunit_Autoload Not Found) - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Phpunit Not Working With Yii Ctestcase (Phpunit_Autoload Not Found) Rate Topic: ***** 1 Votes

#1 User is offline   Ash McConnell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-October 12

Posted 07 October 2012 - 04:11 PM

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
0

#2 User is offline   cruzeta51 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 01-October 12

Posted 07 October 2012 - 06:40 PM

View PostAsh McConnell, on 07 October 2012 - 04:11 PM, said:

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');
0

#3 User is offline   Ash McConnell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-October 12

Posted 08 October 2012 - 02:22 AM

View Postcruzeta51, on 07 October 2012 - 06:40 PM, said:

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
0

#4 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 08 October 2012 - 11:21 AM

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.
0

#5 User is offline   bobafett 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 27-June 12

Posted 09 October 2012 - 09:26 AM

I had the same issue and I temporally resolved it downgrading PHPUnit to version 3.7.1.
0

#6 User is offline   Ash McConnell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-October 12

Posted 10 October 2012 - 02:00 PM

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
0

#7 User is offline   thoellerl 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 10-October 12

Posted 10 October 2012 - 02:15 PM

View Postbobafett, on 09 October 2012 - 09:26 AM, said:

I had the same issue and I temporally resolved it downgrading PHPUnit to version 3.7.1.


It works with PhpUnit 3.7.1 for me too.
0

#8 User is offline   Ash McConnell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-October 12

Posted 10 October 2012 - 03:10 PM

Just tried this for myself. Works fine with 3.7.1, thanks for the help guys!

All the best,
Ash
0

#9 User is offline   Rats 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 12-October 12

Posted 12 October 2012 - 07:28 AM

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
0

#10 User is offline   emix 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 02-March 09
  • Location:Poland

Posted 12 October 2012 - 11:32 AM

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.
0

#11 User is offline   iDexter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-July 12

Posted 14 October 2012 - 07:35 AM

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.
0

#12 User is offline   Rats 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 12-October 12

Posted 15 October 2012 - 02:18 AM

It worked for me after changing the autoload php file on 3.7.7 as well. Thanks for the updates.
0

#13 User is offline   Alexandr Dorogikh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 29-September 09
  • Location:Ukraine, Bila Tserkva

Posted 17 October 2012 - 10:47 AM

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 &copy; 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
{
}

0

#14 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 258
  • Joined: 15-August 12

Posted 17 October 2012 - 07:17 PM

View PostiDexter, on 14 October 2012 - 07:35 AM, said:

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?
0

#15 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 258
  • Joined: 15-August 12

Posted 18 October 2012 - 03:51 AM

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!
0

#16 User is offline   Ash McConnell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-October 12

Posted 18 October 2012 - 03:57 AM

View Postmsoa, on 18 October 2012 - 03:51 AM, said:

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?
0

#17 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 258
  • Joined: 15-August 12

Posted 18 October 2012 - 04:01 AM

View PostAsh McConnell, on 18 October 2012 - 03:57 AM, said:

Is there really a massive amount of change between 3.7.1 and 3.7.7?

When i had installed it, the version was 3.7.7. how can install or downgrade to 3.7.1?
0

#18 User is offline   Ash McConnell 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-October 12

Posted 18 October 2012 - 04:07 AM

http://stackoverflow...it-through-pear

I had to uninstall/reinstall selenium and dbunit too, but it was easier than I thought
0

#19 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 258
  • Joined: 15-August 12

Posted 18 October 2012 - 04:30 AM

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 !
0

#20 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 258
  • Joined: 15-August 12

Posted 18 October 2012 - 12:22 PM

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

0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users