From e62251f0459b68d952268b8927cb1391a94e4b7a Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Mon, 22 Jan 2018 18:13:55 -0500 Subject: [PATCH 1/2] 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. --- VariableAnalysis/Tests/BaseTestCase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/VariableAnalysis/Tests/BaseTestCase.php b/VariableAnalysis/Tests/BaseTestCase.php index 072d2177..20759d97 100644 --- a/VariableAnalysis/Tests/BaseTestCase.php +++ b/VariableAnalysis/Tests/BaseTestCase.php @@ -19,7 +19,9 @@ public function prepareLocalFileForSniffs($sniffFiles, string $fixtureFile): Loc } public function getLineNumbersFromMessages(array $messages): array { - return array_keys($messages); + $lines = array_keys($messages); + sort($lines); + return $lines; } public function getWarningLineNumbersFromFile(LocalFile $phpcsFile): array { From 0f96e0978de43c38033318375cd2e8f990a424f5 Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Mon, 22 Jan 2018 18:18:21 -0500 Subject: [PATCH 2/2] Tests: update tests for sorted line numbers --- .../Tests/CodeAnalysis/VariableAnalysisTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php b/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php index 5bea562d..0dd95cc1 100644 --- a/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php +++ b/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php @@ -73,8 +73,8 @@ public function testFunctionWithGlobalVarWarnings() { $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ - 7, 4, + 7, 22, ]; $this->assertEquals($expectedWarnings, $lines); @@ -214,8 +214,8 @@ public function testFunctionWithReferenceWarnings() { $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ - 20, 8, + 20, 32, 33, 34, @@ -363,13 +363,13 @@ public function testCompactWarnings() { $phpcsFile->process(); $lines = $this->getWarningLineNumbersFromFile($phpcsFile); $expectedWarnings = [ + 2, 7, 10, - 2, - 23, - 26, 14, 19, + 23, + 26, ]; $this->assertEquals($expectedWarnings, $lines); }