Skip to content

Commit 298015c

Browse files
authored
Fix tomasvotruba/type-coverage 0.2.* test expectations (#139)
1 parent 8b93efc commit 298015c

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

lib/BaselineAnalyzer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function checkSeaLevels(AnalyzerResult $result, BaselineError $baselineE
120120
{
121121
if (
122122
sscanf(
123-
$baselineError->unwrapMessage(),
123+
$this->normalizeMessage($baselineError),
124124
$this->printfToScanfFormat(self::PROPERTY_TYPE_DEClARATION_SEA_LEVEL_MESSAGE),
125125
$absoluteCountMin, $coveragePercent, $goalPercent) >= 2
126126
) {
@@ -132,7 +132,7 @@ private function checkSeaLevels(AnalyzerResult $result, BaselineError $baselineE
132132

133133
if (
134134
sscanf(
135-
$baselineError->unwrapMessage(),
135+
$this->normalizeMessage($baselineError),
136136
$this->printfToScanfFormat(self::PARAM_TYPE_DEClARATION_SEA_LEVEL_MESSAGE),
137137
$absoluteCountMin, $coveragePercent, $goalPercent) >= 2
138138
) {
@@ -144,7 +144,7 @@ private function checkSeaLevels(AnalyzerResult $result, BaselineError $baselineE
144144

145145
if (
146146
sscanf(
147-
$baselineError->unwrapMessage(),
147+
$this->normalizeMessage($baselineError),
148148
$this->printfToScanfFormat(self::RETURN_TYPE_DEClARATION_SEA_LEVEL_MESSAGE),
149149
$absoluteCountMin, $coveragePercent, $goalPercent) >= 2
150150
) {
@@ -159,6 +159,11 @@ private function printfToScanfFormat(string $format): string {
159159
// we don't need the float value, therefore simply ignore it, to make the format parseable by sscanf
160160
// see https://github.com/php/php-src/issues/12126
161161
// additionally this makes the output format of tomasvotruba/type-coverage 0.2.* compatible with tomasvotruba/type-coverage 0.1.*
162-
return str_replace('%.1f', '', $format);
162+
return str_replace('%d - %.1f', '%d', $format);
163+
}
164+
165+
private function normalizeMessage(BaselineError $baselineError): string {
166+
// makes the message format of tomasvotruba/type-coverage 0.2.* compatible with tomasvotruba/type-coverage 0.1.*
167+
return \Safe\preg_replace('/only \d+ \- (\d+).\d %/', 'only $1 %', $baselineError->unwrapMessage());
163168
}
164169
}

lib/BaselineError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class BaselineError
2222
*/
2323
public function unwrapMessage(): string {
2424
$msg = $this->message;
25-
$msg = str_replace(['\\.', '%%'], ['.', '%'], $msg);
25+
$msg = str_replace(['\\-', '\\.', '%%'], ['-', '.', '%'], $msg);
2626
$msg = trim($msg, '#^$');
2727
return $msg;
2828
}

tests/fixtures/sea-level-0_2.neon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
parameters:
44
ignoreErrors:
55
-
6-
message: "#^Out of 1 possible property types, only 1 \\- 36\\.0 %% actually have it\\. Add more property types to get over 99 %%$#"
6+
message: "#^Out of 1000 possible property types, only 10 \\- 1\\.0 %% actually have it\\. Add more property types to get over 99 %%$#"
77
count: 2
88
path: N/A
99

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

1515
-
16-
message: "#^Out of 33 possible param types, only 27 \\- 36\\.0 %% actually have it\\. Add more param types to get over 99 %%$#"
16+
message: "#^Out of 1000 possible param types, only 275 \\- 27\\.5 %% actually have it\\. Add more param types to get over 99 %%$#"
1717
count: 2
1818
path: N/A

tests/fixtures/sea-level.neon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
parameters:
44
ignoreErrors:
55
-
6-
message: "#^Out of 1 possible property types, only 1 %% actually have it\\. Add more property types to get over 99 %%$#"
6+
message: "#^Out of 1000 possible property types, only 1 %% actually have it\\. Add more property types to get over 99 %%$#"
77
count: 1
88
path: N/A
99

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

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

0 commit comments

Comments
 (0)