propel を使うためのテンプレート
askeet/test/unit/askeet に *Test.php を書く場合
※APP毎にユニットテストを別けるためにunitディレクトリの下にAPP毎のディレクトリを作った場合
※unitディレクトリ以下に作る場合は相対指定(/..)を一つ切り詰めよう
<?php
// askUser.php
mb_internal_encoding('utf-8');
mb_http_output('cp932');
ob_start('mb_output_handler');
defined('SF_APP') || define('SF_APP', 'askeet');
defined('SF_ENVIRONMENT') || define('SF_ENVIRONMENT', 'test');
defined('SF_DEBUG') || define('SF_DEBUG', true);
//begin initialise database code
include(dirname(__FILE__).'/../../bootstrap/unit.php');
include(dirname(__FILE__).'/../../../config/config.php');
require_once($sf_[[symfony]]_lib_dir.'/util/sfCore.class.php');
sfCore::initSimpleAutoload(
array(
dirname(__FILE__).'/../../../lib/model'
, dirname(__FILE__).'/../../../apps/'.SF_APP.'/lib'
, $sf_symfony_lib_dir
)
);
set_include_path($sf_symfony_lib_dir.'/vendor'.PATH_SEPARATOR.SF_ROOT_DIR.PATH_SEPARATOR.get_include_path());
sfCore::bootstrap($sf_symfony_lib_dir, $sf_symfony_data_dir);
sfContext::getInstance();
Propel::setConfiguration(sfPropelDatabase::getConfiguration());
Propel::initialize();
//end initialise database code
validator をテストするためのテンプレート
<?php
$app='frontend'; // Necessary for fonctional boostrap
include(dirname(__FILE__).'/../test/bootstrap/unit.php');
include(dirname(__FILE__).'/../test/bootstrap/functional.php');
require_once(dirname(__FILE__).'/../../lib/validator/myFooBarValidator.class.php');
$context = sfContext::getInstance();
$request = $context->getRequest();
$manager = new sfValidatorManager();
$manager->initialize($context);
$validator = new myFooBarValidator();
$validator->initialize($context);
// The values to validate.
// You can make a second array with values
// that are supposed to fail and do another
// loop below.
$values = Array('foo', 'bar');
$t = new lime_test(count($values) * 2, new lime_output_color());
$t->diag('myFooBarValidator()');
foreach ( $values as $value ) {
// Re-initialize the validation entry
// Without this, the first failure would
// cause any additional validation to
// be skipped
$manager->registerName('myname', false);
$manager->registerValidator('myname', $validator);
$request->setParameter('myname', $value);
$retval = $manager->execute();
$t->is($retval, true);
$t->is($request->getErrors(), Array());
// We remove the error so that the next loop
// does not carry the error.
$request->removeError('myname');
}
最終更新:2008年04月07日 22:26