【问题标题】:PHPUnit & Zend FrameworkPHPUnit & Zend 框架
【发布时间】:2013-05-22 07:00:30
【问题描述】:

我是单元测试的新手,我一直在研究我在互联网上找到的这个教程:

http://blog.fedecarg.com/2008/12/27/testing-zend-framework-controllers/

我的问题是我根本无法执行教程中显示的测试!

C

:\wamp\www\porttailmg\dev\tests>phpunit PHPUnit 3.7.21 by Sebastian 伯格曼。

从 C:\wamp\www\porttailmg\dev\tests\phpunit.xml 读取配置

时间:0 秒,内存:4.00Mb

没有执行任何测试!

生成 HTML 格式的代码覆盖率报告...完成

C:\wamp\www\porttailmg\dev\tests>

我的 bootstrap.php 是我编辑的唯一文件,因为我有以下错误:

注意:Zend_Loader::Zend_Loader::registerAutoload 已被弃用 1.8.0 并将与 2.0.0 一起删除;在 /www/zf-tutorial/library/Zend/Loader.php 中使用 Zend_Loader_Autoloader

我试图用那个来解决这个问题:

This is because you have the lines:

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

(or similar) somewhere in your bootstrap system.

The easiest solution is to change them to:

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('App_');

Where 'App_' is the name of a directory on your include path that has classes within it that follow the Zend Framework naming convention, so change it as appropriate and add more if you need them.

我的引导程序:

<?php 
error_reporting( E_ALL | E_STRICT );
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../applications'));
define('APPLICATION_ENV', 'loc');
define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/../library'));
define('TESTS_PATH', realpath(dirname(__FILE__)));

$_SERVER['SERVER_NAME'] = 'http://localhost';

$includePaths = array(LIBRARY_PATH, get_include_path());
set_include_path(implode(PATH_SEPARATOR, $includePaths));

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('LIBRARY_PATH');

Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
?>

提前感谢您的帮助

【问题讨论】:

    标签: php zend-framework phpunit


    【解决方案1】:

    您的设置看起来不错,但如果我没记错的话,zend 框架 1 只能与 >=3.5.x 一起使用,所以也许从 3.7 降级到 3.5 可能会奏效。请确保您的 phpunit.xml 文件设置正确并指向测试引导程序而不是您的应用程序引导程序。还要确保遵循单元测试名称约定。见http://phpunit.de/manual/3.5/en/index.html

    【讨论】:

    猜你喜欢
    • 2011-12-13
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    • 2011-12-23
    • 2011-04-03
    • 1970-01-01
    相关资源
    最近更新 更多