Skip to content

Commit

Permalink
Add --logger-html='file.html' CLI option for HTML report
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Jan 7, 2022
1 parent 544efe4 commit e46b4b2
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Command/RunCommand.php
Expand Up @@ -118,6 +118,8 @@ final class RunCommand extends BaseCommand
/** @var string */
private const OPTION_LOGGER_GITHUB = 'logger-github';

private const OPTION_LOGGER_HTML = 'logger-html';

private const OPTION_USE_NOOP_MUTATORS = 'noop';

private const OPTION_EXECUTE_ONLY_COVERING_TEST_CASES = 'only-covering-test-cases';
Expand Down Expand Up @@ -264,6 +266,12 @@ protected function configure(): void
InputOption::VALUE_NONE,
'Log escaped Mutants as GitHub Annotations.',
)
->addOption(
self::OPTION_LOGGER_HTML,
null,
InputOption::VALUE_REQUIRED,
'Path to HTML report file, similar to PHPUnit HTML report.',
)
->addOption(
self::OPTION_USE_NOOP_MUTATORS,
null,
Expand Down Expand Up @@ -388,6 +396,7 @@ private function createContainer(IO $io, LoggerInterface $logger): Container
$testFramework = trim((string) $input->getOption(self::OPTION_TEST_FRAMEWORK));
$testFrameworkExtraOptions = trim((string) $input->getOption(self::OPTION_TEST_FRAMEWORK_OPTIONS));
$initialTestsPhpOptions = trim((string) $input->getOption(self::OPTION_INITIAL_TESTS_PHP_OPTIONS));
$htmlFileLogPath = trim((string) $input->getOption(self::OPTION_LOGGER_HTML));

/** @var string|null $minMsi */
$minMsi = $input->getOption(self::OPTION_MIN_MSI);
Expand Down Expand Up @@ -473,6 +482,7 @@ private function createContainer(IO $io, LoggerInterface $logger): Container
$isForGitDiffLines,
$gitDiffBase,
(bool) $input->getOption(self::OPTION_LOGGER_GITHUB),
$htmlFileLogPath === '' ? Container::DEFAULT_HTML_LOGGER_PATH : $htmlFileLogPath,
(bool) $input->getOption(self::OPTION_USE_NOOP_MUTATORS),
(bool) $input->getOption(self::OPTION_EXECUTE_ONLY_COVERING_TEST_CASES)
);
Expand Down
9 changes: 7 additions & 2 deletions src/Configuration/ConfigurationFactory.php
Expand Up @@ -119,6 +119,7 @@ public function create(
bool $isForGitDiffLines,
?string $gitDiffBase,
bool $useGitHubLogger,
?string $htmlLogFilePath,
bool $useNoopMutators,
bool $executeOnlyCoveringTestCases
): Configuration {
Expand Down Expand Up @@ -150,7 +151,7 @@ public function create(
),
$this->retrieveFilter($filter, $gitDiffFilter, $isForGitDiffLines, $gitDiffBase),
$schema->getSource()->getExcludes(),
$this->retrieveLogs($schema->getLogs(), $useGitHubLogger),
$this->retrieveLogs($schema->getLogs(), $useGitHubLogger, $htmlLogFilePath),
$logVerbosity,
$namespacedTmpDir,
$this->retrievePhpUnit($schema, $configDir),
Expand Down Expand Up @@ -315,12 +316,16 @@ private function retrieveFilter(string $filter, ?string $gitDiffFilter, bool $is
return $this->gitDiffFileProvider->provide($gitDiffFilter, $baseBranch);
}

private function retrieveLogs(Logs $logs, bool $useGitHubLogger): Logs
private function retrieveLogs(Logs $logs, bool $useGitHubLogger, ?string $htmlLogFilePath): Logs
{
if ($useGitHubLogger) {
$logs->setUseGitHubAnnotationsLogger($useGitHubLogger);
}

if ($htmlLogFilePath !== null) {
$logs->setHtmlLogFilePath($htmlLogFilePath);
}

return $logs;
}
}
5 changes: 5 additions & 0 deletions src/Configuration/Entry/Logs.php
Expand Up @@ -94,6 +94,11 @@ public function getHtmlLogFilePath(): ?string
return $this->htmlLogFilePath;
}

public function setHtmlLogFilePath(string $htmlLogFilePath): void
{
$this->htmlLogFilePath = $htmlLogFilePath;
}

public function getSummaryLogFilePath(): ?string
{
return $this->summaryLogFilePath;
Expand Down
5 changes: 5 additions & 0 deletions src/Container.php
Expand Up @@ -170,6 +170,7 @@ final class Container
public const DEFAULT_GIT_DIFF_LINES = false;
public const DEFAULT_GIT_DIFF_BASE = null;
public const DEFAULT_USE_GITHUB_LOGGER = false;
public const DEFAULT_HTML_LOGGER_PATH = null;
public const DEFAULT_USE_NOOP_MUTATORS = false;
public const DEFAULT_EXECUTE_ONLY_COVERING_TEST_CASES = false;
public const DEFAULT_NO_PROGRESS = false;
Expand Down Expand Up @@ -710,6 +711,7 @@ public static function create(): self
self::DEFAULT_GIT_DIFF_LINES,
self::DEFAULT_GIT_DIFF_BASE,
self::DEFAULT_USE_GITHUB_LOGGER,
self::DEFAULT_HTML_LOGGER_PATH,
self::DEFAULT_USE_NOOP_MUTATORS,
self::DEFAULT_EXECUTE_ONLY_COVERING_TEST_CASES
);
Expand Down Expand Up @@ -743,6 +745,7 @@ public function withValues(
bool $isForGitDiffLines,
?string $gitDiffBase,
bool $useGitHubLogger,
?string $htmlLogFilePath,
bool $useNoopMutators,
bool $executeOnlyCoveringTestCases
): self {
Expand Down Expand Up @@ -820,6 +823,7 @@ static function (self $container) use (
$isForGitDiffLines,
$gitDiffBase,
$useGitHubLogger,
$htmlLogFilePath,
$useNoopMutators,
$executeOnlyCoveringTestCases
): Configuration {
Expand Down Expand Up @@ -847,6 +851,7 @@ static function (self $container) use (
$isForGitDiffLines,
$gitDiffBase,
$useGitHubLogger,
$htmlLogFilePath,
$useNoopMutators,
$executeOnlyCoveringTestCases
);
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/Tracing/provide-traces-closure.php
Expand Up @@ -71,6 +71,7 @@
Container::DEFAULT_GIT_DIFF_LINES,
Container::DEFAULT_GIT_DIFF_BASE,
Container::DEFAULT_USE_GITHUB_LOGGER,
Container::DEFAULT_HTML_LOGGER_PATH,
true,
Container::DEFAULT_EXECUTE_ONLY_COVERING_TEST_CASES
);
Expand Down

0 comments on commit e46b4b2

Please sign in to comment.