Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Report/Clover.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Generates a Clover XML logfile from a code coverage object.
*/
final class Clover
final class Clover extends Reporter
{
/**
* @throws \RuntimeException
Expand Down
3 changes: 2 additions & 1 deletion src/Report/Crap4j.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Node\File;
use SebastianBergmann\CodeCoverage\RuntimeException;
use SebastianBergmann\CodeCoverage\Report\Reporter;

final class Crap4j
final class Crap4j extends Reporter
{
/**
* @var int
Expand Down
13 changes: 2 additions & 11 deletions src/Report/Html/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
use SebastianBergmann\CodeCoverage\Report\Reporter;
use SebastianBergmann\CodeCoverage\RuntimeException;

/**
* Generates an HTML report from a code coverage object.
*/
final class Facade
final class Facade extends Reporter
{
/**
* @var string
Expand All @@ -38,11 +39,6 @@ final class Facade
*/
private $highLowerBound;

/**
* @var bool
*/
private $determineBranchCoverage = false;

public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, string $generator = '')
{
$this->generator = $generator;
Expand Down Expand Up @@ -121,11 +117,6 @@ public function process(CodeCoverage $coverage, string $target): void
$this->copyFiles($target);
}

public function setDetermineBranchCoverage(bool $determineBranchCoverage): void
{
$this->determineBranchCoverage = $determineBranchCoverage;
}

/**
* @throws RuntimeException
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Report/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\RuntimeException;
use SebastianBergmann\CodeCoverage\Report\Reporter;

/**
* Uses var_export() to write a SebastianBergmann\CodeCoverage\CodeCoverage object to a file.
*/
final class PHP
final class PHP extends Reporter
{
/**
* @throws \SebastianBergmann\CodeCoverage\RuntimeException
Expand Down
23 changes: 23 additions & 0 deletions src/Report/Reporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);
/*
* This file is part of the php-code-coverage package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Report;

abstract class Reporter
{
/**
* @var bool
*/
protected $determineBranchCoverage = false;

public function setDetermineBranchCoverage(bool $determineBranchCoverage): void
{
$this->determineBranchCoverage = $determineBranchCoverage;
}
}
13 changes: 2 additions & 11 deletions src/Report/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Node\File;
use SebastianBergmann\CodeCoverage\Util;
use SebastianBergmann\CodeCoverage\Report\Reporter;

/**
* Generates human readable output from a code coverage object.
*
* The output gets put into a text file our written to the CLI.
*/
final class Text
final class Text extends Reporter
{
/**
* @var string
Expand Down Expand Up @@ -70,11 +71,6 @@ final class Text
*/
private $showOnlySummary;

/**
* @var bool
*/
private $determineBranchCoverage = false;

public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, bool $showUncoveredFiles = false, bool $showOnlySummary = false)
{
$this->lowUpperBound = $lowUpperBound;
Expand Down Expand Up @@ -350,11 +346,6 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
return $output . \PHP_EOL;
}

public function setDetermineBranchCoverage(bool $determineBranchCoverage): void
{
$this->determineBranchCoverage = $determineBranchCoverage;
}

private function getCoverageColor(int $numberOfCoveredElements, int $totalNumberOfElements): string
{
$coverage = Util::percent(
Expand Down
53 changes: 50 additions & 3 deletions src/Report/Xml/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
use SebastianBergmann\CodeCoverage\Node\AbstractNode;
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
use SebastianBergmann\CodeCoverage\Node\File as FileNode;
use SebastianBergmann\CodeCoverage\Report\Reporter;
use SebastianBergmann\CodeCoverage\RuntimeException;
use SebastianBergmann\CodeCoverage\Version;
use SebastianBergmann\Environment\Runtime;

final class Facade
final class Facade extends Reporter
{
/**
* @var string
Expand Down Expand Up @@ -56,6 +57,7 @@ public function process(CodeCoverage $coverage, string $target): void
$this->project = new Project(
$coverage->getReport()->getName()
);
$this->project->setDetermineBranchCoverage($this->determineBranchCoverage);

$this->setBuildInformation();
$this->processTests($coverage->getTests());
Expand Down Expand Up @@ -135,6 +137,7 @@ private function processFile(FileNode $file, Directory $context): void
);

$fileReport = new Report($path);
$fileReport->setDetermineBranchCoverage($this->determineBranchCoverage);

$this->setTotals($file, $fileReport->getTotals());

Expand All @@ -146,7 +149,13 @@ private function processFile(FileNode $file, Directory $context): void
$this->processFunction($function, $fileReport);
}

foreach ($file->getCoverageData() as $line => $tests) {
$fileCoverageData = $file->getCoverageData();
foreach ($fileCoverageData['lines'] as $line => $lineData) {
if ($lineData === null) {
continue;
}

$tests = $lineData['tests'];
if (!\is_array($tests) || \count($tests) === 0) {
continue;
}
Expand Down Expand Up @@ -202,6 +211,17 @@ private function processUnit(array $unit, Report $report): void
(string) $method['executedLines'],
(string) $method['coverage']
);

if ($this->determineBranchCoverage) {
$methodObject->setPathTotals(
(string) $method['executablePaths'],
(string) $method['executedPaths']
);
$methodObject->setBranchTotals(
(string) $method['executableBranches'],
(string) $method['executedBranches']
);
}
}
}

Expand All @@ -212,7 +232,22 @@ private function processFunction(array $function, Report $report): void
$functionObject->setSignature($function['signature']);
$functionObject->setLines((string) $function['startLine']);
$functionObject->setCrap($function['crap']);
$functionObject->setTotals((string) $function['executableLines'], (string) $function['executedLines'], (string) $function['coverage']);
$functionObject->setTotals(
(string) $function['executableLines'],
(string) $function['executedLines'],
(string) $function['coverage']
);

if ($this->determineBranchCoverage) {
$functionObject->setPathTotals(
(string) $function['executablePaths'],
(string) $function['executedPaths']
);
$functionObject->setBranchTotals(
(string) $function['executableBranches'],
(string) $function['executedBranches']
);
}
}

private function processTests(array $tests): void
Expand Down Expand Up @@ -259,6 +294,18 @@ private function setTotals(AbstractNode $node, Totals $totals): void
$node->getNumFunctions(),
$node->getNumTestedFunctions()
);

if ($this->determineBranchCoverage) {
$totals->setNumPaths(
$node->getNumPaths(),
$node->getNumTestedPaths()
);

$totals->setNumBranches(
$node->getNumBranches(),
$node->getNumTestedBranches()
);
}
}

private function getTargetDirectory(): string
Expand Down
12 changes: 11 additions & 1 deletion src/Report/Xml/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class File
*/
private $contextNode;

/**
* @var bool
*/
private $determineBranchCoverage = false;

public function __construct(\DOMElement $context)
{
$this->dom = $context->ownerDocument;
Expand All @@ -40,7 +45,7 @@ public function getTotals(): Totals
);
}

return new Totals($totalsContainer);
return new Totals($totalsContainer, $this->determineBranchCoverage);
}

public function getLineCoverage(string $line): Coverage
Expand Down Expand Up @@ -69,6 +74,11 @@ public function getLineCoverage(string $line): Coverage
return new Coverage($lineNode, $line);
}

public function setDetermineBranchCoverage(bool $determineBranchCoverage): void
{
$this->determineBranchCoverage = $determineBranchCoverage;
}

protected function getContextNode(): \DOMElement
{
return $this->contextNode;
Expand Down
23 changes: 19 additions & 4 deletions src/Report/Xml/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,28 @@ public function setLines(string $start, ?string $end = null): void
}
}

public function setTotals(string $executable, string $executed, string $coverage): void
{
$this->contextNode->setAttribute('executable', $executable);
$this->contextNode->setAttribute('executed', $executed);
public function setTotals(
string $executableLines,
string $executedLines,
string $coverage
): void {
$this->contextNode->setAttribute('executable', $executableLines);
$this->contextNode->setAttribute('executed', $executedLines);
$this->contextNode->setAttribute('coverage', $coverage);
}

public function setPathTotals(string $executablePaths, string $executedPaths): void
{
$this->contextNode->setAttribute('executablePaths', $executablePaths);
$this->contextNode->setAttribute('executedPaths', $executedPaths);
}

public function setBranchTotals(string $executableBranches, string $executedBranches): void
{
$this->contextNode->setAttribute('executableBranches', $executableBranches);
$this->contextNode->setAttribute('executedBranches', $executedBranches);
}

public function setCrap(string $crap): void
{
$this->contextNode->setAttribute('crap', $crap);
Expand Down
22 changes: 19 additions & 3 deletions src/Report/Xml/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ abstract class Node
*/
private $contextNode;

/**
* @var bool
*/
protected $determineBranchCoverage = false;

public function __construct(\DOMElement $context)
{
$this->setContextNode($context);
Expand All @@ -44,7 +49,7 @@ public function getTotals(): Totals
);
}

return new Totals($totalsContainer);
return new Totals($totalsContainer, $this->determineBranchCoverage);
}

public function addDirectory(string $name): Directory
Expand All @@ -57,7 +62,10 @@ public function addDirectory(string $name): Directory
$dirNode->setAttribute('name', $name);
$this->getContextNode()->appendChild($dirNode);

return new Directory($dirNode);
$directory = new Directory($dirNode);
$directory->setDetermineBranchCoverage($this->determineBranchCoverage);

return $directory;
}

public function addFile(string $name, string $href): File
Expand All @@ -71,7 +79,15 @@ public function addFile(string $name, string $href): File
$fileNode->setAttribute('href', $href);
$this->getContextNode()->appendChild($fileNode);

return new File($fileNode);
$file = new File($fileNode);
$file->setDetermineBranchCoverage($this->determineBranchCoverage);

return $file;
}

public function setDetermineBranchCoverage(bool $determineBranchCoverage): void
{
$this->determineBranchCoverage = $determineBranchCoverage;
}

protected function setContextNode(\DOMElement $context): void
Expand Down
Loading