当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPUnit_Util_Template类代码示例

本文整理汇总了PHP中PHPUnit_Util_Template的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Template类的具体用法?PHP PHPUnit_Util_Template怎么用?PHP PHPUnit_Util_Template使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PHPUnit_Util_Template类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * Runs the test case and collects the results in a TestResult object.
  * If no TestResult object is passed a new one will be created.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @return PHPUnit_Framework_TestResult
  * @throws InvalidArgumentException
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL)
 {
     if ($result === NULL) {
         $result = $this->createResult();
     }
     $this->setExpectedExceptionFromAnnotation();
     $this->setUseErrorHandlerFromAnnotation();
     $this->setUseOutputBufferingFromAnnotation();
     if ($this->useErrorHandler !== NULL) {
         $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
         $result->convertErrorsToExceptions($this->useErrorHandler);
     }
     $this->result = $result;
     if (!empty($this->dependencies) && !$this->inIsolation) {
         $className = get_class($this);
         $passed = $this->result->passed();
         $passedKeys = array_keys($passed);
         $numKeys = count($passedKeys);
         for ($i = 0; $i < $numKeys; $i++) {
             $pos = strpos($passedKeys[$i], ' with data set');
             if ($pos !== FALSE) {
                 $passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
             }
         }
         $passedKeys = array_flip(array_unique($passedKeys));
         foreach ($this->dependencies as $dependency) {
             if (strpos($dependency, '::') === FALSE) {
                 $dependency = $className . '::' . $dependency;
             }
             if (!isset($passedKeys[$dependency])) {
                 $result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
                 return;
             } else {
                 if (isset($passed[$dependency])) {
                     $this->dependencyInput[] = $passed[$dependency];
                 } else {
                     $this->dependencyInput[] = NULL;
                 }
             }
         }
     }
     if ($this->runTestInSeparateProcess === TRUE && $this->inIsolation !== TRUE && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) {
         $class = new ReflectionClass($this);
         $collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
         $template = new PHPUnit_Util_Template(sprintf('%s%sProcess%sTestCaseMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
         $template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'data' => addcslashes(serialize($this->data), "'"), 'dependencyInput' => addcslashes(serialize($this->dependencyInput), "'"), 'dataName' => $this->dataName, 'collectCodeCoverageInformation' => $collectCodeCoverageInformation ? 'TRUE' : 'FALSE', 'included_files' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getIncludedFilesAsString() : '', 'constants' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getConstantsAsString() : '', 'globals' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getGlobalsAsString() : '', 'include_path' => addslashes(get_include_path())));
         $this->prepareTemplate($template);
         $job = $template->render();
         $result->startTest($this);
         $jobResult = PHPUnit_Util_PHP::runJob($job);
         if (!empty($jobResult['stderr'])) {
             $time = 0;
             $result->addError($this, new RuntimeException(trim($jobResult['stderr'])), $time);
         } else {
             $childResult = @unserialize($jobResult['stdout']);
             if ($childResult !== FALSE) {
                 if (!empty($childResult['output'])) {
                     print $childResult['output'];
                 }
                 $this->testResult = $childResult['testResult'];
                 $this->numAssertions = $childResult['numAssertions'];
                 $childResult = $childResult['result'];
                 if ($collectCodeCoverageInformation) {
                     $codeCoverageInformation = $childResult->getRawCodeCoverageInformation();
                     $result->appendCodeCoverageInformation($this, $codeCoverageInformation[0]['data']);
                 }
                 $time = $childResult->time();
                 $notImplemented = $childResult->notImplemented();
                 $skipped = $childResult->skipped();
                 $errors = $childResult->errors();
                 $failures = $childResult->failures();
                 if (!empty($notImplemented)) {
                     $result->addError($this, $notImplemented[0]->thrownException(), $time);
                 } else {
                     if (!empty($skipped)) {
                         $result->addError($this, $skipped[0]->thrownException(), $time);
                     } else {
                         if (!empty($errors)) {
                             $result->addError($this, $errors[0]->thrownException(), $time);
                         } else {
                             if (!empty($failures)) {
                                 $result->addFailure($this, $failures[0]->thrownException(), $time);
                             }
                         }
                     }
                 }
             } else {
                 $time = 0;
                 $result->addError($this, new RuntimeException(trim($jobResult['stdout'])), $time);
             }
         }
         $result->endTest($this, $time);
//.........这里部分代码省略.........
开发者ID:febryantosulistyo,项目名称:ClassicSocial,代码行数:101,代码来源:TestCase.php

示例2: setTemplateVars

 /**
  * @param  PHPUnit_Util_Template $template
  * @param  string                $title
  * @param  string                $charset
  */
 protected function setTemplateVars(PHPUnit_Util_Template $template, $title, $charset)
 {
     $template->setVar(array('title' => $title, 'charset' => $charset, 'link' => $this->getLink(TRUE), 'num_executable_lines' => $this->getNumExecutableLines(), 'num_executed_lines' => $this->getNumExecutedLines(), 'lines_executed_percent' => $this->getLineExecutedPercent(), 'date' => $template->getDate(), 'phpunit_version' => PHPUnit_Runner_Version::id(), 'xdebug_version' => phpversion('xdebug'), 'php_version' => PHP_VERSION));
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:9,代码来源:Node.php

示例3: setTemplateVars

 /**
  * @param  PHPUnit_Util_Template $template
  * @param  string                 $title
  * @access public
  */
 protected function setTemplateVars(PHPUnit_Util_Template $template, $title)
 {
     $template->setVar(array('title', 'link', 'date', 'phpunit_version', 'xdebug_version'), array($title, $this->getLink(TRUE), $template->getDate(), PHPUnit_Runner_Version::id(), phpversion('xdebug')));
 }
开发者ID:453111208,项目名称:bbc,代码行数:9,代码来源:Node.php

示例4: 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 = '';
//.........这里部分代码省略.........
开发者ID:ahmedadham88,项目名称:enhanced-social-network,代码行数:101,代码来源:File.php

示例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();
 }
开发者ID:regnou,项目名称:AXEL-MOWER,代码行数:17,代码来源:Class.php

示例6: 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();
 }
开发者ID:febryantosulistyo,项目名称:ClassicSocial,代码行数:15,代码来源:Generator.php

示例7: 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();
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:maximseshuk,项目名称:lz77-kit,代码行数:101,代码来源:Skeleton.php

示例8: 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());
 }
开发者ID:regnou,项目名称:AXEL-MOWER,代码行数:10,代码来源:HTML.php

示例9: setTemplateVars

 /**
  * @param  PHPUnit_Util_Template $template
  * @param  string                 $title
  * @access public
  */
 protected function setTemplateVars(PHPUnit_Util_Template $template, $title)
 {
     $template->setVar(array('title', 'link', 'executable_lines', 'executed_lines', 'executed_percent', 'date', 'phpunit_version', 'xdebug_version'), array($title, $this->getLink(FALSE, TRUE), $this->getNumExecutableLines(), $this->getNumExecutedLines(), $this->getExecutedPercent(), $template->getDate(), PHPUnit_Runner_Version::id(), phpversion('xdebug')));
 }
开发者ID:dalinhuang,项目名称:shopexts,代码行数:9,代码来源:Node.php

示例10: 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;
 }
开发者ID:dalinhuang,项目名称:shopexts,代码行数:47,代码来源:Directory.php

示例11: setGraphVizTemplateVars

 /**
  * @param  PHPUnit_Util_Template $template
  * @param  string                 $target
  * @access public
  */
 protected function setGraphVizTemplateVars(PHPUnit_Util_Template $template, $target)
 {
     $testmap = '';
     $testmap_image = 'snow.png';
     $safeName = PHPUnit_Util_Filesystem::getSafeFilename($this->getName());
     $dotFile = $target . $safeName . '.dot';
     if (file_exists($dotFile) && class_exists('Image_GraphViz', FALSE)) {
         $pngFile = $target . $safeName . '.png';
         $mapFile = $target . $safeName . '.map';
         shell_exec(sprintf('neato -T png -o %s -T cmapx -o %s %s', $pngFile, $mapFile, $dotFile));
         if (file_exists($pngFile)) {
             $testmap_image = basename($pngFile);
         }
         if (file_exists($mapFile)) {
             $testmap = file_get_contents($mapFile);
             unlink($mapFile);
         }
         unlink($dotFile);
     }
     $template->setVar(array('testmap', 'testmap_image'), array($testmap, $testmap_image));
 }
开发者ID:dalinhuang,项目名称:shopexts,代码行数:26,代码来源:TestSuite.php

示例12: getDate

 /**
  * Returns the cached result of date('D M j G:i:s T Y').
  *
  * @return string
  * @since  Method available since Release 3.0.1
  */
 public static function getDate()
 {
     if (self::$date == '') {
         self::$date = date('D M j G:i:s T Y');
     }
     return self::$date;
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:13,代码来源:Template.php


注:本文中的PHPUnit_Util_Template类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。