コード例 #1
0
 /**
  * Collect coverage from XML object.
  *
  * @param SimpleXMLElement $xml     Clover XML object.
  * @param string           $rootDir Path to src directory.
  *
  * @return \Satooshi\Bundle\CoverallsV1Bundle\Entity\JsonFile
  */
 public function collect(\SimpleXMLElement $xml, $rootDir)
 {
     $root = rtrim($rootDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     if (!isset($this->jsonFile)) {
         $this->jsonFile = new JsonFile();
     }
     // overwrite if run_at has already been set
     $runAt = $this->collectRunAt($xml);
     $this->jsonFile->setRunAt($runAt);
     $xpaths = array('/coverage/project/file', '/coverage/project/package/file');
     foreach ($xpaths as $xpath) {
         foreach ($xml->xpath($xpath) as $file) {
             $srcFile = $this->collectFileCoverage($file, $root);
             if ($srcFile !== null) {
                 $this->jsonFile->addSourceFile($srcFile);
             }
         }
     }
     return $this->jsonFile;
 }
コード例 #2
0
 protected function createJsonFile()
 {
     $jsonFile = new JsonFile();
     $repositoryTestDir = $this->srcDir . '/RepositoryTest';
     $sourceFiles = array(0 => new SourceFile($repositoryTestDir . '/Coverage0.php', 'Coverage0.php'), 10 => new SourceFile($repositoryTestDir . '/Coverage10.php', 'Coverage10.php'), 70 => new SourceFile($repositoryTestDir . '/Coverage70.php', 'Coverage70.php'), 80 => new SourceFile($repositoryTestDir . '/Coverage80.php', 'Coverage80.php'), 90 => new SourceFile($repositoryTestDir . '/Coverage90.php', 'Coverage90.php'), 100 => new SourceFile($repositoryTestDir . '/Coverage100.php', 'Coverage100.php'));
     foreach ($sourceFiles as $percent => $sourceFile) {
         $sourceFile->getMetrics()->merge(new Metrics($this->createCoverage($percent)));
         $jsonFile->addSourceFile($sourceFile);
     }
     return $jsonFile;
 }