2010-06-22 103 views
0

我在另一个forum问了同样的问题,但我还没有任何运气。所以请允许我在这里提出同样的问题。Zend_Test测试控制器

我想设置Zend_Test来测试我的控制器代码(我使用PHP,Zend Framework)。一切似乎都是正确的,根据official documentation,但我不断收到错误。

有关问题和设置的详细说明,请参考forum post这里。任何人都可以给我一个线索,我的设置有什么问题?

谢谢!问候,Andree。

回答

1

我已经使用setFallbackAutoloader(true),这是你以前的时候这个问题,但我从来没有能够追查根源。如果你谷歌错误,你会发现几个ZF错误报告提到它。

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

$autoLoader->suppressNotFoundWarnings(true); 

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

+0

是的,我没有在我的应用程序中使用备用自动载入器,但我在TestHelper.php中设置了一个。在我手动删除行和注册名称空间之后,测试运行正常。谢谢蒂姆! – Andree 2010-06-24 12:29:14

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(见类顶部的链接)。

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

欲了解更多信息,也请查看以下链接:

让我知道它是否也为你的案件做了工作。