From 1cc53f11727d0a1d95ee94fa149a820f404d4dbe Mon Sep 17 00:00:00 2001 From: Brown Date: Thu, 14 May 2020 23:22:49 -0400 Subject: [PATCH] Fix tests --- tests/JsonOutputTest.php | 144 ------------------------------------- tests/ReportOutputTest.php | 107 +++++++++++++++++++++------ 2 files changed, 84 insertions(+), 167 deletions(-) diff --git a/tests/JsonOutputTest.php b/tests/JsonOutputTest.php index ff0d990c8..01f302097 100644 --- a/tests/JsonOutputTest.php +++ b/tests/JsonOutputTest.php @@ -64,150 +64,6 @@ class JsonOutputTest extends TestCase ); } - /** - * @return void - */ - public function testJsonOutputForGetPsalmDotOrg() - { - $file_contents = ' 10) { - $a = 5; -} else { - //$a = 2; -} - -echo $a;'; - - $this->addFile( - 'somefile.php', - $file_contents - ); - - $this->project_analyzer->consolidateAnalyzedData(); - - $this->analyzeFile('somefile.php', new Context()); - - $issue_data = IssueBuffer::getIssuesData()['somefile.php']; - - $this->assertSame( - [ - [ - 'severity' => 'error', - 'line_from' => 3, - 'line_to' => 3, - 'type' => 'UndefinedVariable', - 'message' => 'Cannot find referenced variable $as_you', - 'file_name' => 'somefile.php', - 'file_path' => 'somefile.php', - 'snippet' => ' return $as_you . "type";', - 'selected_text' => '$as_you', - 'from' => 66, - 'to' => 73, - 'snippet_from' => 57, - 'snippet_to' => 83, - 'column_from' => 10, - 'column_to' => 17, - 'error_level' => -1, - 'shortcode' => 24, - 'link' => 'https://psalm.dev/024' - ], - [ - 'severity' => 'error', - 'line_from' => 2, - 'line_to' => 2, - 'type' => 'UnusedParam', - 'message' => 'Param $your_code is never referenced in this method', - 'file_name' => 'somefile.php', - 'file_path' => 'somefile.php', - 'snippet' => 'function psalmCanVerify(int $your_code): ?string {', - 'selected_text' => '$your_code', - 'from' => 34, - 'to' => 44, - 'snippet_from' => 6, - 'snippet_to' => 56, - 'column_from' => 29, - 'column_to' => 39, - 'error_level' => -2, - 'shortcode' => 135, - 'link' => 'https://psalm.dev/135' - ], - [ - 'severity' => 'error', - 'line_from' => 2, - 'line_to' => 2, - 'type' => 'MixedInferredReturnType', - 'message' => 'Could not verify return type \'null|string\' for psalmCanVerify', - 'file_name' => 'somefile.php', - 'file_path' => 'somefile.php', - 'snippet' => 'function psalmCanVerify(int $your_code): ?string {', - 'selected_text' => '?string', - 'from' => 47, - 'to' => 54, - 'snippet_from' => 6, - 'snippet_to' => 56, - 'column_from' => 42, - 'column_to' => 49, - 'error_level' => 1, - 'shortcode' => 47, - 'link' => 'https://psalm.dev/047' - ], - [ - 'severity' => 'error', - 'line_from' => 7, - 'line_to' => 7, - 'type' => 'UndefinedConstant', - 'message' => 'Const CHANGE_ME is not defined', - 'file_name' => 'somefile.php', - 'file_path' => 'somefile.php', - 'snippet' => 'echo CHANGE_ME;', - 'selected_text' => 'CHANGE_ME', - 'from' => 125, - 'to' => 134, - 'snippet_from' => 120, - 'snippet_to' => 135, - 'column_from' => 6, - 'column_to' => 15, - 'error_level' => -1, - 'shortcode' => 20, - 'link' => 'https://psalm.dev/020' - ], - [ - 'severity' => 'error', - 'line_from' => 15, - 'line_to' => 15, - 'type' => 'PossiblyUndefinedGlobalVariable', - 'message' => 'Possibly undefined global variable $a, first seen on line 10', - 'file_name' => 'somefile.php', - 'file_path' => 'somefile.php', - 'snippet' => 'echo $a', - 'selected_text' => '$a', - 'from' => 201, - 'to' => 203, - 'snippet_from' => 196, - 'snippet_to' => 203, - 'column_from' => 6, - 'column_to' => 8, - 'error_level' => 3, - 'shortcode' => 126, - 'link' => 'https://psalm.dev/126' - ], - ], - \array_map( - function ($d) { - return (array) $d; - }, - $issue_data - ) - ); - } - /** * @return array */ diff --git a/tests/ReportOutputTest.php b/tests/ReportOutputTest.php index fa8236330..6f63aa19f 100644 --- a/tests/ReportOutputTest.php +++ b/tests/ReportOutputTest.php @@ -78,7 +78,7 @@ class ReportOutputTest extends TestCase { $file_contents = ' 3, 'line_to' => 3, 'type' => 'UndefinedVariable', - 'message' => 'Cannot find referenced variable $as_you', + 'message' => 'Cannot find referenced variable $as_you_____type', 'file_name' => 'somefile.php', 'file_path' => 'somefile.php', - 'snippet' => ' return $as_you . "type";', - 'selected_text' => '$as_you', + 'snippet' => ' return $as_you_____type;', + 'selected_text' => '$as_you_____type', 'from' => 66, - 'to' => 73, + 'to' => 82, 'snippet_from' => 57, 'snippet_to' => 83, 'column_from' => 10, - 'column_to' => 17, + 'column_to' => 26, 'error_level' => -1, 'shortcode' => 24, 'link' => 'https://psalm.dev/024' ], + [ + 'severity' => 'error', + 'line_from' => 3, + 'line_to' => 3, + 'type' => 'MixedReturnStatement', + 'message' => 'Could not infer a return type', + 'file_name' => 'somefile.php', + 'file_path' => 'somefile.php', + 'snippet' => ' return $as_you_____type;', + 'selected_text' => '$as_you_____type', + 'from' => 66, + 'to' => 82, + 'snippet_from' => 57, + 'snippet_to' => 83, + 'column_from' => 10, + 'column_to' => 26, + 'error_level' => 1, + 'shortcode' => 138, + 'link' => 'https://psalm.dev/138', + ], [ 'severity' => 'error', 'line_from' => 2, @@ -244,13 +264,29 @@ echo $a;'; 'engineId' => 'Psalm', 'ruleId' => 'UndefinedVariable', 'primaryLocation' => [ - 'message' => 'Cannot find referenced variable $as_you', + 'message' => 'Cannot find referenced variable $as_you_____type', 'filePath' => 'somefile.php', 'textRange' => [ 'startLine' => 3, 'endLine' => 3, 'startColumn' => 9, - 'endColumn' => 16, + 'endColumn' => 25, + ], + ], + 'type' => 'CODE_SMELL', + 'severity' => 'CRITICAL', + ], + [ + 'engineId' => 'Psalm', + 'ruleId' => 'MixedReturnStatement', + 'primaryLocation' => [ + 'message' => 'Could not infer a return type', + 'filePath' => 'somefile.php', + 'textRange' => [ + 'startLine' => 3, + 'endLine' => 3, + 'startColumn' => 9, + 'endColumn' => 25, ], ], 'type' => 'CODE_SMELL', @@ -326,7 +362,8 @@ echo $a;'; $emacs_report_options = ProjectAnalyzer::getFileReportOptions([__DIR__ . '/test-report.emacs'])[0]; $this->assertSame( - 'somefile.php:3:10:error - Cannot find referenced variable $as_you + 'somefile.php:3:10:error - Cannot find referenced variable $as_you_____type +somefile.php:3:10:error - Could not infer a return type somefile.php:2:42:error - Could not verify return type \'null|string\' for psalmCanVerify somefile.php:7:6:error - Const CHANGE_ME is not defined somefile.php:15:6:warning - Possibly undefined global variable $a, first seen on line 10 @@ -345,7 +382,8 @@ somefile.php:15:6:warning - Possibly undefined global variable $a, first seen on $pylint_report_options = ProjectAnalyzer::getFileReportOptions([__DIR__ . '/test-report.pylint'])[0]; $this->assertSame( - 'somefile.php:3: [E0001] UndefinedVariable: Cannot find referenced variable $as_you (column 10) + 'somefile.php:3: [E0001] UndefinedVariable: Cannot find referenced variable $as_you_____type (column 10) +somefile.php:3: [E0001] MixedReturnStatement: Could not infer a return type (column 10) somefile.php:2: [E0001] MixedInferredReturnType: Could not verify return type \'null|string\' for psalmCanVerify (column 42) somefile.php:7: [E0001] UndefinedConstant: Const CHANGE_ME is not defined (column 6) somefile.php:15: [W0001] PossiblyUndefinedGlobalVariable: Possibly undefined global variable $a, first seen on line 10 (column 6) @@ -365,8 +403,11 @@ somefile.php:15: [W0001] PossiblyUndefinedGlobalVariable: Possibly undefined glo $console_report_options->use_color = false; $this->assertSame( - 'ERROR: UndefinedVariable - somefile.php:3:10 - Cannot find referenced variable $as_you (see https://psalm.dev/024) - return $as_you . "type"; + 'ERROR: UndefinedVariable - somefile.php:3:10 - Cannot find referenced variable $as_you_____type (see https://psalm.dev/024) + return $as_you_____type; + +ERROR: MixedReturnStatement - somefile.php:3:10 - Could not infer a return type (see https://psalm.dev/138) + return $as_you_____type; ERROR: MixedInferredReturnType - somefile.php:2:42 - Could not verify return type \'null|string\' for psalmCanVerify (see https://psalm.dev/047) function psalmCanVerify(int $your_code): ?string { @@ -394,8 +435,11 @@ echo $a $console_report_options->show_info = false; $this->assertSame( - 'ERROR: UndefinedVariable - somefile.php:3:10 - Cannot find referenced variable $as_you (see https://psalm.dev/024) - return $as_you . "type"; + 'ERROR: UndefinedVariable - somefile.php:3:10 - Cannot find referenced variable $as_you_____type (see https://psalm.dev/024) + return $as_you_____type; + +ERROR: MixedReturnStatement - somefile.php:3:10 - Could not infer a return type (see https://psalm.dev/138) + return $as_you_____type; ERROR: MixedInferredReturnType - somefile.php:2:42 - Could not verify return type \'null|string\' for psalmCanVerify (see https://psalm.dev/047) function psalmCanVerify(int $your_code): ?string { @@ -420,7 +464,10 @@ echo CHANGE_ME; $console_report_options->use_color = false; $this->assertSame( - 'ERROR: UndefinedVariable - somefile.php:3:10 - Cannot find referenced variable $as_you (see https://psalm.dev/024) + 'ERROR: UndefinedVariable - somefile.php:3:10 - Cannot find referenced variable $as_you_____type (see https://psalm.dev/024) + + +ERROR: MixedReturnStatement - somefile.php:3:10 - Could not infer a return type (see https://psalm.dev/138) ERROR: MixedInferredReturnType - somefile.php:2:42 - Could not verify return type \'null|string\' for psalmCanVerify (see https://psalm.dev/047) @@ -454,7 +501,8 @@ INFO: PossiblyUndefinedGlobalVariable - somefile.php:15:6 - Possibly undefined g '+----------+------+---------------------------------+---------------------------------------------------------------+' . "\n" . '| SEVERITY | LINE | ISSUE | DESCRIPTION |' . "\n" . '+----------+------+---------------------------------+---------------------------------------------------------------+' . "\n" . - '| ERROR | 3 | UndefinedVariable | Cannot find referenced variable $as_you |' . "\n" . + '| ERROR | 3 | UndefinedVariable | Cannot find referenced variable $as_you_____type |' . "\n" . + '| ERROR | 3 | MixedReturnStatement | Could not infer a return type |' . "\n" . '| ERROR | 2 | MixedInferredReturnType | Could not verify return type \'null|string\' for psalmCanVerify |' . "\n" . '| ERROR | 7 | UndefinedConstant | Const CHANGE_ME is not defined |' . "\n" . '| INFO | 15 | PossiblyUndefinedGlobalVariable | Possibly undefined global variable $a, first seen on line 10 |' . "\n" . @@ -476,7 +524,10 @@ INFO: PossiblyUndefinedGlobalVariable - somefile.php:15:6 - Possibly undefined g ' - + + + + @@ -512,16 +563,26 @@ INFO: PossiblyUndefinedGlobalVariable - somefile.php:15:6 - Possibly undefined g $this->assertSame( ' - - + + - message: Cannot find referenced variable $as_you + message: Cannot find referenced variable $as_you_____type type: UndefinedVariable -snippet: return $as_you . "type"; -selected_text: $as_you +snippet: return $as_you_____type; +selected_text: $as_you_____type line: 3 column_from: 10 -column_to: 17 +column_to: 26 + + + + message: Could not infer a return type +type: MixedReturnStatement +snippet: return $as_you_____type; +selected_text: $as_you_____type +line: 3 +column_from: 10 +column_to: 26