开发者

Errors when testing with PHPUnit 3.5

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'))开发者_如何学Go;
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


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.


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/


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜