Skip to content

Commit e17df73

Browse files
authored
Tests: sort line numbers (#23)
* Tests: Sort getLineNumbersFromMessages Sometimes the line numbers from warnings or errors are not in order. This sorts the results making it easier to write tests for the line numbers regardless of order. * Tests: update tests for sorted line numbers
1 parent 457183f commit e17df73

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

VariableAnalysis/Tests/BaseTestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public function prepareLocalFileForSniffs($sniffFiles, string $fixtureFile): Loc
1919
}
2020

2121
public function getLineNumbersFromMessages(array $messages): array {
22-
return array_keys($messages);
22+
$lines = array_keys($messages);
23+
sort($lines);
24+
return $lines;
2325
}
2426

2527
public function getWarningLineNumbersFromFile(LocalFile $phpcsFile): array {

VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function testFunctionWithGlobalVarWarnings() {
7373
$phpcsFile->process();
7474
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
7575
$expectedWarnings = [
76-
7,
7776
4,
77+
7,
7878
22,
7979
];
8080
$this->assertEquals($expectedWarnings, $lines);
@@ -214,8 +214,8 @@ public function testFunctionWithReferenceWarnings() {
214214
$phpcsFile->process();
215215
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
216216
$expectedWarnings = [
217-
20,
218217
8,
218+
20,
219219
32,
220220
33,
221221
34,
@@ -363,13 +363,13 @@ public function testCompactWarnings() {
363363
$phpcsFile->process();
364364
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
365365
$expectedWarnings = [
366+
2,
366367
7,
367368
10,
368-
2,
369-
23,
370-
26,
371369
14,
372370
19,
371+
23,
372+
26,
373373
];
374374
$this->assertEquals($expectedWarnings, $lines);
375375
}

0 commit comments

Comments
 (0)