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


PHP PHPUnit_Util_XML::convertToUtf8方法代码示例

本文整理汇总了PHP中PHPUnit_Util_XML::convertToUtf8方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_XML::convertToUtf8方法的具体用法?PHP PHPUnit_Util_XML::convertToUtf8怎么用?PHP PHPUnit_Util_XML::convertToUtf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPUnit_Util_XML的用法示例。


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

示例1: process

 /**
  * @param  PHPUnit_Framework_TestResult $result
  */
 public function process(PHPUnit_Framework_TestResult $result)
 {
     $sutData = $result->getCodeCoverageInformation();
     $sutFiles = PHPUnit_Util_CodeCoverage::getSummary($sutData, TRUE);
     $allData = $result->getCodeCoverageInformation(FALSE);
     $allFiles = PHPUnit_Util_CodeCoverage::getSummary($allData, TRUE);
     $testFiles = array_diff(array_keys($allFiles), array_keys($sutFiles));
     foreach (array_keys($allFiles) as $key) {
         if (!@in_array($key, $testFiles)) {
             unset($allFiles[$key]);
         }
     }
     $allCommonPath = PHPUnit_Util_Filesystem::reducePaths($allFiles);
     $sutCommonPath = PHPUnit_Util_Filesystem::reducePaths($sutFiles);
     $testFiles = $allFiles;
     unset($allData);
     unset($allFiles);
     unset($sutData);
     $testToCoveredLinesMap = array();
     $time = time();
     foreach ($sutFiles as $filename => $data) {
         $fullPath = $sutCommonPath . DIRECTORY_SEPARATOR . $filename;
         if (file_exists($fullPath)) {
             $fullPath = realpath($fullPath);
             $document = new DOMDocument('1.0', 'UTF-8');
             $document->formatOutput = TRUE;
             $coveredFile = $document->createElement('coveredFile');
             $coveredFile->setAttribute('fullPath', $fullPath);
             $coveredFile->setAttribute('shortenedPath', $filename);
             $coveredFile->setAttribute('generated', $time);
             $coveredFile->setAttribute('phpunit', PHPUnit_Runner_Version::id());
             $document->appendChild($coveredFile);
             $lines = file($fullPath, FILE_IGNORE_NEW_LINES);
             $lineNum = 1;
             foreach ($lines as $line) {
                 if (isset($data[$lineNum])) {
                     if (is_array($data[$lineNum])) {
                         $count = count($data[$lineNum]);
                     } else {
                         $count = $data[$lineNum];
                     }
                 } else {
                     $count = -3;
                 }
                 $xmlLine = $coveredFile->appendChild($document->createElement('line'));
                 $xmlLine->setAttribute('lineNumber', $lineNum);
                 $xmlLine->setAttribute('executed', $count);
                 $xmlLine->appendChild($document->createElement('body', htmlspecialchars(PHPUnit_Util_XML::convertToUtf8($line), ENT_COMPAT, 'UTF-8')));
                 if (isset($data[$lineNum]) && is_array($data[$lineNum])) {
                     $xmlTests = $document->createElement('tests');
                     $xmlLine->appendChild($xmlTests);
                     foreach ($data[$lineNum] as $test) {
                         $xmlTest = $xmlTests->appendChild($document->createElement('test'));
                         if ($test instanceof PHPUnit_Framework_TestCase) {
                             $xmlTest->setAttribute('name', $test->getName());
                             $xmlTest->setAttribute('status', $test->getStatus());
                             if ($test->hasFailed()) {
                                 $xmlTest->appendChild($document->createElement('message', htmlspecialchars(PHPUnit_Util_XML::convertToUtf8($test->getStatusMessage()), ENT_COMPAT, 'UTF-8')));
                             }
                             $class = new ReflectionClass($test);
                             $testFullPath = $class->getFileName();
                             $testShortenedPath = str_replace($allCommonPath, '', $testFullPath);
                             $methodName = $test->getName(FALSE);
                             if ($class->hasMethod($methodName)) {
                                 $method = $class->getMethod($methodName);
                                 $startLine = $method->getStartLine();
                                 $xmlTest->setAttribute('class', $class->getName());
                                 $xmlTest->setAttribute('fullPath', $testFullPath);
                                 $xmlTest->setAttribute('shortenedPath', $testShortenedPath);
                                 $xmlTest->setAttribute('line', $startLine);
                                 if (!isset($testToCoveredLinesMap[$testFullPath][$startLine])) {
                                     $testToCoveredLinesMap[$testFullPath][$startLine] = array();
                                 }
                                 if (!isset($testToCoveredLinesMap[$testFullPath][$startLine][$fullPath])) {
                                     $testToCoveredLinesMap[$testFullPath][$startLine][$fullPath] = array('coveredLines' => array($lineNum), 'shortenedPath' => $filename);
                                 } else {
                                     $testToCoveredLinesMap[$testFullPath][$startLine][$fullPath]['coveredLines'][] = $lineNum;
                                 }
                             }
                         }
                     }
                 }
                 $lineNum++;
             }
             $document->save(sprintf('%s%s.xml', $this->directory, PHPUnit_Util_Filesystem::getSafeFilename(str_replace(DIRECTORY_SEPARATOR, '_', $filename))));
         }
     }
     foreach ($testFiles as $filename => $data) {
         $fullPath = $allCommonPath . DIRECTORY_SEPARATOR . $filename;
         if (file_exists($fullPath)) {
             $document = new DOMDocument('1.0', 'UTF-8');
             $document->formatOutput = TRUE;
             $testFile = $document->createElement('testFile');
             $testFile->setAttribute('fullPath', $fullPath);
             $testFile->setAttribute('shortenedPath', $filename);
             $testFile->setAttribute('generated', $time);
             $testFile->setAttribute('phpunit', PHPUnit_Runner_Version::id());
//.........这里部分代码省略.........
开发者ID:cjmi,项目名称:miniblog,代码行数:101,代码来源:Source.php

示例2: addSkippedTest

 /**
  * Skipped test.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  Exception              $e
  * @param  float                  $time
  * @since  Method available since Release 3.0.0
  */
 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
 {
     if ($this->logIncompleteSkipped) {
         $error = $this->document->createElement('error');
         $error->setAttribute('type', get_class($e));
         $error->appendChild($this->document->createCDATASection(PHPUnit_Util_XML::convertToUtf8("Skipped Test\n" . PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE))));
         $this->currentTestCase->appendChild($error);
         $this->testSuiteErrors[$this->testSuiteLevel]++;
     } else {
         $this->attachCurrentTestCase = FALSE;
     }
 }
开发者ID:maximseshuk,项目名称:lz77-kit,代码行数:20,代码来源:XML.php

示例3: process

 /**
  * @param  PHPUnit_Framework_TestResult $result
  */
 public function process(PHPUnit_Framework_TestResult $result, $minLines = 5, $minMatches = 70)
 {
     $codeCoverage = $result->getCodeCoverageInformation();
     $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage);
     $files = array_keys($summary);
     $metrics = new PHPUnit_Util_Metrics_Project($files, $summary, TRUE, $minLines, $minMatches);
     $document = new DOMDocument('1.0', 'UTF-8');
     $document->formatOutput = TRUE;
     $cpd = $document->createElement('pmd-cpd');
     $cpd->setAttribute('version', 'PHPUnit ' . PHPUnit_Runner_Version::id());
     $document->appendChild($cpd);
     foreach ($metrics->getDuplicates() as $duplicate) {
         $xmlDuplication = $cpd->appendChild($document->createElement('duplication'));
         $xmlDuplication->setAttribute('lines', $duplicate['numLines']);
         $xmlDuplication->setAttribute('tokens', $duplicate['numTokens']);
         $xmlFile = $xmlDuplication->appendChild($document->createElement('file'));
         $xmlFile->setAttribute('path', $duplicate['fileA']->getPath());
         $xmlFile->setAttribute('line', $duplicate['firstLineA']);
         $xmlFile = $xmlDuplication->appendChild($document->createElement('file'));
         $xmlFile->setAttribute('path', $duplicate['fileB']->getPath());
         $xmlFile->setAttribute('line', $duplicate['firstLineB']);
         $xmlDuplication->appendChild($document->createElement('codefragment', htmlspecialchars(PHPUnit_Util_XML::convertToUtf8(join('', array_slice($duplicate['fileA']->getLines(), $duplicate['firstLineA'] - 1, $duplicate['numLines']))), ENT_COMPAT, 'UTF-8')));
     }
     $this->write($document->saveXML());
     $this->flush();
 }
开发者ID:kytvi2p,项目名称:ZettaFramework,代码行数:29,代码来源:CPD.php


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