我是单元测试的新手,我一直在研究在互联网上找到的本教程:
http://blog.fedecarg.com/2008/12/27/testing-zend-framework-controllers/
我的问题是我根本无法执行教程中显示的测试!
C
:\wamp\www\portailmg\dev\tests>phpunit PHPUnit 3.7.21 by Sebastian
Bergmann.
Configuration read from C:\wamp\www\portailmg\dev\tests\phpunit.xml
Time: 0 seconds, Memory: 4.00Mb
No tests executed!
Generating code coverage report in HTML format ... done
C:\wamp\www\portailmg\dev\tests>
我的bootstrap.php是我编辑的唯一文件,因为出现以下错误:
Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of
1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /www/zf-tutorial/library/Zend/Loader.php
我试图用这个来解决这个问题:
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.
我的引导程序:
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();
?>
在此先感谢您的帮助
您的设置看起来还可以,尽管如果我没记错的话,zend framework 1仅适用于> = 3.5.x,因此也许可以将其从3.7降级到3.5。 确保确保正确安装了phpunit.xml文件,并指向测试引导程序,而不是应用程序引导程序。 另外,请确保遵循单元测试名称约定。 参见http://phpunit.de/manual/3.5/en/index.html
没错,版本必须为3.5.x,另请参见此处的链接
framework.zend.com/blog/ ZF 1.12.4及更高版本支持/使用phpunit 3.7