Symbol test refactor (#92)
* Don't use json_decode in symbol tests * Remove custom setUp() * Use getDefinitionLocation() * TextDocumentTestCase -> ServerTestCase * Refactor Workspace\SymbolTestpull/93/head
parent
cdcfaf7849
commit
6b6ec8c105
|
@ -73,4 +73,18 @@ class SymbolInformation
|
||||||
}
|
}
|
||||||
return $symbol;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
@ -9,13 +9,18 @@ use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{Position, Location, Range};
|
use LanguageServer\Protocol\{Position, Location, Range};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
abstract class TextDocumentTestCase extends TestCase
|
abstract class ServerTestCase extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Server\TextDocument
|
* @var Server\TextDocument
|
||||||
*/
|
*/
|
||||||
protected $textDocument;
|
protected $textDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Server\Workspace
|
||||||
|
*/
|
||||||
|
protected $workspace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Project
|
* @var Project
|
||||||
*/
|
*/
|
||||||
|
@ -40,12 +45,13 @@ abstract class TextDocumentTestCase 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'));
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/symbols.php'));
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php'));
|
||||||
$useUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/use.php'));
|
$useUri = pathToUri(realpath(__DIR__ . '/../../fixtures/use.php'));
|
||||||
|
|
||||||
$this->project->loadDocument($symbolsUri);
|
$this->project->loadDocument($symbolsUri);
|
||||||
$this->project->loadDocument($referencesUri);
|
$this->project->loadDocument($referencesUri);
|
||||||
|
@ -56,26 +62,30 @@ abstract class TextDocumentTestCase extends TestCase
|
||||||
$this->definitionLocations = [
|
$this->definitionLocations = [
|
||||||
|
|
||||||
// Global
|
// Global
|
||||||
'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 4, 6), new Position(4, 22))),
|
'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))),
|
'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))),
|
'TestTrait' => new Location($globalSymbolsUri, new Range(new Position(23, 0), new Position(26, 1))),
|
||||||
'TestClass::TEST_CLASS_CONST' => new Location($globalSymbolsUri, new Range(new Position( 8, 10), new Position(8, 32))),
|
'TestInterface' => new Location($globalSymbolsUri, new Range(new Position(28, 0), new Position(31, 1))),
|
||||||
'TestClass::testProperty' => new Location($globalSymbolsUri, new Range(new Position(10, 11), new Position(10, 24))),
|
'TestClass::TEST_CLASS_CONST' => new Location($globalSymbolsUri, new Range(new Position( 8, 10), new Position(8, 32))),
|
||||||
'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position( 9, 18), new Position(9, 37))),
|
'TestClass::testProperty' => new Location($globalSymbolsUri, new Range(new Position(10, 11), new Position(10, 24))),
|
||||||
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(12, 4), new Position(15, 5))),
|
'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position( 9, 18), new Position(9, 37))),
|
||||||
'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(17, 4), new Position(20, 5))),
|
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(12, 4), new Position(15, 5))),
|
||||||
'test_function()' => new Location($globalSymbolsUri, new Range(new Position(33, 0), new Position(36, 1))),
|
'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
|
// 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))),
|
||||||
'TestNamespace\\TestClass' => new Location($symbolsUri, new Range(new Position( 6, 0), new Position(21, 1))),
|
'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\\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\\TestTrait' => new Location($symbolsUri, new Range(new Position(23, 0), new Position(26, 1))),
|
||||||
'TestNamespace\\TestClass::testProperty' => new Location($symbolsUri, new Range(new Position(10, 11), new Position(10, 24))),
|
'TestNamespace\\TestClass::TEST_CLASS_CONST' => new Location($symbolsUri, new Range(new Position( 8, 10), new Position(8, 32))),
|
||||||
'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position( 9, 18), new Position(9, 37))),
|
'TestNamespace\\TestClass::testProperty' => new Location($symbolsUri, new Range(new Position(10, 11), new Position(10, 24))),
|
||||||
'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(12, 4), new Position(15, 5))),
|
'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position( 9, 18), new Position(9, 37))),
|
||||||
'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(17, 4), new Position(20, 5))),
|
'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(12, 4), new Position(15, 5))),
|
||||||
'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(33, 0), new Position(36, 1)))
|
'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 = [
|
$this->referenceLocations = [
|
|
@ -4,11 +4,11 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location};
|
||||||
|
|
||||||
class GlobalFallbackTest extends TextDocumentTestCase
|
class GlobalFallbackTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,11 +3,11 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
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 LanguageServer\Protocol\{TextDocumentIdentifier, Position, Location, Range};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class GlobalTest extends TextDocumentTestCase
|
class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testDefinitionFileBeginning() {
|
public function testDefinitionFileBeginning() {
|
||||||
// |<?php
|
// |<?php
|
||||||
|
|
|
@ -3,211 +3,30 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, SymbolKind};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, SymbolInformation, SymbolKind, Position, Location, Range};
|
||||||
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class DocumentSymbolTest extends TestCase
|
class DocumentSymbolTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var Server\TextDocument
|
|
||||||
*/
|
|
||||||
private $textDocument;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
|
||||||
$project = new Project($client);
|
|
||||||
$this->textDocument = new Server\TextDocument($project, $client);
|
|
||||||
$project->openDocument('symbols', file_get_contents(__DIR__ . '/../../../fixtures/symbols.php'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test()
|
public function test()
|
||||||
{
|
{
|
||||||
// Request symbols
|
// 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([
|
$this->assertEquals([
|
||||||
[
|
new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
|
||||||
'name' => 'TEST_CONST',
|
new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'),
|
||||||
'kind' => SymbolKind::CONSTANT,
|
new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'),
|
||||||
'location' => [
|
new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
|
||||||
'uri' => 'symbols',
|
new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'),
|
||||||
'range' => [
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'start' => [
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'line' => 4,
|
new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'),
|
||||||
'character' => 6
|
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'),
|
||||||
],
|
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'),
|
||||||
'end' => [
|
], $result);
|
||||||
'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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@ use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
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()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,10 +4,10 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\References;
|
namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
|
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
||||||
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class GlobalTest extends TextDocumentTestCase
|
class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testReferencesForClassLike()
|
public function testReferencesForClassLike()
|
||||||
{
|
{
|
||||||
|
|
|
@ -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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue