0

別のフォーラムで同じ質問をしましたが、まだ運がありません。ですから、ここで同じ質問をさせてください。

コントローラーコードをテストするためにZend_Testをセットアップしたい(PHP、Zend Frameworkを使用しています)。すべてが正しく、公式ドキュメントによると、エラーが発生し続けました。

問題と私の設定の詳細については、こちらのフォーラム投稿を参照してください。誰でも私に手がかりを与えることができます、私のセットアップの何が問題になっていますか?

ありがとう!よろしく、アンドリー。

4

3 に答える 3

1

setFallbackAutoloader(true)を使用しているときにこの問題が発生しましたが、根本的な原因を突き止めることができませんでした。エラーをグーグルで検索すると、それについて言及しているZFバグレポートがいくつか見つかります。

アプリケーションでsetFallbackAutoloader(true)も使用していることを確認できますか?そうでない場合は、TestHelper.phpからその行を削除できます。もしそうなら、追加してみてください:

$autoLoader->suppressNotFoundWarnings(true);

その直後、これで通常は問題が解決します(ただし、他の問題が発生する可能性があります)。

于 2010-06-22T10:14:22.177 に答える
0

私はいくつかの会議でこのテーマについて講演しましたが、Zend Webサイトにはウェビナーもあります(以下のリンクを参照)。

セットアップスクリプトを見ると、そこには多くの混乱があり、アプリケーションに機能を追加すると、保守が困難になります。

私の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 に答える
0

このチュートリアルをチェックして、ステップバイステップでそれに従ってください。私にとってはうまくいきます。

チュートリアルPHPUNIT+Zend Framework

于 2010-06-22T08:19:48.020 に答える