J'ai donné une conférence sur ce sujet lors de plusieurs conférences, et il y a même un webinaire sur le site Web de Zend (voir les liens ci-dessous).
Lorsque je regarde vos scripts d'installation, il y a beaucoup d'encombrement dans le fichier, ce qui le rend difficile à maintenir une fois que vous avez ajouté plus de fonctionnalités à votre application.
Ma classe TestHelper ne contient que les éléments suivants:
<?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);
Ceci est similaire aux paramètres d'origine MWOP fourni sur son blog (voir le lien au-dessus de la classe).
Et c'est tout, pas besoin de vous soucier d'ajouter des modules manuellement ou de suivre les changements dans l'architecture de votre application, car cela utilisera le bootstrap de votre application.
Pour plus d'informations, ne consultez ces liens:
Permettez-moi savoir si elle a fait le travail pour votre cas aussi bien.
Oui, je n'utilise pas l'autovaler de secours dans mon application, mais j'en ai défini un dans TestHelper.php. Après avoir supprimé la ligne et enregistré l'espace de noms manuellement, le test fonctionne correctement. Merci Tim! – Andree