Skip to content

Commit

Permalink
Add cli --logger-gitlab options.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmlara committed Sep 28, 2023
1 parent 4e9ea31 commit 2fc798d
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 4 deletions.
2 changes: 1 addition & 1 deletion resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"gitlab": {
"type": "string",
"definition": "GitLab(Code Climate) code quality json file."
"definition": "GitLab (Code Climate) code quality json file."
},
"summaryJson": {
"type": "string",
Expand Down
11 changes: 11 additions & 0 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ final class RunCommand extends BaseCommand
/** @var string */
private const OPTION_LOGGER_GITHUB = 'logger-github';

/** @var string */
private const OPTION_LOGGER_GITLAB = 'logger-gitlab';

private const OPTION_LOGGER_HTML = 'logger-html';

private const OPTION_USE_NOOP_MUTATORS = 'noop';
Expand Down Expand Up @@ -274,6 +277,12 @@ protected function configure(): void
'Log escaped Mutants as GitHub Annotations (automatically detected on Github Actions itself, use <comment>true</comment> to force-enable or <comment>false</comment> to force-disable it).',
false
)
->addOption(
self::OPTION_LOGGER_GITLAB,
null,
InputOption::VALUE_OPTIONAL,
'Path to log escaped Mutants in the GitLab (Code Climate) JSON format.',
)
->addOption(
self::OPTION_LOGGER_HTML,
null,
Expand Down Expand Up @@ -404,6 +413,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));
$gitlabFileLogPath = trim((string) $input->getOption(self::OPTION_LOGGER_GITLAB));

Check warning on line 416 in src/Command/RunCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ $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)); - $gitlabFileLogPath = trim((string) $input->getOption(self::OPTION_LOGGER_GITLAB)); + $gitlabFileLogPath = (string) $input->getOption(self::OPTION_LOGGER_GITLAB); $htmlFileLogPath = trim((string) $input->getOption(self::OPTION_LOGGER_HTML)); /** @var string|null $minMsi */ $minMsi = $input->getOption(self::OPTION_MIN_MSI);

Check warning on line 416 in src/Command/RunCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ $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)); - $gitlabFileLogPath = trim((string) $input->getOption(self::OPTION_LOGGER_GITLAB)); + $gitlabFileLogPath = (string) $input->getOption(self::OPTION_LOGGER_GITLAB); $htmlFileLogPath = trim((string) $input->getOption(self::OPTION_LOGGER_HTML)); /** @var string|null $minMsi */ $minMsi = $input->getOption(self::OPTION_MIN_MSI);
$htmlFileLogPath = trim((string) $input->getOption(self::OPTION_LOGGER_HTML));

/** @var string|null $minMsi */
Expand Down Expand Up @@ -489,6 +499,7 @@ private function createContainer(IO $io, LoggerInterface $logger): Container
$isForGitDiffLines,
$gitDiffBase,
$this->getUseGitHubLogger($input),
$gitlabFileLogPath === '' ? Container::DEFAULT_GITLAB_LOGGER_PATH : $gitlabFileLogPath,

Check warning on line 502 in src/Command/RunCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "Identical": --- Original +++ New @@ @@ $isForGitDiffLines, $gitDiffBase, $this->getUseGitHubLogger($input), - $gitlabFileLogPath === '' ? Container::DEFAULT_GITLAB_LOGGER_PATH : $gitlabFileLogPath, + $gitlabFileLogPath !== '' ? Container::DEFAULT_GITLAB_LOGGER_PATH : $gitlabFileLogPath, $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)

Check warning on line 502 in src/Command/RunCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ $isForGitDiffLines, $gitDiffBase, $this->getUseGitHubLogger($input), - $gitlabFileLogPath === '' ? Container::DEFAULT_GITLAB_LOGGER_PATH : $gitlabFileLogPath, + $gitlabFileLogPath === '' ? $gitlabFileLogPath : Container::DEFAULT_GITLAB_LOGGER_PATH, $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)

Check warning on line 502 in src/Command/RunCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "Identical": --- Original +++ New @@ @@ $isForGitDiffLines, $gitDiffBase, $this->getUseGitHubLogger($input), - $gitlabFileLogPath === '' ? Container::DEFAULT_GITLAB_LOGGER_PATH : $gitlabFileLogPath, + $gitlabFileLogPath !== '' ? Container::DEFAULT_GITLAB_LOGGER_PATH : $gitlabFileLogPath, $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)

Check warning on line 502 in src/Command/RunCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ $isForGitDiffLines, $gitDiffBase, $this->getUseGitHubLogger($input), - $gitlabFileLogPath === '' ? Container::DEFAULT_GITLAB_LOGGER_PATH : $gitlabFileLogPath, + $gitlabFileLogPath === '' ? $gitlabFileLogPath : Container::DEFAULT_GITLAB_LOGGER_PATH, $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)
$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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function create(
bool $isForGitDiffLines,
?string $gitDiffBase,
?bool $useGitHubLogger,
?string $gitlabLogFilePath,
?string $htmlLogFilePath,
bool $useNoopMutators,
bool $executeOnlyCoveringTestCases
Expand Down Expand Up @@ -140,7 +141,7 @@ public function create(
),
$this->retrieveFilter($filter, $gitDiffFilter, $isForGitDiffLines, $gitDiffBase, $schema->getSource()->getDirectories()),
$schema->getSource()->getExcludes(),
$this->retrieveLogs($schema->getLogs(), $configDir, $useGitHubLogger, $htmlLogFilePath),
$this->retrieveLogs($schema->getLogs(), $configDir, $useGitHubLogger, $gitlabLogFilePath, $htmlLogFilePath),
$logVerbosity,
$namespacedTmpDir,
$this->retrievePhpUnit($schema, $configDir),
Expand Down Expand Up @@ -308,7 +309,7 @@ private function retrieveFilter(string $filter, ?string $gitDiffFilter, bool $is
return $this->gitDiffFileProvider->provide($gitDiffFilter, $baseBranch, $sourceDirectories);
}

private function retrieveLogs(Logs $logs, string $configDir, ?bool $useGitHubLogger, ?string $htmlLogFilePath): Logs
private function retrieveLogs(Logs $logs, string $configDir, ?bool $useGitHubLogger, ?string $gitlabLogFilePath, ?string $htmlLogFilePath): Logs
{
if ($useGitHubLogger === null) {
$useGitHubLogger = $this->detectCiGithubActions();
Expand All @@ -318,6 +319,10 @@ private function retrieveLogs(Logs $logs, string $configDir, ?bool $useGitHubLog
$logs->setUseGitHubAnnotationsLogger($useGitHubLogger);
}

if ($gitlabLogFilePath !== null) {
$logs->setGitlabLogFilePath($gitlabLogFilePath);
}

if ($htmlLogFilePath !== null) {
$logs->setHtmlLogFilePath($htmlLogFilePath);
}
Expand Down
7 changes: 6 additions & 1 deletion src/Configuration/Entry/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
private ?string $htmlLogFilePath,
private readonly ?string $summaryLogFilePath,
private readonly ?string $jsonLogFilePath,
private readonly ?string $gitlabLogFilePath,
private ?string $gitlabLogFilePath,
private readonly ?string $debugLogFilePath,
private readonly ?string $perMutatorFilePath,
private bool $useGitHubAnnotationsLogger,
Expand Down Expand Up @@ -81,6 +81,11 @@ public function getHtmlLogFilePath(): ?string
return $this->htmlLogFilePath;
}

public function setGitlabLogFilePath(string $gitlabLogFilePath): void
{
$this->gitlabLogFilePath = $gitlabLogFilePath;
}

public function setHtmlLogFilePath(string $htmlLogFilePath): void
{
$this->htmlLogFilePath = $htmlLogFilePath;
Expand Down
4 changes: 4 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ final class Container
public const DEFAULT_GIT_DIFF_LINES = false;
public const DEFAULT_GIT_DIFF_BASE = null;
public const DEFAULT_USE_GITHUB_LOGGER = null;
public const DEFAULT_GITLAB_LOGGER_PATH = null;
public const DEFAULT_HTML_LOGGER_PATH = null;
public const DEFAULT_USE_NOOP_MUTATORS = false;
public const DEFAULT_EXECUTE_ONLY_COVERING_TEST_CASES = false;
Expand Down Expand Up @@ -588,6 +589,7 @@ public static function create(): self
self::DEFAULT_GIT_DIFF_LINES,
self::DEFAULT_GIT_DIFF_BASE,
self::DEFAULT_USE_GITHUB_LOGGER,
self::DEFAULT_GITLAB_LOGGER_PATH,
self::DEFAULT_HTML_LOGGER_PATH,
self::DEFAULT_USE_NOOP_MUTATORS,
self::DEFAULT_EXECUTE_ONLY_COVERING_TEST_CASES
Expand Down Expand Up @@ -622,6 +624,7 @@ public function withValues(
bool $isForGitDiffLines,
?string $gitDiffBase,
?bool $useGitHubLogger,
?string $gitlabLogFilePath,
?string $htmlLogFilePath,
bool $useNoopMutators,
bool $executeOnlyCoveringTestCases
Expand Down Expand Up @@ -690,6 +693,7 @@ public function withValues(
$isForGitDiffLines,
$gitDiffBase,
$useGitHubLogger,
$gitlabLogFilePath,
$htmlLogFilePath,
$useNoopMutators,
$executeOnlyCoveringTestCases
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/Tracing/provide-traces-closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
Container::DEFAULT_GIT_DIFF_LINES,
Container::DEFAULT_GIT_DIFF_BASE,
Container::DEFAULT_USE_GITHUB_LOGGER,
Container::DEFAULT_GITLAB_LOGGER_PATH,
Container::DEFAULT_HTML_LOGGER_PATH,
true,
Container::DEFAULT_EXECUTE_ONLY_COVERING_TEST_CASES
Expand Down
Loading

0 comments on commit 2fc798d

Please sign in to comment.