Skip to content

Commit 644bf05

Browse files
committed
Add tests for error count
1 parent 3e6e696 commit 644bf05

5 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/BaselinePerIdentifierFormatter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function formatErrors(
7474
foreach ($fileErrors as $identifier => $errors) {
7575
$errorsToOutput = [];
7676

77+
$errorsCount = 0;
7778
foreach ($errors as $file => $errorMessages) {
7879
$fileErrorsCounts = [];
7980

@@ -94,12 +95,12 @@ public function formatErrors(
9495
'count' => $count,
9596
'path' => NeonHelper::escape($file),
9697
];
98+
$errorsCount += $count;
9799
}
98100
}
99101

100102
$includes[] = $identifier . '.neon';
101103
$baselineFilePath = $this->baselinesDir . '/' . $identifier . '.neon';
102-
$errorsCount = count($errorsToOutput);
103104

104105
$output->writeLineFormatted(sprintf('Writing baseline file %s with %d errors', $baselineFilePath, $errorsCount));
105106

tests/Rule/BaselinePerIdentifierFormatterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22

33
namespace ShipMonk\PHPStan\Baseline;
44

@@ -24,6 +24,7 @@ public function testFormat(): void
2424
$this->createAnalysisResult(
2525
[
2626
(new Error('Error simple', $fakeRoot . '/app/file.php', 1))->withIdentifier('sample.identifier'), // @phpstan-ignore phpstanApi.constructor
27+
(new Error('Error simple', $fakeRoot . '/app/file.php', 5))->withIdentifier('sample.identifier'), // @phpstan-ignore phpstanApi.constructor
2728
(new Error('Error to escape \'#', $fakeRoot . '/app/config.php', 2))->withIdentifier('another.identifier'), // @phpstan-ignore phpstanApi.constructor
2829
(new Error('Error 3', $fakeRoot . '/app/index.php', 3)), // @phpstan-ignore phpstanApi.constructor
2930
],
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# total 1 error
1+
# total 2 errors
22

33
parameters:
44
ignoreErrors:
55
-
66
message: '#^Error simple$#'
7-
count: 1
7+
count: 2
88
path: ../app/file.php

tests/Rule/data/baselines-php/sample.identifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php declare(strict_types = 1);
22

3-
// total 1 error
3+
// total 2 errors
44

55
$ignoreErrors = [];
66
$ignoreErrors[] = [
77
'message' => '#^Error simple$#',
8-
'count' => 1,
8+
'count' => 2,
99
'path' => __DIR__ . '/../app/file.php',
1010
];
1111

tests/SplitterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testSplitter(): void
6161
self::assertSame([
6262
$folder . '/baselines/another.identifier.neon' => 1,
6363
$folder . '/baselines/missing-identifier.neon' => 1,
64-
$folder . '/baselines/sample.identifier.neon' => 1,
64+
$folder . '/baselines/sample.identifier.neon' => 2,
6565
$folder . '/baselines/loader.neon' => null,
6666
], $written);
6767
}
@@ -84,7 +84,7 @@ private function getSampleErrors(): array
8484
'ignoreErrors' => [
8585
[
8686
'message' => '#^Error simple$#',
87-
'count' => 1,
87+
'count' => 2,
8888
'path' => '../app/file.php',
8989
'identifier' => 'sample.identifier',
9090
],

0 commit comments

Comments
 (0)