Skip to content

Commit 0b60660

Browse files
authored
Fix outputted paths (#17)
1 parent f6d7bb7 commit 0b60660

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

phpstan.neon.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ parameters:
4040

4141
shipmonkBaselinePerIdentifier:
4242
directory: %currentWorkingDirectory%
43+
44+
ignoreErrors:
45+
- # allow uncatched exceptions in tests
46+
identifier: missingType.checkedException
47+
path: tests/*

src/BaselineSplitter.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use ShipMonk\PHPStan\Baseline\Exception\ErrorException;
66
use ShipMonk\PHPStan\Baseline\Handler\HandlerFactory;
77
use SplFileInfo;
8-
use function array_keys;
98
use function assert;
109
use function count;
1110
use function dirname;
@@ -56,14 +55,16 @@ public function split(string $loaderFilePath): array
5655

5756
$groupedErrors = $this->groupErrorsByIdentifier($ignoredErrors, $folder);
5857

59-
$createdBaselines = [];
58+
$outputInfo = [];
59+
$baselineFiles = [];
6060

6161
foreach ($groupedErrors as $identifier => $errors) {
6262
$fileName = $identifier . '.' . $extension;
6363
$filePath = $folder . '/' . $fileName;
6464
$errorsCount = count($errors);
6565

66-
$createdBaselines[$fileName] = $errorsCount;
66+
$outputInfo[$filePath] = $errorsCount;
67+
$baselineFiles[] = $fileName;
6768

6869
$plural = $errorsCount === 1 ? '' : 's';
6970
$prefix = "total $errorsCount error$plural";
@@ -72,12 +73,12 @@ public function split(string $loaderFilePath): array
7273
$this->writeFile($filePath, $encodedData);
7374
}
7475

75-
$baselineLoaderData = $handler->encodeBaselineLoader(array_keys($createdBaselines), $this->indent);
76-
$this->writeFile($loaderFilePath, $baselineLoaderData);
76+
$baselineLoaderData = $handler->encodeBaselineLoader($baselineFiles, $this->indent);
77+
$this->writeFile($realPath, $baselineLoaderData);
7778

78-
$createdBaselines[$loaderFilePath] = null;
79+
$outputInfo[$realPath] = null;
7980

80-
return $createdBaselines;
81+
return $outputInfo;
8182
}
8283

8384
/**

tests/BinTest.php renamed to tests/SplitterTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
use function uniqid;
1515
use function var_export;
1616

17-
class BinTest extends TestCase
17+
class SplitterTest extends TestCase
1818
{
1919

20-
public function testNeon(): void
20+
public function testBinaryWithNeon(): void
2121
{
2222
$fakeRoot = $this->prepareSampleFolder();
2323
$squashed = $this->getSampleErrors();
@@ -32,7 +32,7 @@ public function testNeon(): void
3232
self::assertFileEquals(__DIR__ . '/Rule/data/baselines-neon/missing-identifier.neon', $fakeRoot . '/baselines/missing-identifier.neon');
3333
}
3434

35-
public function testPhp(): void
35+
public function testBinaryWithPhp(): void
3636
{
3737
$fakeRoot = $this->prepareSampleFolder();
3838
$squashed = $this->getSampleErrors();
@@ -47,6 +47,25 @@ public function testPhp(): void
4747
self::assertFileEquals(__DIR__ . '/Rule/data/baselines-php/missing-identifier.php', $fakeRoot . '/baselines/missing-identifier.php');
4848
}
4949

50+
public function testSplitter(): void
51+
{
52+
$folder = $this->prepareSampleFolder();
53+
$squashed = $this->getSampleErrors();
54+
55+
$loaderPath = $folder . '/baselines/loader.neon';
56+
file_put_contents($loaderPath, Neon::encode($squashed));
57+
58+
$splitter = new BaselineSplitter("\t");
59+
$written = $splitter->split($loaderPath);
60+
61+
self::assertSame([
62+
$folder . '/baselines/another.identifier.neon' => 1,
63+
$folder . '/baselines/missing-identifier.neon' => 1,
64+
$folder . '/baselines/sample.identifier.neon' => 1,
65+
$folder . '/baselines/loader.neon' => null,
66+
], $written);
67+
}
68+
5069
private function prepareSampleFolder(): string
5170
{
5271
$folder = sys_get_temp_dir() . '/' . uniqid('split');

0 commit comments

Comments
 (0)