0

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

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

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

C

:\wamp\www\porttailmg\dev\tests>phpunit PHPUnit 3.7.21 由 Sebastian Bergmann 编写。

从 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();
?>

在此先感谢您的帮助

4

1 回答 1

2

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

于 2013-05-27T12:24:18.313 回答