From 0775e0c683badad52c03b11c2cd86a9fdecb937a Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Fri, 8 Jan 2021 11:31:05 -0500 Subject: [PATCH] Add test for compact being used with variable strings (#223) --- .../VariableAnalysisTest.php | 23 +++++++++++++++++++ .../fixtures/CompactFixture.php | 19 +++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Tests/VariableAnalysisSniff/VariableAnalysisTest.php b/Tests/VariableAnalysisSniff/VariableAnalysisTest.php index b461ee46..8e77b1a5 100644 --- a/Tests/VariableAnalysisSniff/VariableAnalysisTest.php +++ b/Tests/VariableAnalysisSniff/VariableAnalysisTest.php @@ -502,10 +502,33 @@ public function testCompactWarnings() { 19, 23, 26, + 36, ]; $this->assertEquals($expectedWarnings, $lines); } + public function testCompactWarningsHaveCorrectSniffCodes() { + $fixtureFile = $this->getFixture('CompactFixture.php'); + $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); + $phpcsFile->ruleset->setSniffProperty( + 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff', + 'allowUnusedParametersBeforeUsed', + 'false' + ); + $phpcsFile->process(); + + $warnings = $phpcsFile->getWarnings(); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[2][49][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[7][23][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[10][54][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[14][52][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[19][5][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[23][23][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[26][66][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[36][5][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[36][23][0]['source']); + } + public function testTraitAllowsThis() { $fixtureFile = $this->getFixture('TraitFixture.php'); $phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); diff --git a/Tests/VariableAnalysisSniff/fixtures/CompactFixture.php b/Tests/VariableAnalysisSniff/fixtures/CompactFixture.php index a92e20a8..d259b1bd 100644 --- a/Tests/VariableAnalysisSniff/fixtures/CompactFixture.php +++ b/Tests/VariableAnalysisSniff/fixtures/CompactFixture.php @@ -1,32 +1,37 @@