我在几次会议上就这个主题发表过演讲,Zend 网站上什至还有一个网络研讨会(请参阅下面的链接)。
当我查看您的设置脚本时,您会发现其中有很多混乱,一旦您向应用程序添加更多功能,就很难维护。
我的 TestHelper 类仅包含以下内容:
<?php
/*
* Example test helper script taken from the blog article of Matthew Weier
* O'Phinney on September 11, 2008
*
* {@link http://weierophinney.net/matthew/archives/190-Setting-up-your-Zend_Test-test-suites.html}
*/
/*
* Start output buffering
*/
//ob_start();
/*
* Set error reporting to the level to which code must comply.
*/
error_reporting( E_ALL | E_STRICT );
/*
* Set default timezone
*/
date_default_timezone_set('Europe/Brussels');
/*
* Testing environment
*/
if (!defined('APPLICATION_ENV'))
define('APPLICATION_ENV', 'testing');
/*
* Determine the root, library, tests, and models directories
*/
$root = realpath(dirname(__FILE__) . '/../');
$library = $root . '/library';
$tests = $root . '/tests';
$models = $root . '/application/models';
$controllers = $root . '/application/controllers';
/*
* Set up application and test path constant for easy access helper classes
*/
if (!defined('APPLICATION_PATH'))
define('APPLICATION_PATH', $root . '/application');
define('TEST_PATH', $tests);
/*
* Prepend the library/, tests/, and models/ directories to the
* include_path. This allows the tests to run out of the box.
*/
$localFrameworkPaths = array (
'/usr/local/zend/share/ZendFramework/library',
'/opt/ZendFramework',
);
$include_path = get_include_path();
foreach ($localFrameworkPaths as $zfPath) {
$include_path = str_replace($zfPath . PATH_SEPARATOR, '', $include_path);
}
$path = array(
APPLICATION_PATH,
$models,
$library,
$tests,
$include_path,
);
set_include_path(implode(PATH_SEPARATOR, $path));
/**
* Register autoloader
*/
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
/**
* Store application root in registry
*/
Zend_Registry::set('testRoot', $root);
Zend_Registry::set('testBootstrap', $root . '/application/bootstrap.php');
/**
* Say to the sessions we use unit testing here
*/
Zend_Session::$_unitTestEnabled = true;
/*
* Unset global variables that are no longer needed.
*/
unset($root, $library, $models, $controllers, $tests, $path);
这类似于他的博客上提供的原始设置 MWOP(请参阅课程顶部的链接)。
就是这样,无需担心手动添加模块或跟踪应用程序架构中的更改,因为这将使用应用程序自己的引导程序。
有关更多信息,请查看以下链接:
让我知道它是否也适用于您的案例。