views:

260

answers:

4

Hello,

After installing phpUnit 3.5 i am trying to run my tests this way:

phpunit AllTests.php

But I am getting the following errors:

PHP Fatal error:  Class 'PHPUnit_TextUI_TestRunner' not found in /usr/share/php/PHPUnit/TextUI/Command.php on line 140
Fatal error: Class 'PHPUnit_TextUI_TestRunner' not found in /usr/share/php/PHPUnit/TextUI/Command.php on line 140

This is the contents of my AllTests.php

And here is the contents of Alltests.php

      <?php
    if (!defined('PHPUnit_MAIN_METHOD')) {
        define('PHPUnit_MAIN_METHOD', 'AllTests::main');
    }

    /**
     * TestHelper
     */
    require_once 'TestHelper.php';

    /**
     * @see SF_Unit_AllTests
     */
    require_once 'unit/AllTests.php';

    class AllTests
    {
        public static function main()
        {
            $parameters = array();

            PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
        }

        public static function suite()
        {
            $suite = new PHPUnit_Framework_TestSuite('EventManager');

            $suite->addTest(SF_Unit_AllTests::suite());

            return $suite;
        }
    }

    if (PHPUnit_MAIN_METHOD == 'AllTests::main') {
        AllTests::main();
    }

And here is the Unit/AllTests.php file

<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
    define('PHPUnit_MAIN_METHOD', 'SF_Unit_AllTests::main');
}

/**
 * Testhelper
 */
require_once dirname(__FILE__). '/../TestHelper.php';

/**
 * Include unit tests
 */
require_once('unit/Model/ModelAbstractTest.php');
require_once('unit/Model/EventTest.php');
//require_once('unit/Model/UserTest.php');
//require_once('unit/Model/AuthenticationTest.php);

/**
 * 
 * @author jigal
 *
 */
class SF_Unit_AllTests
{
    /**
     * 
     * @return unknown_type
     */
    public static function main()
    {
        PHPUnit_TextUI_TestRunner::run(self::suite());
    }

    /**
     * 
     * @return PHPUnit_Framework_TestSuite
     */
    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('EventManager Unit tests');
        $suite->addTestSuite('ModelAbstractTest');
        $suite->addTestSuite('EventTest');
        //$suite->addTestSuite('UserTest');
        //$suite->addTestSuite('Authentication')
        return $suite;
    }


}

if (PHPUnit_MAIN_METHOD == 'SF_Unit_AllTests::main') {
    SF_Unit_AllTests::main();
}

TestHelper.php

/**
 * Get PHPUnit
 */
require_once 'PHPUnit/Autoload.php';


/*
 * Set error reporting level
 */
error_reporting( E_ALL | E_STRICT );

/**
 * Default timezone
 */
date_default_timezone_set('Europe/London');

/*
 * Set the include path
 */
    /*
 * Set the include path
 */

    $root  = realpath(dirname(__FILE__) . '/../');
    $paths = array(
        "/usr/share/php/",
        "$root/library/Incu",
        "$root/library",
        "$root/tests",
        "$root/application"
    );
    set_include_path(get_include_path() . PATH_SEPARATOR . implode(PATH_SEPARATOR, $paths))

;


defined('APPLICATION_PATH')
    or define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
defined('APPLICATION_ENV')
or define('APPLICATION_ENV', 'development');
    require_once 'Zend/Application.php';
/**
 * Autoloader helpers
 */
function _SF_Autloader_SetUp() 
{
    require_once 'Zend/Loader/Autoloader.php';

    $loader = Zend_Loader_Autoloader::getInstance();
    $loader->registerNamespace('SF_');
    $application = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH.'/configs/events.ini'
    );

}

function _SF_Autloader_TearDown()
{
    Zend_Loader_Autoloader::resetInstance();
    $loader = Zend_Loader_Autoloader::getInstance();
    $loader->registerNamespace('SF_');
}

/**
 * Init autoloader
 */
_SF_Autloader_SetUp();

/**
 * Start session now!
 */
Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();

/**
 * Ignore folders from code coverage etc
 */
//PHPUnit_Util_Filter::addDirectoryToFilter("$root/tests");
//PHPUnit_Util_Filter::addDirectoryToFilter("$root/library/Zend");


PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist("$root/tests");
PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist("$root/library/Zend");

Any Idea's?

Update

I have added /usr/share/php to my include path. Now I am getting a different error:

PHPUnit 3.5.0 by Sebastian Bergmann.

....PHP Fatal error:  Class 'PHPUnit_Framework_MockObject_Generator' not found in /usr/share/php/PHPUnit/Framework/TestCase.php on line 1049

Fatal error: Class 'PHPUnit_Framework_MockObject_Generator' not found in /usr/share/php/PHPUnit/Framework/TestCase.php on line 1049
+3  A: 

You need to

require_once 'PHPUnit/Framework.php'

since phpunit 3.4 IIRC. Do not try to load the individual PHPUnit files anymore.

Oh, and in PHPUnit 3.5 there is an autoloader you should use:

require_once 'PHPUnit/Autoload.php';
cweiske
Well this gives me a notice that I dont need to require it anymore. Besides that the errors are not gone.
sanders
Yes that's what I had before. But that doesn't solve the problem.
sanders
I don't see any require_once "PHPUnit/Autoload.php"; code in your question, that's why I didn't see it.
cweiske
Its in the testhelper file which was required in one of the files. I have added it to my start post.
sanders
could it be that your sf autoloader breaks the phpunit one?
cweiske
I have added some updated information to my startpost.
sanders
So it seems I was wright about your autoloader:http://github.com/sebastianbergmann/phpunit/issues/closed#issue/31
cweiske
Yes, that solved the problem before the update in my startpost. ;-)
sanders
+1  A: 

For PHPUnit_Framework_MockObject_Generator error, had to manually get http://pear.phpunit.de/get/PHPUnit_MockObject-1.0.0.tgz and copy

PHPUnit_MockObject-1.0.0/PHPUnit/Framework/MockObject/

to

/usr/share/pear/PHPUnit/Framework/

Laurent Laffont
my PHPUNit is not installed in this directory. So that won't work
sanders
+1  A: 

I had to do the same thing @Laurent said, it doesn't matter where your phpunit is installed.

If you installed PHPUnit with pear just do a pear config-get php_dir in your shell. PHPUnit is most likely installed in that directory.

Wherever your PHPUnit is installed, replace the directory at PHPUnit/Framework/MockObject with the directory at PHPUnit/Framework/MockObject/ in the folder you downloaded from here http://pear.phpunit.de/get/PHPUnit_MockObject-1.0.0.tgz

Kayla Rose
Here is a the developer of PHPUnit explaining the problem http://sebastian-bergmann.de/archives/899-PHPUnit-3.5-Upgrading-Woes.html
Kayla Rose
+4  A: 

Well, actually Laurent Laffont kind of provided the correct answer: incomplete MockObject installation.

Per Installation Instructions you have to uninstall previous PHPUnit, before you will be able to install version 3.5

But that seems not enough, you also have to uninstall extra packages (in this case PHPUnit_MockObjects) and only then install new verstion:

pear uninstall phpunit/phpunit
pear uninstall phpunit/PHP_MockObject
pear install phpunit/phpunit

And that reinstalled PHP_MockObject package with all necessary files in place.

Victor Farazdagi
Thanks finally got this to work, had to change it to pear uninstall phpunit/PHPUnit_MockObjectthough
Paul Dixon