1
0
Fork 0

Refactor Workspace\SymbolTest

pull/92/head
Felix Becker 2016-10-18 23:00:51 +02:00
parent 61f25c0bdb
commit 5d3ddcaa18
2 changed files with 61 additions and 285 deletions

View File

@ -16,6 +16,11 @@ abstract class ServerTestCase extends TestCase
*/ */
protected $textDocument; protected $textDocument;
/**
* @var Server\Workspace
*/
protected $workspace;
/** /**
* @var Project * @var Project
*/ */
@ -40,6 +45,7 @@ abstract class ServerTestCase extends TestCase
$client = new LanguageClient(new MockProtocolStream()); $client = new LanguageClient(new MockProtocolStream());
$this->project = new Project($client); $this->project = new Project($client);
$this->textDocument = new Server\TextDocument($this->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')); $globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_symbols.php'));
$globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php')); $globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php'));
@ -66,6 +72,7 @@ abstract class ServerTestCase extends TestCase
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(12, 4), new Position(15, 5))), '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))), '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_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 // Namespaced
'TestNamespace\\TEST_CONST' => new Location($symbolsUri, new Range(new Position( 4, 6), new Position(4, 22))), 'TestNamespace\\TEST_CONST' => new Location($symbolsUri, new Range(new Position( 4, 6), new Position(4, 22))),
@ -77,7 +84,8 @@ abstract class ServerTestCase extends TestCase
'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position( 9, 18), new Position(9, 37))), '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::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\\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_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 = [ $this->referenceLocations = [

View File

@ -3,245 +3,45 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server\Workspace; namespace LanguageServer\Tests\Server\Workspace;
use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument}; 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 AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
use function LanguageServer\pathToUri; 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() public function testEmptyQueryReturnsAllSymbols()
{ {
// Request symbols // Request symbols
$result = $this->workspace->symbol(''); $result = $this->workspace->symbol('');
$this->assertEquals([ $this->assertEquals([
[ // Namespaced
'name' => 'TEST_CONST', new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
'kind' => SymbolKind::CONSTANT, new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'),
'location' => [ new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'),
'uri' => $this->symbolsUri, new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
'range' => [ new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'),
'start' => [ new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
'line' => 4, new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
'character' => 6 new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'),
], new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'),
'end' => [ new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'),
'line' => 4, new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\whatever()'), 'TestNamespace'),
'character' => 22 // 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'),
'containerName' => 'TestNamespace' 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'),
'name' => 'TestClass', new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass'),
'kind' => SymbolKind::CLASS_, new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestTrait'), ''),
'location' => [ new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''),
'uri' => $this->symbolsUri, new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''),
'range' => [ new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), '')
'start' => [ ], $result);
'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));
} }
public function testQueryFiltersResults() public function testQueryFiltersResults()
@ -249,42 +49,10 @@ class SymbolTest extends TestCase
// Request symbols // Request symbols
$result = $this->workspace->symbol('testmethod'); $result = $this->workspace->symbol('testmethod');
$this->assertEquals([ $this->assertEquals([
[ new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
'name' => 'staticTestMethod', new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
'kind' => SymbolKind::METHOD, new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'),
'location' => [ new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass')
'uri' => $this->symbolsUri, ], $result);
'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));
} }
} }