Skip to content

Commit

Permalink
Fix tomasvotruba/type-coverage 0.2.* test expectations (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 14, 2023
1 parent 8b93efc commit 298015c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
13 changes: 9 additions & 4 deletions lib/BaselineAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function checkSeaLevels(AnalyzerResult $result, BaselineError $baselineE
{
if (
sscanf(
$baselineError->unwrapMessage(),
$this->normalizeMessage($baselineError),
$this->printfToScanfFormat(self::PROPERTY_TYPE_DEClARATION_SEA_LEVEL_MESSAGE),
$absoluteCountMin, $coveragePercent, $goalPercent) >= 2
) {
Expand All @@ -132,7 +132,7 @@ private function checkSeaLevels(AnalyzerResult $result, BaselineError $baselineE

if (
sscanf(
$baselineError->unwrapMessage(),
$this->normalizeMessage($baselineError),
$this->printfToScanfFormat(self::PARAM_TYPE_DEClARATION_SEA_LEVEL_MESSAGE),
$absoluteCountMin, $coveragePercent, $goalPercent) >= 2
) {
Expand All @@ -144,7 +144,7 @@ private function checkSeaLevels(AnalyzerResult $result, BaselineError $baselineE

if (
sscanf(
$baselineError->unwrapMessage(),
$this->normalizeMessage($baselineError),
$this->printfToScanfFormat(self::RETURN_TYPE_DEClARATION_SEA_LEVEL_MESSAGE),
$absoluteCountMin, $coveragePercent, $goalPercent) >= 2
) {
Expand All @@ -159,6 +159,11 @@ private function printfToScanfFormat(string $format): string {
// we don't need the float value, therefore simply ignore it, to make the format parseable by sscanf
// see https://github.com/php/php-src/issues/12126
// additionally this makes the output format of tomasvotruba/type-coverage 0.2.* compatible with tomasvotruba/type-coverage 0.1.*
return str_replace('%.1f', '', $format);
return str_replace('%d - %.1f', '%d', $format);
}

private function normalizeMessage(BaselineError $baselineError): string {
// makes the message format of tomasvotruba/type-coverage 0.2.* compatible with tomasvotruba/type-coverage 0.1.*
return \Safe\preg_replace('/only \d+ \- (\d+).\d %/', 'only $1 %', $baselineError->unwrapMessage());
}
}
2 changes: 1 addition & 1 deletion lib/BaselineError.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class BaselineError
*/
public function unwrapMessage(): string {
$msg = $this->message;
$msg = str_replace(['\\.', '%%'], ['.', '%'], $msg);
$msg = str_replace(['\\-', '\\.', '%%'], ['-', '.', '%'], $msg);
$msg = trim($msg, '#^$');
return $msg;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/sea-level-0_2.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
parameters:
ignoreErrors:
-
message: "#^Out of 1 possible property types, only 1 \\- 36\\.0 %% actually have it\\. Add more property types to get over 99 %%$#"
message: "#^Out of 1000 possible property types, only 10 \\- 1\\.0 %% actually have it\\. Add more property types to get over 99 %%$#"
count: 2
path: N/A

-
message: "#^Out of 22 possible return types, only 4 \\- 36\\.0 %% actually have it\\. Add more return types to get over 99 %%$#"
message: "#^Out of 1000 possible return types, only 41 \\- 4\\.1 %% actually have it\\. Add more return types to get over 99 %%$#"
count: 2
path: N/A

-
message: "#^Out of 33 possible param types, only 27 \\- 36\\.0 %% actually have it\\. Add more param types to get over 99 %%$#"
message: "#^Out of 1000 possible param types, only 275 \\- 27\\.5 %% actually have it\\. Add more param types to get over 99 %%$#"
count: 2
path: N/A
6 changes: 3 additions & 3 deletions tests/fixtures/sea-level.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
parameters:
ignoreErrors:
-
message: "#^Out of 1 possible property types, only 1 %% actually have it\\. Add more property types to get over 99 %%$#"
message: "#^Out of 1000 possible property types, only 1 %% actually have it\\. Add more property types to get over 99 %%$#"
count: 1
path: N/A

-
message: "#^Out of 22 possible return types, only 4 %% actually have it\\. Add more return types to get over 99 %%$#"
message: "#^Out of 500 possible return types, only 4 %% actually have it\\. Add more return types to get over 99 %%$#"
count: 1
path: N/A

-
message: "#^Out of 33 possible param types, only 27 %% actually have it\\. Add more param types to get over 99 %%$#"
message: "#^Out of 100 possible param types, only 27 %% actually have it\\. Add more param types to get over 99 %%$#"
count: 1
path: N/A

0 comments on commit 298015c

Please sign in to comment.