Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'));
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
like image 708
sanders Avatar asked Nov 30 '22 17:11

sanders


1 Answers

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.

like image 69
Victor Farazdagi Avatar answered Dec 06 '22 08:12

Victor Farazdagi