Setup PHPUnit with Zend Test

若如初见. 提交于 2019-12-05 07:07:52

I'm missing the loading of the application in your bootstrap.

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

To give you an idea about what I have in my tests/bootstrap.php (this is auto-generated by zend tool since release-1.11.4)

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../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();

As mentioned by the Zend Framework manual, best is to use PHPUnit 3.4.15 although I could run my tests using PHPUnit 3.6.12 as I'm isolating my tests to focus on my business logic and not the logic of Zend Framework.

I also modified my phpunit.xml as well into the following:

<phpunit bootstrap="./bootstrap.php" colors="true">
    <testsuite name="Application Test Suite">
        <directory>./application</directory>
    </testsuite>
    <testsuite name="Library Test Suite">
        <directory>./library</directory>
    </testsuite>

    <filter>
        <whitelist>
            <directory suffix=".php">../../library</directory>
            <directory suffix=".php">../../application</directory>
            <exclude>
                <directory suffix=".php">../../library/Zend</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

I hope this solves many of your issues you're facing now.

Best regards,

Michelangelo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!