本文整理汇总了PHP中PHPUnit_Framework_TestCase::prepareTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::prepareTemplate方法的具体用法?PHP PHPUnit_Framework_TestCase::prepareTemplate怎么用?PHP PHPUnit_Framework_TestCase::prepareTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestCase
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestCase::prepareTemplate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareTemplate
/**
* Define constants after including files.
*/
function prepareTemplate(Text_Template $template)
{
$template->setVar(array('constants' => ''));
$template->setVar(array('wp_constants' => PHPUnit_Util_GlobalState::getConstantsAsString()));
parent::prepareTemplate($template);
}
示例2: prepareTemplate
/**
* Performs custom preparations on the process isolation template.
*
* @param Text_Template $template
*
* @author Felix Gilcher <felix.gilcher@bitextender.com>
* @since 1.0.2
*/
protected function prepareTemplate(Text_Template $template)
{
parent::prepareTemplate($template);
// FIXME: workaround for php unit bug (https://github.com/sebastianbergmann/phpunit/pull/1338)
$template->setVar(array('dataName' => "'.(" . var_export($this->myDataName, true) . ").'"));
// FIXME: if we have full composer autoloading we can remove this
// we need to restore the included files even without global state, since otherwise
// the agavi test class files would be missing.
// We can't write include()s directly since Agavi possibly get's bootstrapped later
// in the process (but before the test instance is created) and if we'd load any
// files which are being loaded by the bootstrap process chaos would ensue since
// the bootstrap process uses plain include()s without _once
$fileAutoloader = sprintf('
spl_autoload_register(function($name) {
$classMap = %s;
if(isset($classMap[$name])) {
include($classMap[$name]);
}
});
', var_export($this->getDependendClasses(), true));
// these constants are either used by out bootstrap wrapper script
// (AGAVI_TESTING_ORIGINAL_PHPUNIT_BOOTSTRAP) or can be used by the user's
// bootstrap script (AGAVI_TESTING_IN_SEPERATE_PROCESS)
$constants = sprintf('
define("AGAVI_TESTING_IN_SEPERATE_PROCESS", true);
define("AGAVI_TESTING_ORIGINAL_PHPUNIT_BOOTSTRAP", %s);
', var_export(isset($GLOBALS["__PHPUNIT_BOOTSTRAP"]) ? $GLOBALS["__PHPUNIT_BOOTSTRAP"] : null, true));
$isolatedTestSettings = array('environment' => $this->getIsolationEnvironment(), 'defaultContext' => $this->getIsolationDefaultContext(), 'clearCache' => $this->getClearCache(), 'bootstrap' => $this->doBootstrap());
$globals = sprintf('
$GLOBALS["AGAVI_TESTING_CONFIG"] = %s;
$GLOBALS["AGAVI_TESTING_ISOLATED_TEST_SETTINGS"] = %s;
$GLOBALS["__PHPUNIT_BOOTSTRAP"] = %s;
', var_export(AgaviConfig::toArray(), true), var_export($isolatedTestSettings, true), var_export(__DIR__ . '/scripts/IsolatedBootstrap.php', true));
if (!$this->preserveGlobalState) {
$template->setVar(array('included_files' => $fileAutoloader, 'constants' => $constants, 'globals' => $globals));
} else {
// HACK: oh great, text/template doesn't expose the already set variables, but we need to modify
// them instead of overwriting them. So let's use the reflection to the rescue here.
$reflected = new ReflectionObject($template);
$property = $reflected->getProperty('values');
$property->setAccessible(true);
$oldVars = $property->getValue($template);
$template->setVar(array('included_files' => $fileAutoloader, 'constants' => $oldVars['constants'] . PHP_EOL . $constants, 'globals' => $oldVars['globals'] . PHP_EOL . $globals));
}
}
示例3: prepareTemplate
/**
* Define constants after requires/includes
*
* See http://kpayne.me/2012/07/02/phpunit-process-isolation-and-constant-already-defined/
* for more details
*
* @param \Text_Template $template
*/
public function prepareTemplate(\Text_Template $template)
{
$template->setVar(array('globals' => '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = \'' . $GLOBALS['__PHPUNIT_BOOTSTRAP'] . '\';'));
parent::prepareTemplate($template);
}
示例4: prepareTemplate
/**
* Performs custom preparations on the process isolation template.
*
* @param Text_Template $template
*
* @author Felix Gilcher <felix.gilcher@bitextender.com>
* @since 1.0.2
*/
protected function prepareTemplate(Text_Template $template)
{
parent::prepareTemplate($template);
$vars = array('agavi_environment' => '', 'agavi_default_context' => '', 'agavi_clear_cache' => 'false');
if (null !== ($env = $this->getIsolationEnvironment())) {
$vars['agavi_environment'] = $env;
}
if (null !== ($ctx = $this->getIsolationDefaultContext())) {
$vars['agavi_default_context'] = $ctx;
}
if ($this->getClearCache()) {
$vars['agavi_clear_cache'] = 'true';
// literal strings required for proper template rendering
}
$template->setVar($vars);
$templateFile = $this->getTemplateFile();
if (null !== $templateFile) {
$template->setFile($templateFile);
}
}