From b9791d24dc402b0d26e2cf70506986d3cf1551d4 Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Tue, 20 Dec 2022 21:09:34 +0000 Subject: [PATCH] fix some tests --- tests/LanguageServer/CompletionTest.php | 7 ++- tests/LanguageServer/DiagnosticTest.php | 49 ++++++++---------- tests/LanguageServer/FileMapTest.php | 7 ++- tests/LanguageServer/MockProtocolStream.php | 1 - tests/LanguageServer/SymbolLookupTest.php | 57 ++++++++++----------- 5 files changed, 54 insertions(+), 67 deletions(-) diff --git a/tests/LanguageServer/CompletionTest.php b/tests/LanguageServer/CompletionTest.php index 055876da2..290562509 100644 --- a/tests/LanguageServer/CompletionTest.php +++ b/tests/LanguageServer/CompletionTest.php @@ -3,9 +3,9 @@ namespace Psalm\Tests\LanguageServer; use LanguageServerProtocol\Position; +use Psalm\Codebase; use Psalm\Context; use Psalm\Internal\Analyzer\ProjectAnalyzer; -use Psalm\Internal\LanguageServer\Codebase; use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; use Psalm\Tests\Internal\Provider\FakeFileReferenceCacheProvider; @@ -19,8 +19,7 @@ use function count; class CompletionTest extends TestCase { - /** @var Codebase */ - protected $codebase; + protected Codebase $codebase; public function setUp(): void { @@ -48,7 +47,7 @@ class CompletionTest extends TestCase [], 1, null, - $this->codebase + $this->codebase, ); $this->project_analyzer->setPhpVersion('7.3', 'tests'); diff --git a/tests/LanguageServer/DiagnosticTest.php b/tests/LanguageServer/DiagnosticTest.php index f449b2452..e93191057 100644 --- a/tests/LanguageServer/DiagnosticTest.php +++ b/tests/LanguageServer/DiagnosticTest.php @@ -3,10 +3,10 @@ namespace Psalm\Tests\LanguageServer; use Amp\Deferred; +use Psalm\Codebase; use Psalm\Internal\Analyzer\IssueData; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\LanguageServer\ClientConfiguration; -use Psalm\Internal\LanguageServer\Codebase; use Psalm\Internal\LanguageServer\LanguageServer; use Psalm\Internal\LanguageServer\Message; use Psalm\Internal\LanguageServer\Progress; @@ -26,20 +26,11 @@ use function rand; class DiagnosticTest extends AsyncTestCase { - /** @var Codebase */ - protected $codebase; - - /** @var int */ - private $increment = 0; - - /** @var ProjectAnalyzer */ - protected $project_analyzer; - - /** @var FakeFileProvider */ - protected $file_provider; - - /** @var string */ - protected static $src_dir_path; + protected Codebase $codebase; + private int $increment = 0; + protected ProjectAnalyzer $project_analyzer; + protected FakeFileProvider $file_provider; + protected static string $src_dir_path; public function setUp(): void { @@ -67,7 +58,7 @@ class DiagnosticTest extends AsyncTestCase [], 1, null, - $this->codebase + $this->codebase, ); $this->project_analyzer->setPhpVersion('7.4', 'tests'); @@ -96,7 +87,7 @@ class DiagnosticTest extends AsyncTestCase $this->project_analyzer, $this->codebase, $clientConfiguration, - new Progress + new Progress, ); $write->on('message', function (Message $message) use ($deferred, $server): void { @@ -120,7 +111,7 @@ class DiagnosticTest extends AsyncTestCase $this->addFile( 'somefile.php', - '' + '', ); $issues = $this->changeFile( @@ -131,7 +122,7 @@ class DiagnosticTest extends AsyncTestCase public function __construct() { } - }' + }', ); $this->assertEmpty($issues); @@ -145,7 +136,7 @@ class DiagnosticTest extends AsyncTestCase { strpos("", ""); } - }' + }', ); $this->assertArrayHasKey('somefile.php', $issues); @@ -164,7 +155,7 @@ class DiagnosticTest extends AsyncTestCase } public function foobar(): void {} - }' + }', ); $this->assertArrayHasKey('somefile.php', $issues); @@ -187,7 +178,7 @@ class DiagnosticTest extends AsyncTestCase } public function foobar(): void {} - }' + }', ); $this->assertArrayHasKey('somefile.php', $issues); @@ -208,7 +199,7 @@ class DiagnosticTest extends AsyncTestCase } public function foobar(): void {} - }' + }', ); $this->assertArrayHasKey('somefile.php', $issues); @@ -226,7 +217,7 @@ class DiagnosticTest extends AsyncTestCase } public function foobar(): void {} - }' + }', ); $this->assertArrayHasKey('somefile.php', $issues); @@ -247,7 +238,7 @@ class DiagnosticTest extends AsyncTestCase } public function foobar(): void {} - }' + }', ); $this->assertEmpty($issues); @@ -261,15 +252,15 @@ class DiagnosticTest extends AsyncTestCase $this->codebase->addTemporaryFileChanges( $file_path, $contents, - $this->increment + $this->increment, ); $this->codebase->reloadFiles( $this->project_analyzer, - [$file_path] + [$file_path], ); $this->codebase->analyzer->addFilesToAnalyze( - [$file_path => $file_path] + [$file_path => $file_path], ); $this->codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false); @@ -669,7 +660,7 @@ class DiagnosticTest extends AsyncTestCase ], ], 'trace' => 'off', - ] + ], ]; } } diff --git a/tests/LanguageServer/FileMapTest.php b/tests/LanguageServer/FileMapTest.php index 9568c3f4b..e17b19be5 100644 --- a/tests/LanguageServer/FileMapTest.php +++ b/tests/LanguageServer/FileMapTest.php @@ -2,9 +2,9 @@ namespace Psalm\Tests\LanguageServer; +use Psalm\Codebase; use Psalm\Context; use Psalm\Internal\Analyzer\ProjectAnalyzer; -use Psalm\Internal\LanguageServer\Codebase; use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; use Psalm\Tests\Internal\Provider\FakeFileReferenceCacheProvider; @@ -17,8 +17,7 @@ use function count; class FileMapTest extends TestCase { - /** @var Codebase */ - protected $codebase; + protected Codebase $codebase; public function setUp(): void { @@ -46,7 +45,7 @@ class FileMapTest extends TestCase [], 1, null, - $this->codebase + $this->codebase, ); $this->project_analyzer->setPhpVersion('7.3', 'tests'); diff --git a/tests/LanguageServer/MockProtocolStream.php b/tests/LanguageServer/MockProtocolStream.php index 084e47f03..34f8072c9 100644 --- a/tests/LanguageServer/MockProtocolStream.php +++ b/tests/LanguageServer/MockProtocolStream.php @@ -22,7 +22,6 @@ class MockProtocolStream implements ProtocolReader, ProtocolWriter, EmitterInter /** * Sends a Message to the client * - * @param Message $msg * @psalm-suppress PossiblyUnusedReturnValue */ public function write(Message $msg): Promise diff --git a/tests/LanguageServer/SymbolLookupTest.php b/tests/LanguageServer/SymbolLookupTest.php index e854ce6ca..aace1a15f 100644 --- a/tests/LanguageServer/SymbolLookupTest.php +++ b/tests/LanguageServer/SymbolLookupTest.php @@ -4,10 +4,10 @@ namespace Psalm\Tests\LanguageServer; use LanguageServerProtocol\Position; use LanguageServerProtocol\Range; +use Psalm\Codebase; use Psalm\Context; use Psalm\Internal\Analyzer\FileAnalyzer; use Psalm\Internal\Analyzer\ProjectAnalyzer; -use Psalm\Internal\LanguageServer\Codebase; use Psalm\Internal\LanguageServer\Reference; use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; @@ -19,8 +19,7 @@ use Psalm\Tests\TestConfig; class SymbolLookupTest extends TestCase { - /** @var Codebase */ - protected $codebase; + protected Codebase $codebase; public function setUp(): void { @@ -48,7 +47,7 @@ class SymbolLookupTest extends TestCase [], 1, null, - $this->codebase + $this->codebase, ); $this->project_analyzer->setPhpVersion('7.3', 'tests'); @@ -103,8 +102,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'B\A::foo()', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame("public function foo(): void", $information->code); @@ -115,8 +114,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'B\A::$a', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame('protected int|null $a', $information->code); @@ -127,8 +126,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'B\bar()', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame('function B\bar(): int', $information->code); @@ -139,8 +138,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'B\A::BANANA', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame('public const BANANA = 🍌;', $information->code); @@ -151,8 +150,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'B\baz()', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame("function B\baz(\n int \$a\n): int", $information->code); @@ -163,8 +162,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'B\qux()', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame("function B\qux(\n int \$a,\n int \$b\n): int", $information->code); @@ -175,8 +174,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', '$_SESSION', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame("array", $information->code); @@ -187,8 +186,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', '$my_global', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame("string", $information->code); @@ -215,8 +214,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'APPLE', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame("const APPLE string", $information->code); @@ -227,8 +226,8 @@ class SymbolLookupTest extends TestCase new Reference( 'somefile.php', 'BANANA', - $range - ) + $range, + ), ); $this->assertNotNull($information); $this->assertSame("const BANANA string", $information->code); @@ -270,7 +269,7 @@ class SymbolLookupTest extends TestCase $method_symbol_location = $this->codebase->getSymbolLocation(new Reference( 'somefile.php', 'B\A::foo()', - $range + $range, )); $this->assertNotNull($method_symbol_location); @@ -280,7 +279,7 @@ class SymbolLookupTest extends TestCase $property_symbol_location = $this->codebase->getSymbolLocation(new Reference( 'somefile.php', 'B\A::$a', - $range + $range, )); $this->assertNotNull($property_symbol_location); @@ -290,7 +289,7 @@ class SymbolLookupTest extends TestCase $constant_symbol_location = $this->codebase->getSymbolLocation(new Reference( 'somefile.php', 'B\A::BANANA', - $range + $range, )); $this->assertNotNull($constant_symbol_location); @@ -300,7 +299,7 @@ class SymbolLookupTest extends TestCase $function_symbol_location = $this->codebase->getSymbolLocation(new Reference( 'somefile.php', 'B\bar()', - $range + $range, )); $this->assertNotNull($function_symbol_location); @@ -310,7 +309,7 @@ class SymbolLookupTest extends TestCase $function_symbol_location = $this->codebase->getSymbolLocation(new Reference( 'somefile.php', '257-259', - $range + $range, )); $this->assertNotNull($function_symbol_location);