Ejemplo n.º 1
0
 /**
  * Collect environment variables.
  *
  * @param array $env $_SERVER environment.
  *
  * @return \Satooshi\Bundle\CoverallsV1Bundle\Api\Jobs
  *
  * @throws \Satooshi\Bundle\CoverallsV1Bundle\Entity\Exception\RequirementsNotSatisfiedException
  */
 public function collectEnvVars(array $env)
 {
     $envCollector = new CiEnvVarsCollector($this->config);
     try {
         $this->jsonFile->fillJobs($envCollector->collect($env));
     } catch (\Satooshi\Bundle\CoverallsV1Bundle\Entity\Exception\RequirementsNotSatisfiedException $e) {
         $e->setReadEnv($envCollector->getReadEnv());
         throw $e;
     }
     return $this;
 }
 /**
  * Collect coverage data.
  *
  * @param SimpleXMLElement $file     Clover XML object of a file.
  * @param string           $path     Path to source file.
  * @param string           $filename Filename.
  *
  * @return \Satooshi\Bundle\CoverallsV1Bundle\Entity\SourceFile
  */
 protected function collectCoverage(\SimpleXMLElement $file, $path, $filename)
 {
     if ($this->jsonFile->hasSourceFile($path)) {
         $srcFile = $this->jsonFile->getSourceFile($path);
     } else {
         $srcFile = new SourceFile($path, $filename);
     }
     foreach ($file->line as $line) {
         if ((string) $line['type'] === 'stmt') {
             $lineNum = (int) $line['num'];
             if ($lineNum > 0) {
                 $srcFile->addCoverage($lineNum - 1, (int) $line['count']);
             }
         }
     }
     return $srcFile;
 }
 /**
  * @test
  * @depends shouldCollectSourceFilesUnderRootDir
  */
 public function shouldCollectSourceFileTest2UnderRootDir(JsonFile $jsonFile)
 {
     $sourceFiles = $jsonFile->getSourceFiles();
     $name2 = 'test2.php';
     $path2 = $this->srcDir . DIRECTORY_SEPARATOR . $name2;
     $this->assertArrayHasKey($path2, $sourceFiles);
     $this->assertSourceFileTest2UnderRootDir($sourceFiles[$path2]);
 }
Ejemplo n.º 4
0
protected function logCollectedSourceFiles(JsonFile $jsonFile)
{
$sourceFiles = $jsonFile->getSourceFiles();
$numFiles = count($sourceFiles);

$this->logger->info(sprintf('Found <info>%s</info> source file%s:', number_format($numFiles), $numFiles > 1 ? 's' : ''));

foreach ($sourceFiles as $sourceFile) {

$coverage = $sourceFile->reportLineCoverage();
$template = '  - ' . $this->colorizeCoverage($coverage, '%6.2f%%') . ' %s';

$this->logger->info(sprintf($template, $coverage, $sourceFile->getName()));
}

$coverage = $jsonFile->reportLineCoverage();
$template = 'Coverage: ' . $this->colorizeCoverage($coverage, '%6.2f%% (%d/%d)');
$metrics = $jsonFile->getMetrics();

$this->logger->info(sprintf($template, $coverage, $metrics->getCoveredStatements(), $metrics->getStatements()));
}
Ejemplo n.º 5
0
 /**
  * @test
  * @depends shouldHaveJsonFileAfterCollectGitInfo
  */
 public function shouldHaveGitAfterCollectGitInfo(JsonFile $jsonFile)
 {
     $git = $jsonFile->getGit();
     $this->assertNotNull($git);
 }
 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;
 }
Ejemplo n.º 7
0
 public function getRunAt()
 {
     return strtotime(parent::getRunAt());
 }