我在另一个问题中问了同样的问题 论坛, ,但是我还没有运气。因此,请允许我在这里问同样的问题。

我想设置zend_test来测试我的控制器代码(我正在使用PHP,Zend Framework)。一切似乎都是正确的,并且根据 官方文件, ,但是我一直遇到错误。

有关问题和我的设置的详细说明,请参考 论坛帖子 这里。有人可以给我一个线索,我的设置怎么了?

谢谢!问候,安德烈。

有帮助吗?

解决方案

在使用SetFallBackautoloader(true)时,我遇到了这个问题,但是我从来没有能够跟踪根本原因。如果您在Google上搜索错误,您会发现一些提及的ZF错误报告。

您可以确认您的应用程序中还使用SetFallBackAutoloader(true)吗?如果不是,那么您可以从testHelper.php中删除该行。如果是,请尝试添加:

$autoLoader->suppressNotFoundWarnings(true);

在此之后,这通常为我解决问题(但可能会引起其他问题)。

其他提示

查看本教程,然后逐步按照它进行操作。对我来说很好。

教程phpunit + Zend框架

我在几个会议上就这个主题进行了讨论,甚至在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(请参阅班级顶部的链接)。

就是这样,无需担心手动添加模块或跟踪应用程序体系结构中的更改,因为这将使用您的应用程序自己的Bootstrap。

有关更多信息,请查看以下链接:

让我知道它是否也为您的案件完成了工作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top