Skip to content

Commit

Permalink
Correctly log to Stryker dashboard when file loggers are disabled wit…
Browse files Browse the repository at this point in the history
…h `--log-verbosity=none`
  • Loading branch information
maks-rafalko committed Jan 8, 2022
1 parent f5429e3 commit c161d33
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/Metrics/TargetDetectionStatusesProvider.php
Expand Up @@ -92,6 +92,16 @@ private function findRequired(): Generator
yield DetectionStatus::ESCAPED;
}

$strykerConfig = $this->logConfig->getStrykerConfig();
$isStrykerFullReportEnabled = $strykerConfig !== null && $strykerConfig->isForFullReport();

// Stryker HTML report needs all mutation results.
if ($isStrykerFullReportEnabled) {
yield from DetectionStatus::ALL;

return;
}

// This one stops all file logging.
if ($this->logVerbosity === LogVerbosity::NONE) {
return;
Expand All @@ -112,9 +122,7 @@ private function findRequired(): Generator
}

// HTML logger needs all mutation results to make a summary.
$strykerConfig = $this->logConfig->getStrykerConfig();

if ($this->logConfig->getHtmlLogFilePath() !== null || ($strykerConfig !== null && $strykerConfig->isForFullReport())) {
if ($this->logConfig->getHtmlLogFilePath() !== null) {
yield from DetectionStatus::ALL;

return;
Expand Down
21 changes: 20 additions & 1 deletion tests/phpunit/Metrics/TargetDetectionStatusesProviderTest.php
Expand Up @@ -215,7 +215,7 @@ public function test_it_provides_all_statuses_for_full_stryker_report(): void
{
$logs = $this->createMock(Logs::class);
$logs
->expects($this->once())
->expects($this->never())
->method('getHtmlLogFilePath')
->willReturn(null)
;
Expand All @@ -230,6 +230,25 @@ public function test_it_provides_all_statuses_for_full_stryker_report(): void
$this->assertProvidesExcluding([], $provider->get());
}

public function test_it_provides_all_statuses_for_full_stryker_report_with_verbosity_none(): void
{
$logs = $this->createMock(Logs::class);
$logs
->expects($this->never())
->method('getHtmlLogFilePath')
->willReturn(null)
;
$logs
->expects($this->once())
->method('getStrykerConfig')
->willReturn(StrykerConfig::forFullReport('master'))
;

$provider = new TargetDetectionStatusesProvider($logs, LogVerbosity::NONE, true, false);

$this->assertProvidesExcluding([], $provider->get());
}

public function test_it_provides_nothing_for_stryker_badge_report(): void
{
$logs = $this->createMock(Logs::class);
Expand Down

0 comments on commit c161d33

Please sign in to comment.