Skip to content

Commit 7b68603

Browse files
committed
RuleTestCase - do not assert diffs, but whole files
1 parent cfbf11c commit 7b68603

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

src/Testing/RuleTestCase.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
use PHPStan\Rules\Properties\ReadWritePropertiesExtensionProvider;
3737
use PHPStan\Rules\Rule;
3838
use PHPStan\Type\FileTypeMapper;
39-
use SebastianBergmann\Diff\Differ;
40-
use SebastianBergmann\Diff\Output\DiffOnlyOutputBuilder;
4139
use function array_map;
4240
use function array_merge;
4341
use function count;
@@ -197,7 +195,7 @@ static function (Error $error) use ($strictlyTypedSprintf): string {
197195
$this->assertSame($expectedErrorsString, $actualErrorsString);
198196
}
199197

200-
public function fix(string $file, string $expectedDiff): void
198+
public function fix(string $file, string $expectedFile): void
201199
{
202200
[$errors] = $this->gatherAnalyserErrorsWithDelayedErrors([$file]);
203201
$diffs = [];
@@ -209,11 +207,11 @@ public function fix(string $file, string $expectedDiff): void
209207
}
210208

211209
$patcher = self::getContainer()->getByType(Patcher::class);
212-
$originalFileContents = FileReader::read($file);
213210
$newFileContents = $patcher->applyDiffs($file, $diffs); // @phpstan-ignore missingType.checkedException, missingType.checkedException
214211

215-
$differ = new Differ(new DiffOnlyOutputBuilder(''));
216-
$this->assertSame($expectedDiff, $differ->diff($originalFileContents, $newFileContents));
212+
$fixedFileContents = FileReader::read($expectedFile);
213+
214+
$this->assertSame($fixedFileContents, $newFileContents);
217215
}
218216

219217
/**

tests/PHPStan/Build/NamedArgumentsRuleTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,18 @@ public function testRule(): void
4141

4242
public function testNoFix(): void
4343
{
44-
$this->fix(__DIR__ . '/data/named-arguments-no-errors.php', '');
44+
$this->fix(
45+
__DIR__ . '/data/named-arguments-no-errors.php',
46+
__DIR__ . '/data/named-arguments-no-errors.php',
47+
);
4548
}
4649

4750
public function testFix(): void
4851
{
49-
$this->fix(__DIR__ . '/data/named-arguments.php', <<<DIFF
50-
- new Exception('foo', 0, new Exception('previous'));
51-
- new Exception('foo', code: 0, previous: new Exception('previous'));
52-
+ new Exception('foo', previous: new Exception('previous'));
53-
+ new Exception(previous: new Exception('previous'));
54-
- new Exception('', 0, new Exception('previous'));
55-
+ new Exception(previous: new Exception('previous'));
56-
57-
DIFF);
52+
$this->fix(
53+
__DIR__ . '/data/named-arguments.php',
54+
__DIR__ . '/data/named-arguments.php.fixed',
55+
);
5856
}
5957

6058
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php // lint >= 8.0
2+
3+
namespace NamedArgumentRule;
4+
5+
use Exception;
6+
7+
class Foo
8+
{
9+
10+
public function doFoo(): void
11+
{
12+
new Exception('foo', 0);
13+
new Exception('foo', 0, null);
14+
new Exception('foo', previous: new Exception('previous'));
15+
new Exception('foo', previous: new Exception('previous'));
16+
new Exception(previous: new Exception('previous'));
17+
new Exception('foo', code: 1, previous: new Exception('previous'));
18+
new Exception('foo', 1, new Exception('previous'));
19+
new Exception('foo', 1);
20+
new Exception(previous: new Exception('previous'));
21+
}
22+
23+
}

0 commit comments

Comments
 (0)