Skip to content

Commit e75b49d

Browse files
ondrejmirtesclaude
andcommitted
Assert UnusedVariableRule errors through analyse()
testRedundantOffsets and testDynamicOffsetOverwritten gathered the errors themselves to filter or to check identifiers; analyse() over the whole fixture covers the same, like every other rule test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bm4YbtwnyY5UMgp64hK1ff
1 parent 10de21d commit e75b49d

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

‎tests/PHPStan/Rules/DeadCode/UnusedVariableRuleTest.php‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -379,28 +379,24 @@ public function testOffsets(): void
379379

380380
public function testRedundantOffsets(): void
381381
{
382-
$redundant = [];
383-
foreach ($this->gatherAnalyserErrors([__DIR__ . '/data/unused-variable-redundant-offsets.php']) as $error) {
384-
if ($error->getIdentifier() !== 'assign.redundant') {
385-
continue;
386-
}
387-
$redundant[] = [$error->getMessage(), $error->getLine()];
388-
}
389-
$this->assertSame([
382+
$this->analyse([__DIR__ . '/data/unused-variable-redundant-offsets.php'], [
383+
['Offset 0 of array assigned to variable $a is never read before being overwritten.', 7],
384+
['Offset 1 of array assigned to variable $a is never read.', 7],
390385
['Offset $a[0] is assigned value 1 but it already has that value.', 8],
386+
['Offset 0 of array assigned to variable $a is never read before being overwritten.', 13],
391387
['Offset $a[0] is assigned value 1 but it already has that value.', 14],
392388
['Offset $a[\'x\'][\'y\'] is assigned value 1 but it already has that value.', 21],
389+
['Offset 0 of array assigned to variable $a is never read before being overwritten.', 27],
393390
['Offset $a[\'0\'] is assigned value 1 but it already has that value.', 28],
394-
], $redundant);
391+
['Offset 0 of array assigned to variable $a is never read before being overwritten.', 34],
392+
]);
395393
}
396394

397395
public function testDynamicOffsetOverwritten(): void
398396
{
399-
$errors = $this->gatherAnalyserErrors([__DIR__ . '/data/unused-variable-offset-overwrite.php']);
400-
$this->assertCount(1, $errors);
401-
$this->assertSame('Value assigned to $a[$i] is never read.', $errors[0]->getMessage());
402-
$this->assertSame('assign.unused', $errors[0]->getIdentifier());
403-
$this->assertSame(8, $errors[0]->getLine());
397+
$this->analyse([__DIR__ . '/data/unused-variable-offset-overwrite.php'], [
398+
['Value assigned to $a[$i] is never read.', 8],
399+
]);
404400
}
405401

406402
public function testOverwritten(): void

0 commit comments

Comments
 (0)