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


PHP PHPUnit_Util_CodeCoverage::getCoveringTests方法代码示例

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


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

示例1: storeCodeCoverage

 /**
  * Stores code coverage information.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  integer                      $revision
  * @access public
  */
 public function storeCodeCoverage(PHPUnit_Framework_TestResult $result, $revision)
 {
     $codeCoverage = $result->getCodeCoverageInformation(FALSE, TRUE);
     $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage);
     $files = array_keys($summary);
     $commonPath = PHPUnit_Util_Filesystem::getCommonPath($files);
     $this->dbh->beginTransaction();
     foreach ($files as $file) {
         $filename = str_replace($commonPath, '', $file);
         $fileId = FALSE;
         $lines = file($file);
         $numLines = count($lines);
         $stmt = $this->dbh->query(sprintf('SELECT code_file_id
                FROM code_file
               WHERE code_file_name = "%s"
                 AND revision       = %d;', $filename, $revision));
         if ($stmt) {
             $fileId = (int) $stmt->fetchColumn();
         }
         unset($stmt);
         if ($fileId == 0) {
             $this->dbh->exec(sprintf('INSERT INTO code_file
                              (code_file_name, code_file_md5, revision)
                        VALUES("%s", "%s", %d);', $filename, md5_file($file), $revision));
             $fileId = $this->dbh->lastInsertId();
             $classes = PHPUnit_Util_Class::getClassesInFile($file, $commonPath);
             foreach ($classes as $class) {
                 $this->dbh->exec(sprintf('INSERT INTO code_class
                                  (code_file_id, code_class_name,
                                   code_class_start_line, code_class_end_line)
                            VALUES(%d, "%s", %d, %d);', $fileId, $class->getName(), $class->getStartLine(), $class->getEndLine()));
                 $classId = $this->dbh->lastInsertId();
                 foreach ($class->getMethods() as $method) {
                     if ($class->getName() != $method->getDeclaringClass()->getName()) {
                         continue;
                     }
                     $this->dbh->exec(sprintf('INSERT INTO code_method
                                      (code_class_id, code_method_name,
                                       code_method_start_line, code_method_end_line)
                                VALUES(%d, "%s", %d, %d);', $classId, $method->getName(), $method->getStartLine(), $method->getEndLine()));
                 }
             }
             $i = 1;
             foreach ($lines as $line) {
                 $this->dbh->exec(sprintf('INSERT INTO code_line
                                  (code_file_id, code_line_number, code_line,
                                   code_line_covered)
                            VALUES(%d, %d, "%s", %d);', $fileId, $i, trim($line), isset($summary[$file][$i]) ? $summary[$file][$i] : 0));
                 $i++;
             }
         }
         for ($lineNumber = 1; $lineNumber <= $numLines; $lineNumber++) {
             $coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests($codeCoverage, $file, $lineNumber);
             if (is_array($coveringTests)) {
                 $stmt = $this->dbh->query(sprintf('SELECT code_line_id, code_line_covered
                        FROM code_line
                       WHERE code_file_id     = %d
                         AND code_line_number = %d;', $fileId, $lineNumber));
                 $codeLineId = (int) $stmt->fetchColumn(0);
                 $oldCoverageFlag = (int) $stmt->fetchColumn(1);
                 unset($stmt);
                 $newCoverageFlag = $summary[$file][$lineNumber];
                 if ($oldCoverageFlag == 0 && $newCoverageFlag != 0 || $oldCoverageFlag < 0 && $newCoverageFlag > 0) {
                     $this->dbh->exec(sprintf('UPDATE code_line
                             SET code_line_covered = %d
                           WHERE code_line_id      = %d;', $newCoverageFlag, $codeLineId));
                 }
                 foreach ($coveringTests as $test) {
                     $this->dbh->exec(sprintf('INSERT INTO code_coverage
                                      (test_id, code_line_id)
                                VALUES(%d, %d);', $test->__db_id, $codeLineId));
                 }
             }
         }
     }
     foreach ($result->topTestSuite() as $test) {
         if ($test instanceof PHPUnit_Framework_TestCase) {
             $stmt = $this->dbh->query(sprintf('SELECT code_method.code_method_id
                    FROM code_class, code_method
                   WHERE code_class.code_class_id     = code_method.code_class_id
                     AND code_class.code_class_name   = "%s"
                     AND code_method.code_method_name = "%s";', get_class($test), $test->getName()));
             $methodId = (int) $stmt->fetchColumn();
             unset($stmt);
             $this->dbh->exec(sprintf('UPDATE test
                     SET code_method_id = %d
                   WHERE test_id = %d;', $methodId, $test->__db_id));
         }
     }
     $this->dbh->commit();
 }
开发者ID:dalinhuang,项目名称:shopexts,代码行数:98,代码来源:Database.php

示例2: storeCodeCoverage


//.........这里部分代码省略.........
                 $methodLocExecuted = $methodMetrics->getLocExecuted();
                 $methodCcn = $methodMetrics->getCCN();
                 $methodCrap = $methodMetrics->getCrapIndex();
                 $methodNpath = $methodMetrics->getNPath();
                 $stmtInsertMethod->bindParam(':runId', $runId, PDO::PARAM_INT);
                 $stmtInsertMethod->bindParam(':methodId', $methodId, PDO::PARAM_INT);
                 $stmtInsertMethod->bindParam(':coverage', $methodCoverage);
                 $stmtInsertMethod->bindParam(':loc', $methodLoc, PDO::PARAM_INT);
                 $stmtInsertMethod->bindParam(':locExecutable', $methodLocExecutable, PDO::PARAM_INT);
                 $stmtInsertMethod->bindParam(':locExecuted', $methodLocExecuted, PDO::PARAM_INT);
                 $stmtInsertMethod->bindParam(':ccn', $methodCcn, PDO::PARAM_INT);
                 $stmtInsertMethod->bindParam(':crap', $methodCrap);
                 $stmtInsertMethod->bindParam(':npath', $methodNpath, PDO::PARAM_INT);
                 $stmtInsertMethod->execute();
             }
         }
         unset($stmtSelectFunctionId);
         unset($stmtInsertFunction);
         unset($stmtSelectClassId);
         unset($stmtInsertClass);
         unset($stmtSelectMethodId);
         unset($stmtInsertMethod);
         $stmt = $this->dbh->prepare('SELECT code_line_id, code_line_covered
              FROM code_line
             WHERE code_file_id     = :fileId
               AND code_line_number = :lineNumber;');
         $stmt2 = $this->dbh->prepare('UPDATE code_line
               SET code_line_covered = :lineCovered
             WHERE code_line_id      = :lineId;');
         $stmt3 = $this->dbh->prepare('INSERT INTO code_coverage
                   (test_id, code_line_id)
             VALUES(:testId, :lineId);');
         for ($lineNumber = 1; $lineNumber <= $fileLoc; $lineNumber++) {
             $coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests($codeCoverage, $fileName, $lineNumber);
             if (is_array($coveringTests)) {
                 $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT);
                 $stmt->bindParam(':lineNumber', $lineNumber, PDO::PARAM_INT);
                 $stmt->execute();
                 $codeLineId = (int) $stmt->fetchColumn(0);
                 $oldCoverageFlag = (int) $stmt->fetchColumn(1);
                 $newCoverageFlag = isset($summary[$fileName][$lineNumber]) ? 1 : 0;
                 if ($oldCoverageFlag == 0 && $newCoverageFlag != 0 || $oldCoverageFlag < 0 && $newCoverageFlag > 0) {
                     $stmt2->bindParam(':lineCovered', $newCoverageFlag, PDO::PARAM_INT);
                     $stmt2->bindParam(':lineId', $codeLineId, PDO::PARAM_INT);
                     $stmt2->execute();
                 }
                 foreach ($coveringTests as $test) {
                     $stmt3->bindParam(':testId', $test->__db_id, PDO::PARAM_INT);
                     $stmt3->bindParam(':lineId', $codeLineId, PDO::PARAM_INT);
                     $stmt3->execute();
                 }
             }
         }
     }
     unset($stmt);
     unset($stmt2);
     unset($stmt3);
     $stmt = $this->dbh->prepare('SELECT code_method.code_method_id
          FROM code_class, code_method
         WHERE code_class.code_class_id     = code_method.code_class_id
           AND code_class.code_class_name   = :className
           AND code_method.code_method_name = :methodName;');
     $stmt2 = $this->dbh->prepare('UPDATE test
           SET code_method_id = :methodId
         WHERE test_id = :testId;');
     foreach ($result->topTestSuite() as $test) {
开发者ID:nblackman,项目名称:pimcore,代码行数:67,代码来源:Database.php


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