From 6b6ec8c10506ac181018e6e8fe39a18d41f0d162 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Tue, 18 Oct 2016 23:09:51 +0200 Subject: [PATCH] Symbol test refactor (#92) * Don't use json_decode in symbol tests * Remove custom setUp() * Use getDefinitionLocation() * TextDocumentTestCase -> ServerTestCase * Refactor Workspace\SymbolTest --- src/Protocol/SymbolInformation.php | 14 + ...ocumentTestCase.php => ServerTestCase.php} | 60 ++-- .../Definition/GlobalFallbackTest.php | 4 +- .../TextDocument/Definition/GlobalTest.php | 4 +- .../TextDocument/DocumentSymbolTest.php | 215 +------------ .../References/GlobalFallbackTest.php | 4 +- .../TextDocument/References/GlobalTest.php | 4 +- tests/Server/Workspace/SymbolTest.php | 298 ++---------------- 8 files changed, 107 insertions(+), 496 deletions(-) rename tests/Server/{TextDocument/TextDocumentTestCase.php => ServerTestCase.php} (76%) diff --git a/src/Protocol/SymbolInformation.php b/src/Protocol/SymbolInformation.php index 19bffcd..ee88176 100644 --- a/src/Protocol/SymbolInformation.php +++ b/src/Protocol/SymbolInformation.php @@ -73,4 +73,18 @@ class SymbolInformation } return $symbol; } + + /** + * @param string $name + * @param int $kind + * @param Location $location + * @param string $containerName + */ + public function __construct($name = null, $kind = null, $location = null, $containerName = null) + { + $this->name = $name; + $this->kind = $kind; + $this->location = $location; + $this->containerName = $containerName; + } } diff --git a/tests/Server/TextDocument/TextDocumentTestCase.php b/tests/Server/ServerTestCase.php similarity index 76% rename from tests/Server/TextDocument/TextDocumentTestCase.php rename to tests/Server/ServerTestCase.php index 1733fea..bd8e7d8 100644 --- a/tests/Server/TextDocument/TextDocumentTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -1,7 +1,7 @@ project = new Project($client); $this->textDocument = new Server\TextDocument($this->project, $client); + $this->workspace = new Server\Workspace($this->project, $client); - $globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_symbols.php')); - $globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_references.php')); - $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php')); - $referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php')); - $useUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/use.php')); + $globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_symbols.php')); + $globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php')); + $symbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/symbols.php')); + $referencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php')); + $useUri = pathToUri(realpath(__DIR__ . '/../../fixtures/use.php')); $this->project->loadDocument($symbolsUri); $this->project->loadDocument($referencesUri); @@ -56,26 +62,30 @@ abstract class TextDocumentTestCase extends TestCase $this->definitionLocations = [ // Global - 'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 4, 6), new Position(4, 22))), - 'TestClass' => new Location($globalSymbolsUri, new Range(new Position( 6, 0), new Position(21, 1))), - 'TestInterface' => new Location($globalSymbolsUri, new Range(new Position(28, 0), new Position(31, 1))), - 'TestClass::TEST_CLASS_CONST' => new Location($globalSymbolsUri, new Range(new Position( 8, 10), new Position(8, 32))), - 'TestClass::testProperty' => new Location($globalSymbolsUri, new Range(new Position(10, 11), new Position(10, 24))), - 'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position( 9, 18), new Position(9, 37))), - 'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(12, 4), new Position(15, 5))), - 'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(17, 4), new Position(20, 5))), - 'test_function()' => new Location($globalSymbolsUri, new Range(new Position(33, 0), new Position(36, 1))), + 'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 4, 6), new Position(4, 22))), + 'TestClass' => new Location($globalSymbolsUri, new Range(new Position( 6, 0), new Position(21, 1))), + 'TestTrait' => new Location($globalSymbolsUri, new Range(new Position(23, 0), new Position(26, 1))), + 'TestInterface' => new Location($globalSymbolsUri, new Range(new Position(28, 0), new Position(31, 1))), + 'TestClass::TEST_CLASS_CONST' => new Location($globalSymbolsUri, new Range(new Position( 8, 10), new Position(8, 32))), + 'TestClass::testProperty' => new Location($globalSymbolsUri, new Range(new Position(10, 11), new Position(10, 24))), + 'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position( 9, 18), new Position(9, 37))), + 'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(12, 4), new Position(15, 5))), + 'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(17, 4), new Position(20, 5))), + 'test_function()' => new Location($globalSymbolsUri, new Range(new Position(33, 0), new Position(36, 1))), + 'whatever()' => new Location($globalReferencesUri, new Range(new Position(15, 0), new Position(17, 1))), // Namespaced - 'TestNamespace\\TEST_CONST' => new Location($symbolsUri, new Range(new Position( 4, 6), new Position(4, 22))), - 'TestNamespace\\TestClass' => new Location($symbolsUri, new Range(new Position( 6, 0), new Position(21, 1))), - 'TestNamespace\\TestInterface' => new Location($symbolsUri, new Range(new Position(28, 0), new Position(31, 1))), - 'TestNamespace\\TestClass::TEST_CLASS_CONST' => new Location($symbolsUri, new Range(new Position( 8, 10), new Position(8, 32))), - 'TestNamespace\\TestClass::testProperty' => new Location($symbolsUri, new Range(new Position(10, 11), new Position(10, 24))), - 'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position( 9, 18), new Position(9, 37))), - 'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(12, 4), new Position(15, 5))), - 'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(17, 4), new Position(20, 5))), - 'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(33, 0), new Position(36, 1))) + 'TestNamespace\\TEST_CONST' => new Location($symbolsUri, new Range(new Position( 4, 6), new Position(4, 22))), + 'TestNamespace\\TestClass' => new Location($symbolsUri, new Range(new Position( 6, 0), new Position(21, 1))), + 'TestNamespace\\TestInterface' => new Location($symbolsUri, new Range(new Position(28, 0), new Position(31, 1))), + 'TestNamespace\\TestTrait' => new Location($symbolsUri, new Range(new Position(23, 0), new Position(26, 1))), + 'TestNamespace\\TestClass::TEST_CLASS_CONST' => new Location($symbolsUri, new Range(new Position( 8, 10), new Position(8, 32))), + 'TestNamespace\\TestClass::testProperty' => new Location($symbolsUri, new Range(new Position(10, 11), new Position(10, 24))), + 'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position( 9, 18), new Position(9, 37))), + 'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(12, 4), new Position(15, 5))), + 'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(17, 4), new Position(20, 5))), + 'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(33, 0), new Position(36, 1))), + 'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(15, 0), new Position(17, 1))) ]; $this->referenceLocations = [ diff --git a/tests/Server/TextDocument/Definition/GlobalFallbackTest.php b/tests/Server/TextDocument/Definition/GlobalFallbackTest.php index 28a01e7..ef3fc9a 100644 --- a/tests/Server/TextDocument/Definition/GlobalFallbackTest.php +++ b/tests/Server/TextDocument/Definition/GlobalFallbackTest.php @@ -4,11 +4,11 @@ declare(strict_types = 1); namespace LanguageServer\Tests\Server\TextDocument\Definition; use LanguageServer\Tests\MockProtocolStream; -use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase; +use LanguageServer\Tests\Server\ServerTestCase; use LanguageServer\{Server, LanguageClient, Project}; use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location}; -class GlobalFallbackTest extends TextDocumentTestCase +class GlobalFallbackTest extends ServerTestCase { public function setUp() { diff --git a/tests/Server/TextDocument/Definition/GlobalTest.php b/tests/Server/TextDocument/Definition/GlobalTest.php index d2ce222..94f677a 100644 --- a/tests/Server/TextDocument/Definition/GlobalTest.php +++ b/tests/Server/TextDocument/Definition/GlobalTest.php @@ -3,11 +3,11 @@ declare(strict_types = 1); namespace LanguageServer\Tests\Server\TextDocument\Definition; -use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase; +use LanguageServer\Tests\Server\ServerTestCase; use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Location, Range}; use function LanguageServer\pathToUri; -class GlobalTest extends TextDocumentTestCase +class GlobalTest extends ServerTestCase { public function testDefinitionFileBeginning() { // |textDocument = new Server\TextDocument($project, $client); - $project->openDocument('symbols', file_get_contents(__DIR__ . '/../../../fixtures/symbols.php')); - } - public function test() { // Request symbols - $result = $this->textDocument->documentSymbol(new TextDocumentIdentifier('symbols')); + $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php')); + $result = $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri)); $this->assertEquals([ - [ - 'name' => 'TEST_CONST', - 'kind' => SymbolKind::CONSTANT, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 4, - 'character' => 6 - ], - 'end' => [ - 'line' => 4, - 'character' => 22 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'TestClass', - 'kind' => SymbolKind::CLASS_, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 6, - 'character' => 0 - ], - 'end' => [ - 'line' => 21, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'TEST_CLASS_CONST', - 'kind' => SymbolKind::CONSTANT, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 8, - 'character' => 10 - ], - 'end' => [ - 'line' => 8, - 'character' => 32 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'staticTestProperty', - 'kind' => SymbolKind::FIELD, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 9, - 'character' => 18 - ], - 'end' => [ - 'line' => 9, - 'character' => 37 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'testProperty', - 'kind' => SymbolKind::FIELD, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 10, - 'character' => 11 - ], - 'end' => [ - 'line' => 10, - 'character' => 24 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'staticTestMethod', - 'kind' => SymbolKind::METHOD, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 12, - 'character' => 4 - ], - 'end' => [ - 'line' => 15, - 'character' => 5 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'testMethod', - 'kind' => SymbolKind::METHOD, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 17, - 'character' => 4 - ], - 'end' => [ - 'line' => 20, - 'character' => 5 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'TestTrait', - 'kind' => SymbolKind::CLASS_, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 23, - 'character' => 0 - ], - 'end' => [ - 'line' => 26, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'TestInterface', - 'kind' => SymbolKind::INTERFACE, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 28, - 'character' => 0 - ], - 'end' => [ - 'line' => 31, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'test_function', - 'kind' => SymbolKind::FUNCTION, - 'location' => [ - 'uri' => 'symbols', - 'range' => [ - 'start' => [ - 'line' => 33, - 'character' => 0 - ], - 'end' => [ - 'line' => 36, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ] - ], json_decode(json_encode($result), true)); + new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'), + new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'), + new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'), + new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'), + new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'), + new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'), + new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'), + new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'), + new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'), + new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'), + ], $result); } } diff --git a/tests/Server/TextDocument/References/GlobalFallbackTest.php b/tests/Server/TextDocument/References/GlobalFallbackTest.php index 5ad5442..9511064 100644 --- a/tests/Server/TextDocument/References/GlobalFallbackTest.php +++ b/tests/Server/TextDocument/References/GlobalFallbackTest.php @@ -7,9 +7,9 @@ use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, LanguageClient, Project}; use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range}; -use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase; +use LanguageServer\Tests\Server\ServerTestCase; -class GlobalFallbackTest extends TextDocumentTestCase +class GlobalFallbackTest extends ServerTestCase { public function setUp() { diff --git a/tests/Server/TextDocument/References/GlobalTest.php b/tests/Server/TextDocument/References/GlobalTest.php index ea09266..563d17e 100644 --- a/tests/Server/TextDocument/References/GlobalTest.php +++ b/tests/Server/TextDocument/References/GlobalTest.php @@ -4,10 +4,10 @@ declare(strict_types = 1); namespace LanguageServer\Tests\Server\TextDocument\References; use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range}; -use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase; +use LanguageServer\Tests\Server\ServerTestCase; use function LanguageServer\pathToUri; -class GlobalTest extends TextDocumentTestCase +class GlobalTest extends ServerTestCase { public function testReferencesForClassLike() { diff --git a/tests/Server/Workspace/SymbolTest.php b/tests/Server/Workspace/SymbolTest.php index 49d0cc0..90b6090 100644 --- a/tests/Server/Workspace/SymbolTest.php +++ b/tests/Server/Workspace/SymbolTest.php @@ -3,245 +3,45 @@ declare(strict_types = 1); namespace LanguageServer\Tests\Server\Workspace; -use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; +use LanguageServer\Tests\Server\ServerTestCase; use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument}; -use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, SymbolKind, DiagnosticSeverity, FormattingOptions}; +use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, SymbolInformation, SymbolKind, DiagnosticSeverity, FormattingOptions}; use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody}; use function LanguageServer\pathToUri; -class SymbolTest extends TestCase +class SymbolTest extends ServerTestCase { - /** - * @var LanguageServer\Workspace $workspace - */ - private $workspace; - - /** - * @var string - */ - private $symbolsUri; - - /** - * @var string - */ - private $referencesUri; - - public function setUp() - { - $client = new LanguageClient(new MockProtocolStream()); - $project = new Project($client); - $this->workspace = new Server\Workspace($project, $client); - $this->symbolsUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php')); - $this->referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php')); - $project->loadDocument($this->symbolsUri); - $project->loadDocument($this->referencesUri); - } - public function testEmptyQueryReturnsAllSymbols() { // Request symbols $result = $this->workspace->symbol(''); $this->assertEquals([ - [ - 'name' => 'TEST_CONST', - 'kind' => SymbolKind::CONSTANT, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 4, - 'character' => 6 - ], - 'end' => [ - 'line' => 4, - 'character' => 22 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'TestClass', - 'kind' => SymbolKind::CLASS_, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 6, - 'character' => 0 - ], - 'end' => [ - 'line' => 21, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'TEST_CLASS_CONST', - 'kind' => SymbolKind::CONSTANT, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 8, - 'character' => 10 - ], - 'end' => [ - 'line' => 8, - 'character' => 32 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'staticTestProperty', - 'kind' => SymbolKind::FIELD, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 9, - 'character' => 18 - ], - 'end' => [ - 'line' => 9, - 'character' => 37 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'testProperty', - 'kind' => SymbolKind::FIELD, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 10, - 'character' => 11 - ], - 'end' => [ - 'line' => 10, - 'character' => 24 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'staticTestMethod', - 'kind' => SymbolKind::METHOD, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 12, - 'character' => 4 - ], - 'end' => [ - 'line' => 15, - 'character' => 5 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'testMethod', - 'kind' => SymbolKind::METHOD, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 17, - 'character' => 4 - ], - 'end' => [ - 'line' => 20, - 'character' => 5 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'TestTrait', - 'kind' => SymbolKind::CLASS_, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 23, - 'character' => 0 - ], - 'end' => [ - 'line' => 26, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'TestInterface', - 'kind' => SymbolKind::INTERFACE, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 28, - 'character' => 0 - ], - 'end' => [ - 'line' => 31, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'test_function', - 'kind' => SymbolKind::FUNCTION, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 33, - 'character' => 0 - ], - 'end' => [ - 'line' => 36, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ], - [ - 'name' => 'whatever', - 'kind' => SymbolKind::FUNCTION, - 'location' => [ - 'uri' => $this->referencesUri, - 'range' => [ - 'start' => [ - 'line' => 15, - 'character' => 0 - ], - 'end' => [ - 'line' => 17, - 'character' => 1 - ] - ] - ], - 'containerName' => 'TestNamespace' - ] - ], json_decode(json_encode($result), true)); + // Namespaced + new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'), + new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'), + new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'), + new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'), + new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'), + new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'), + new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'), + new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'), + new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'), + new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'), + new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\whatever()'), 'TestNamespace'), + // Global + new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_CONST'), ''), + new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestClass'), ''), + new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), 'TestClass'), + new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestClass::staticTestProperty'), 'TestClass'), + new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestClass::testProperty'), 'TestClass'), + new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'), + new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass'), + new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestTrait'), ''), + new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''), + new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''), + new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), '') + ], $result); } public function testQueryFiltersResults() @@ -249,42 +49,10 @@ class SymbolTest extends TestCase // Request symbols $result = $this->workspace->symbol('testmethod'); $this->assertEquals([ - [ - 'name' => 'staticTestMethod', - 'kind' => SymbolKind::METHOD, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 12, - 'character' => 4 - ], - 'end' => [ - 'line' => 15, - 'character' => 5 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ], - [ - 'name' => 'testMethod', - 'kind' => SymbolKind::METHOD, - 'location' => [ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 17, - 'character' => 4 - ], - 'end' => [ - 'line' => 20, - 'character' => 5 - ] - ] - ], - 'containerName' => 'TestNamespace\\TestClass' - ] - ], json_decode(json_encode($result), true)); + new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'), + new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'), + new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'), + new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass') + ], $result); } }