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;
/**
* @var Server\Workspace
*/
protected $workspace;
/**
* @var Project
*/
@ -40,6 +45,7 @@ abstract class ServerTestCase extends TestCase
$client = new LanguageClient(new MockProtocolStream());
$this->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'));
@ -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::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))),
@ -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::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_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 = [

View File

@ -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);
}
}