Skip to content

Commit

Permalink
Merge branch '0.26'
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Jan 11, 2022
2 parents 6820703 + 1e584ea commit 07490ad
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Logger/Html/StrykerHtmlReportBuilder.php
Expand Up @@ -58,6 +58,7 @@
use Infection\Mutator\MutatorFactory;
use Infection\Mutator\ProfileList;
use Infection\Mutator\Removal\MethodCallRemoval;
use Infection\Str;
use function ltrim;
use function md5;
use const PHP_EOL;
Expand Down Expand Up @@ -249,14 +250,14 @@ function (MutantExecutionResult $result) use ($originalCode): array {
return [
'id' => $result->getMutantHash(),
'mutatorName' => $result->getMutatorName(),
'replacement' => ltrim($replacement),
'replacement' => Str::convertToUtf8(Str::trimLineReturns(ltrim($replacement))),
'description' => $this->getMutatorDescription($result->getMutatorName()),
'location' => [
'start' => ['line' => $result->getOriginalStartingLine(), 'column' => $startingColumn],
'end' => ['line' => $endingLine, 'column' => $endingColumn],
],
'status' => self::DETECTION_STATUS_MAP[$result->getDetectionStatus()],
'statusReason' => $result->getProcessOutput(),
'statusReason' => Str::convertToUtf8(Str::trimLineReturns($result->getProcessOutput())),
'coveredBy' => array_unique(array_map(
fn (TestLocation $testLocation): string => $this->buildTestMethodId($testLocation->getMethod()),
$result->getTests()
Expand Down
10 changes: 2 additions & 8 deletions src/Logger/JsonLogger.php
Expand Up @@ -41,7 +41,6 @@
use Infection\Str;
use function json_encode;
use const JSON_THROW_ON_ERROR;
use function mb_convert_encoding;

/**
* @internal
Expand Down Expand Up @@ -112,16 +111,11 @@ private function getResultsLine(array $executionResults): array
'originalFilePath' => $mutantProcess->getOriginalFilePath(),
'originalStartLine' => $mutantProcess->getOriginalStartingLine(),
],
'diff' => $this->convertToUtf8(Str::trimLineReturns($mutantProcess->getMutantDiff())),
'processOutput' => $this->convertToUtf8(Str::trimLineReturns($mutantProcess->getProcessOutput())),
'diff' => Str::convertToUtf8(Str::trimLineReturns($mutantProcess->getMutantDiff())),
'processOutput' => Str::convertToUtf8(Str::trimLineReturns($mutantProcess->getProcessOutput())),
];
}

return $mutatorRows;
}

private function convertToUtf8(string $string): string
{
return mb_convert_encoding($string, 'UTF-8', 'UTF-8');
}
}
6 changes: 6 additions & 0 deletions src/Str.php
Expand Up @@ -39,6 +39,7 @@
use function count;
use function explode;
use function implode;
use function mb_convert_encoding;
use const PHP_EOL;
use function str_replace;
use function trim;
Expand Down Expand Up @@ -89,4 +90,9 @@ public static function trimLineReturns(string $string): string

return implode(PHP_EOL, $lines);
}

public static function convertToUtf8(string $string): string
{
return mb_convert_encoding($string, 'UTF-8', 'UTF-8');
}
}
41 changes: 41 additions & 0 deletions tests/phpunit/Logger/Html/StrykerHtmlReportBuilderTest.php
Expand Up @@ -53,6 +53,7 @@
use function Later\now;
use const PHP_EOL;
use PHPUnit\Framework\TestCase;
use function Safe\base64_decode;
use function Safe\file_get_contents;
use function Safe\json_decode;
use function Safe\json_encode;
Expand Down Expand Up @@ -186,6 +187,18 @@ public function metricsProvider()
'killedBy' => [],
'testsCompleted' => 0,
],
[
'id' => '22f68ca331c9262cc97322271d88d06d',
'mutatorName' => 'PublicVisibility',
'replacement' => 'protected function add(int $a, int $b) : int',
'description' => 'Replaces the `public` method visibility keyword with `protected`.',
'location' => ['start' => ['line' => 13, 'column' => 5], 'end' => ['line' => 13, 'column' => 6]],
'status' => 'Killed',
'statusReason' => 'Output without ability to detect the number of executed testsi?',
'coveredBy' => ['06a6c58caae5aa33e9b787f064618f5e'],
'killedBy' => [],
'testsCompleted' => 0,
],
],
],
],
Expand Down Expand Up @@ -415,6 +428,34 @@ final class ForHtmlReport2
],
'Output without ability to detect the number of executed tests'
),
//
// with non UTF-8 character
$this->createMutantExecutionResult(
DetectionStatus::KILLED,
<<<'DIFF'
--- Original
+++ New
@@ @@
use function array_fill_keys;
final class ForHtmlReport2
{
- public function add(int $a, int $b) : int
+ protected function add(int $a, int $b) : int
{
return 0;
DIFF,
'22f68ca331c9262cc97322271d88d06d',
PublicVisibility::class,
realpath(__DIR__ . '/../../Fixtures/ForHtmlReport2.php'),
13,
35,
124,
547,
[
new TestLocation('TestClass::test_method1', '/infection/path/to/TestClass.php', 0.123),
],
'Output without ability to detect the number of executed tests' . base64_decode('abc', true) // produces non UTF-8 character
),
);
}

Expand Down

0 comments on commit 07490ad

Please sign in to comment.