本文整理汇总了PHP中PHPUnit_Util_Template::render方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Template::render方法的具体用法?PHP PHPUnit_Util_Template::render怎么用?PHP PHPUnit_Util_Template::render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Template
的用法示例。
在下文中一共展示了PHPUnit_Util_Template::render方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Renders this node.
*
* @param string $target
* @param string $title
* @param string $charset
* @param boolean $highlight
* @param integer $lowUpperBound
* @param integer $highLowerBound
* @access public
*/
public function render($target, $title, $charset = 'ISO-8859-1', $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
{
if ($this->yui) {
$template = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'file.html');
$yuiTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'yui_item.js');
} else {
$template = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'file_no_yui.html');
}
$i = 1;
$lines = '';
$ignore = FALSE;
foreach ($this->codeLines as $line) {
if (strpos($line, '@codeCoverageIgnore') !== FALSE) {
if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) {
$ignore = TRUE;
} else {
if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) {
$ignore = FALSE;
}
}
}
$css = '';
if (!$ignore && isset($this->executedLines[$i])) {
$count = '';
// Array: Line is executable and was executed.
// count(Array) = Number of tests that hit this line.
if (is_array($this->executedLines[$i])) {
$color = 'lineCov';
$numTests = count($this->executedLines[$i]);
$count = sprintf('%8d', $numTests);
if ($this->yui) {
$buffer = '';
foreach ($this->executedLines[$i] as $test) {
if (!isset($test->__liHtml)) {
$test->__liHtml = '';
if ($test instanceof PHPUnit_Framework_SelfDescribing) {
$testName = $test->toString();
if ($test instanceof PHPUnit_Framework_TestCase) {
switch ($test->getStatus()) {
case PHPUnit_Runner_BaseTestRunner::STATUS_PASSED:
$testCSS = ' class=\\"testPassed\\"';
break;
case PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE:
$testCSS = ' class=\\"testFailure\\"';
break;
case PHPUnit_Runner_BaseTestRunner::STATUS_ERROR:
$testCSS = ' class=\\"testError\\"';
break;
case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE:
case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED:
$testCSS = ' class=\\"testIncomplete\\"';
break;
default:
$testCSS = '';
}
}
}
$test->__liHtml .= sprintf('<li%s>%s</li>', $testCSS, $testName);
}
$buffer .= $test->__liHtml;
}
if ($numTests > 1) {
$header = $numTests . ' tests cover';
} else {
$header = '1 test covers';
}
$header .= ' line ' . $i;
$yuiTemplate->setVar(array('line' => $i, 'header' => $header, 'tests' => $buffer), FALSE);
$this->yuiPanelJS .= $yuiTemplate->render();
}
} else {
if ($this->executedLines[$i] == -1) {
$color = 'lineNoCov';
$count = sprintf('%8d', 0);
} else {
$color = 'lineDeadCode';
$count = ' ';
}
}
$css = sprintf('<span class="%s"> %s : ', $color, $count);
}
$fillup = array_shift($this->codeLinesFillup);
if ($fillup > 0) {
$line .= str_repeat(' ', $fillup);
}
$lines .= sprintf('<span class="lineNum" id="container%d"><a name="%d"></a><a href="#%d" id="line%d">%8d</a> </span>%s%s%s' . "\n", $i, $i, $i, $i, $i, !empty($css) ? $css : ' : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : '');
$i++;
}
$items = '';
//.........这里部分代码省略.........
示例2: doRenderItem
protected function doRenderItem(array $data, $lowUpperBound, $highLowerBound, $template = NULL)
{
if ($template === NULL) {
if ($this instanceof PHPUnit_Util_Report_Node_Directory) {
$template = 'directory_item.html';
} else {
$template = 'file_item.html';
}
}
$itemTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . $template);
if ($data['numClasses'] > 0) {
list($classesColor, $classesLevel) = $this->getColorLevel($data['testedClassesPercent'], $lowUpperBound, $highLowerBound);
$classesNumber = $data['numTestedClasses'] . ' / ' . $data['numClasses'];
} else {
$classesColor = 'snow';
$classesLevel = 'None';
$classesNumber = ' ';
}
if ($data['numMethods'] > 0) {
list($methodsColor, $methodsLevel) = $this->getColorLevel($data['testedMethodsPercent'], $lowUpperBound, $highLowerBound);
$methodsNumber = $data['numTestedMethods'] . ' / ' . $data['numMethods'];
} else {
$methodsColor = 'snow';
$methodsLevel = 'None';
$methodsNumber = ' ';
}
list($linesColor, $linesLevel) = $this->getColorLevel($data['executedLinesPercent'], $lowUpperBound, $highLowerBound);
if ($data['name'] == '<b><a href="#0">*</a></b>') {
$functions = TRUE;
} else {
$functions = FALSE;
}
$itemTemplate->setVar(array('name' => $functions ? 'Functions' : $data['name'], 'itemClass' => isset($data['itemClass']) ? $data['itemClass'] : 'coverItem', 'classes_color' => $classesColor, 'classes_level' => $functions ? 'None' : $classesLevel, 'classes_tested_width' => floor($data['testedClassesPercent']), 'classes_tested_percent' => !$functions && $data['numClasses'] > 0 ? $data['testedClassesPercent'] . '%' : ' ', 'classes_not_tested_width' => 100 - floor($data['testedClassesPercent']), 'classes_number' => $functions ? ' ' : $classesNumber, 'methods_color' => $methodsColor, 'methods_level' => $methodsLevel, 'methods_tested_width' => floor($data['testedMethodsPercent']), 'methods_tested_percent' => $data['numMethods'] > 0 ? $data['testedMethodsPercent'] . '%' : ' ', 'methods_not_tested_width' => 100 - floor($data['testedMethodsPercent']), 'methods_number' => $methodsNumber, 'lines_color' => $linesColor, 'lines_level' => $linesLevel, 'lines_executed_width' => floor($data['executedLinesPercent']), 'lines_executed_percent' => $data['executedLinesPercent'] . '%', 'lines_not_executed_width' => 100 - floor($data['executedLinesPercent']), 'num_executable_lines' => $data['numExecutableLines'], 'num_executed_lines' => $data['numExecutedLines']));
return $itemTemplate->render();
}
示例3: generateMockedMethodDefinition
/**
* @param string $templateDir
* @param string $className
* @param string $methodName
* @param string $modifier
* @param string $arguments
* @param string $reference
* @return string
*/
protected static function generateMockedMethodDefinition($templateDir, $className, $methodName, $modifier = 'public', $arguments = '', $reference = '')
{
$template = new PHPUnit_Util_Template($templateDir . 'mocked_method.tpl');
$template->setVar(array('arguments' => $arguments, 'class_name' => $className, 'method_name' => $methodName, 'modifier' => $modifier, 'reference' => $reference));
return $template->render();
}
示例4: doRenderItem
protected function doRenderItem(array $data, $lowUpperBound, $highLowerBound, $template = 'item.html')
{
$itemTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . $template);
list($classesColor, $classesLevel) = $this->getColorLevel($data['calledClassesPercent'], $lowUpperBound, $highLowerBound);
list($methodsColor, $methodsLevel) = $this->getColorLevel($data['calledMethodsPercent'], $lowUpperBound, $highLowerBound);
list($linesColor, $linesLevel) = $this->getColorLevel($data['executedLinesPercent'], $lowUpperBound, $highLowerBound);
$itemTemplate->setVar(array('name' => $data['name'], 'itemClass' => isset($data['itemClass']) ? $data['itemClass'] : 'coverItem', 'classes_color' => $classesColor, 'classes_level' => $classesLevel, 'classes_called_width' => floor($data['calledClassesPercent']), 'classes_called_percent' => $data['calledClassesPercent'], 'classes_not_called_width' => 100 - floor($data['calledClassesPercent']), 'num_classes' => $data['numClasses'], 'num_called_classes' => $data['numCalledClasses'], 'methods_color' => $methodsColor, 'methods_level' => $methodsLevel, 'methods_called_width' => floor($data['calledMethodsPercent']), 'methods_called_percent' => $data['calledMethodsPercent'], 'methods_not_called_width' => 100 - floor($data['calledMethodsPercent']), 'num_methods' => $data['numMethods'], 'num_called_methods' => $data['numCalledMethods'], 'lines_color' => $linesColor, 'lines_level' => $linesLevel, 'lines_executed_width' => floor($data['executedLinesPercent']), 'lines_executed_percent' => $data['executedLinesPercent'], 'lines_not_executed_width' => 100 - floor($data['executedLinesPercent']), 'num_executable_lines' => $data['numExecutableLines'], 'num_executed_lines' => $data['numExecutedLines']));
return $itemTemplate->render();
}
示例5: generate
/**
* Generates the class' source.
*
* @return mixed
*/
public function generate()
{
$methods = '';
foreach ($this->findTestedMethods() as $method) {
$methodTemplate = new PHPUnit_Util_Template(sprintf('%s%sTemplate%sMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
$methodTemplate->setVar(array('methodName' => $method));
$methods .= $methodTemplate->render();
}
$classTemplate = new PHPUnit_Util_Template(sprintf('%s%sTemplate%sClass.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
$classTemplate->setVar(array('className' => $this->outClassName['fullyQualifiedClassName'], 'methods' => $methods, 'date' => date('Y-m-d'), 'time' => date('H:i:s')));
return $classTemplate->render();
}
示例6: generate
/**
* Generates the test class' source.
*
* @param boolean $verbose
* @return mixed
*/
public function generate($verbose = FALSE)
{
$class = new ReflectionClass($this->className);
$methods = '';
$incompleteMethods = '';
foreach ($class->getMethods() as $method) {
if (!$method->isConstructor() && !$method->isAbstract() && $method->isPublic() && $method->getDeclaringClass()->getName() == $this->className) {
$assertAnnotationFound = FALSE;
if (preg_match_all('/@assert(.*)$/Um', $method->getDocComment(), $annotations)) {
foreach ($annotations[1] as $annotation) {
if (preg_match('/\\((.*)\\)\\s+([^\\s]*)\\s+(.*)/', $annotation, $matches)) {
switch ($matches[2]) {
case '==':
$assertion = 'Equals';
break;
case '!=':
$assertion = 'NotEquals';
break;
case '===':
$assertion = 'Same';
break;
case '!==':
$assertion = 'NotSame';
break;
case '>':
$assertion = 'GreaterThan';
break;
case '>=':
$assertion = 'GreaterThanOrEqual';
break;
case '<':
$assertion = 'LessThan';
break;
case '<=':
$assertion = 'LessThanOrEqual';
break;
case 'throws':
$assertion = 'exception';
break;
default:
throw new RuntimeException();
}
if ($assertion == 'exception') {
$template = 'TestMethodException';
} else {
if ($assertion == 'Equals' && strtolower($matches[3]) == 'true') {
$assertion = 'True';
$template = 'TestMethodBool';
} else {
if ($assertion == 'NotEquals' && strtolower($matches[3]) == 'true') {
$assertion = 'False';
$template = 'TestMethodBool';
} else {
if ($assertion == 'Equals' && strtolower($matches[3]) == 'false') {
$assertion = 'False';
$template = 'TestMethodBool';
} else {
if ($assertion == 'NotEquals' && strtolower($matches[3]) == 'false') {
$assertion = 'True';
$template = 'TestMethodBool';
} else {
$template = 'TestMethod';
}
}
}
}
}
if ($method->isStatic()) {
$template .= 'Static';
}
$methodTemplate = new PHPUnit_Util_Template(sprintf('%s%sSkeleton%s%s.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $template));
$origMethodName = $method->getName();
$methodName = ucfirst($origMethodName);
if (isset($this->methodNameCounter[$methodName])) {
$this->methodNameCounter[$methodName]++;
} else {
$this->methodNameCounter[$methodName] = 1;
}
if ($this->methodNameCounter[$methodName] > 1) {
$methodName .= $this->methodNameCounter[$methodName];
}
$methodTemplate->setVar(array('annotation' => trim($annotation), 'arguments' => $matches[1], 'assertion' => isset($assertion) ? $assertion : '', 'expected' => $matches[3], 'origMethodName' => $origMethodName, 'className' => $this->className, 'methodName' => $methodName));
$methods .= $methodTemplate->render();
$assertAnnotationFound = TRUE;
}
}
}
if (!$assertAnnotationFound) {
$methodTemplate = new PHPUnit_Util_Template(sprintf('%s%sSkeleton%sIncompleteTestMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
$methodTemplate->setVar(array('methodName' => ucfirst($method->getName())));
$incompleteMethods .= $methodTemplate->render();
}
}
}
//.........这里部分代码省略.........
示例7: endRun
/**
* Handler for 'end run' event.
*
*/
protected function endRun()
{
$scenariosTemplate = new PHPUnit_Util_Template($this->templatePath . 'scenarios.html');
$scenariosTemplate->setVar(array('scenarios' => $this->scenarios, 'successfulScenarios' => $this->successful, 'failedScenarios' => $this->failed, 'skippedScenarios' => $this->skipped, 'incompleteScenarios' => $this->incomplete));
$this->write($scenariosTemplate->render());
}
示例8: doRenderItems
/**
* @param array $items
* @param boolean $includeDetails
* @return string
* @access protected
*/
protected function doRenderItems(array $items, $includeDetails)
{
$result = '';
foreach ($items as $item) {
$itemTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::getTemplatePath() . 'coverage_item.html');
$details = '';
if ($includeDetails) {
foreach ($item->getCoveringTests() as $suite => $tests) {
$detailsHeaderTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::getTemplatePath() . 'coverage_item_details_header.html');
$detailsHeaderTemplate->setVar('link', sprintf('<a href="%s-test.html">%s</a>', PHPUnit_Util_Filesystem::getSafeFilename($suite), $suite));
$details .= $detailsHeaderTemplate->render();
foreach ($tests as $test => $_test) {
$detailsTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::getTemplatePath() . 'coverage_item_details.html');
if ($_test['object']->getResult() !== PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
$failure = sprintf('<br /><pre>%s</pre>', htmlspecialchars($_test['object']->getResult()->exceptionMessage()));
} else {
$failure = '';
}
$detailsTemplate->setVar(array('item', 'executed_percent', 'executed_lines', 'executable_lines'), array($test . $failure, sprintf('%01.2f', $_test['numLinesExecuted'] / $item->getNumExecutableLines() * 100), $_test['numLinesExecuted'], $item->getNumExecutableLines()));
$details .= $detailsTemplate->render();
}
}
}
$floorPercent = floor($item->getExecutedPercent());
if ($floorPercent < self::LOW_UPPER_BOUND) {
$color = 'scarlet_red';
$level = 'Lo';
} else {
if ($floorPercent >= self::LOW_UPPER_BOUND && $floorPercent < self::HIGH_LOWER_BOUND) {
$color = 'butter';
$level = 'Med';
} else {
$color = 'chameleon';
$level = 'Hi';
}
}
$itemTemplate->setVar(array('link', 'color', 'level', 'executed_width', 'executed_percent', 'not_executed_width', 'executable_lines', 'executed_lines', 'details'), array($item->getLink(FALSE, FALSE), $color, $level, floor($item->getExecutedPercent()), $item->getExecutedPercent(), 100 - floor($item->getExecutedPercent()), $item->getNumExecutableLines(), $item->getNumExecutedLines(), $details));
$result .= $itemTemplate->render();
}
return $result;
}
示例9: renderItems
/**
* @return string
* @access protected
*/
protected function renderItems()
{
$result = '';
foreach ($this->tests as $item) {
$itemTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::getTemplatePath() . 'testsuite_item.html');
$resultCode = $item->getResult();
if ($resultCode instanceof PHPUnit_Framework_TestFailure) {
if ($resultCode->isFailure()) {
$testResult = 'Failure';
} else {
if ($resultCode->thrownException() instanceof PHPUnit_Framework_SkippedTest) {
$testResult = 'Skipped';
} else {
if ($resultCode->thrownException() instanceof PHPUnit_Framework_IncompleteTest) {
$testResult = 'Incomplete';
} else {
$testResult = 'Error';
}
}
}
} else {
if ($resultCode === PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
$testResult = 'Passed';
} else {
$testResult = 'Error';
}
}
switch ($testResult) {
case 'Passed':
case 'Skipped':
$color = 'chameleon';
break;
case 'Incomplete':
$color = 'butter';
break;
case 'Error':
case 'Failure':
default:
$color = 'scarlet_red';
}
$itemTemplate->setVar(array('color', 'result', 'name'), array($color, $testResult, $item->getName()));
$result .= $itemTemplate->render();
}
return $result;
}