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 Dec 26, 2021
1 parent 59f25bc commit 57f6716
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 @@ -115,6 +115,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 @@ -254,6 +256,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 @@ -378,6 +386,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 @@ -457,6 +466,7 @@ private function createContainer(IO $io, LoggerInterface $logger): Container
$gitDiffFilter,
$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 @@ -118,6 +118,7 @@ public function create(
?string $gitDiffFilter,
?string $gitDiffBase,
bool $useGitHubLogger,
?string $htmlLogFilePath,
bool $useNoopMutators,
bool $executeOnlyCoveringTestCases
): Configuration {
Expand Down Expand Up @@ -149,7 +150,7 @@ public function create(
),
$this->retrieveFilter($filter, $gitDiffFilter, $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 @@ -306,12 +307,16 @@ private function retrieveFilter(string $filter, ?string $gitDiffFilter, ?string
return $this->gitDiffFileProvider->provide($gitDiffFilter, $gitDiffBase ?? GitDiffFileProvider::DEFAULT_BASE);
}

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 @@ -167,6 +167,7 @@ final class Container
public const DEFAULT_GIT_DIFF_FILTER = null;
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 @@ -695,6 +696,7 @@ public static function create(): self
self::DEFAULT_GIT_DIFF_FILTER,
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 @@ -727,6 +729,7 @@ public function withValues(
?string $gitDiffFilter,
?string $gitDiffBase,
bool $useGitHubLogger,
?string $htmlLogFilePath,
bool $useNoopMutators,
bool $executeOnlyCoveringTestCases
): self {
Expand Down Expand Up @@ -803,6 +806,7 @@ static function (self $container) use (
$gitDiffFilter,
$gitDiffBase,
$useGitHubLogger,
$htmlLogFilePath,
$useNoopMutators,
$executeOnlyCoveringTestCases
): Configuration {
Expand All @@ -829,6 +833,7 @@ static function (self $container) use (
$gitDiffFilter,
$gitDiffBase,
$useGitHubLogger,
$htmlLogFilePath,
$useNoopMutators,
$executeOnlyCoveringTestCases
);
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/Tracing/provide-traces-closure.php
Expand Up @@ -70,6 +70,7 @@
Container::DEFAULT_GIT_DIFF_FILTER,
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 57f6716

Please sign in to comment.