0

I just stuck all this morning to figure out this, but without luck.

I create a test under tests/unit

<?php

  class DbTest extends CTestCase {

    public function testConnection() {
  $this->assertTrue( true );
    }
  }

?>

when I run it in the terminal

$ cd tests
$ phpunit unit/DbTest.php

I get this error:

PHPUnit 3.7.8 by Sebastian Bergmann.

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

my phpunit version is 3.7.8

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
Abderrahmane
  • 751
  • 1
  • 8
  • 10

2 Answers2

2

This is a known bug.

You need to alter the autoloader's

or

downgrade PHPUnit to 3.7.1

Community
  • 1
  • 1
Pentium10
  • 204,586
  • 122
  • 423
  • 502
2

Following thing worked well for me. Found googling. http://www.yiiframework.com/forum/index.php/topic/37294-yii-unit-test-not-working/

Old Code in framework/test/CTestCase.php, Comment it out.

   require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
   require_once('PHPUnit/Autoload.php');
   spl_autoload_unregister('phpunit_autoload');
   Yii::registerAutoloader('phpunit_autoload');

And change to this

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

}

Vemman
  • 21
  • 2