0

I asked the same question in another forum, but I don't yet have any luck there. So please allow me to ask the same question here.

I want to setup Zend_Test to test my controller code (I am using PHP, Zend Framework). Everything seems to be correct and according to the official documentation, but I kept getting an error.

For the detailed explanation about the problem and my setup, please refer to the forum post here. Anyone can give me a clue, what's wrong with my setup?

Thanks! Regards, Andree.

4

3 回答 3

1

我之前在使用 setFallbackAutoloader(true) 时遇到过这个问题,但我一直无法找到根本原因。如果你谷歌这个错误,你会发现一些 ZF 错误报告提到它。

你能确认你在你的应用程序中也使用了 setFallbackAutoloader(true) 吗?如果没有,那么您可以从您的 TestHelper.php 中删除该行。如果是,请尝试添加:

$autoLoader->suppressNotFoundWarnings(true);

就在它之后,这通常会为我解决问题(但可能会导致其他一些问题)。

于 2010-06-22T10:14:22.177 回答
0

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

教程 PHPUNIT + Zend 框架

于 2010-06-22T08:19:48.020 回答
0

我在几次会议上就这个主题发表过演讲,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(请参阅课程顶部的链接)。

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

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

让我知道它是否也适用于您的案例。

于 2011-02-16T10:02:33.760 回答