简体   繁体   中英

Zend Framework + PHPUnit + Netbeans

I am hardly struggling against problem I experience for last two days. In fact I can not run test properly and receive:

PHP Fatal error: Call to undefined function Zend_Application() in C:\\xxxxxx\\tests\\application\\controllers\\IndexControllerTest.php on line 10

IndexControllerTest is very simple and looks like this:

require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';


class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{

    public function setUp()
    {   
        $this->bootstrap = Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
        parent::setUp();
    }

    public function appBootstrap() {
        $this->application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
        $this->application->bootstrap();
    }  
...

On the other hand bootstrap for tests contains only following code:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); //   /../application

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

Could you please help me with finding a problem? I would like to increase quality of mini project i indend to start but without testing it won't be possible.

Thank you in advance.


结构体

I added directories structure for my project. I keep zend libs in Source Files/library/Zend.

The error is coming from this:

$this->bootstrap = Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');

You're missing a new before Zend_Application .

But, it's not clear to me what you have the appBootstrap function for unless you're going to use it:

public function setUp()
{   
    $this->appBootstrap();
    parent::setUp();
}

What command are you using to run the tests? If you don't load the bootstrap you'll get this error. phpunit --bootstrap tests/bootstrap.php tests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM