Refactor tests for easier changes to fixtures
parent
cba4357856
commit
898c586765
|
@ -3,380 +3,174 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Location, Range};
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use function LanguageServer\pathToUri;
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position};
|
|
||||||
|
|
||||||
class GlobalTest extends TestCase
|
class GlobalTest extends TextDocumentTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @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('references', file_get_contents(__DIR__ . '/../../../../fixtures/global_references.php'));
|
|
||||||
$project->openDocument('symbols', file_get_contents(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
|
||||||
// Load this to check that there are no conflicts
|
|
||||||
$project->openDocument('references_namespaced', file_get_contents(__DIR__ . '/../../../../fixtures/references.php'));
|
|
||||||
$project->openDocument('symbols_namespaced', file_get_contents(__DIR__ . '/../../../../fixtures/symbols.php'));
|
|
||||||
$project->openDocument('use', file_get_contents(__DIR__ . '/../../../../fixtures/use.php'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionFileBeginning() {
|
public function testDefinitionFileBeginning() {
|
||||||
// |<?php
|
// |<?php
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(0, 0));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(0, 0));
|
||||||
$this->assertEquals([], json_decode(json_encode($result), true));
|
$this->assertEquals([], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionEmptyResult() {
|
public function testDefinitionEmptyResult() {
|
||||||
// namespace keyword
|
// namespace keyword
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(2, 4));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(2, 4));
|
||||||
$this->assertEquals([], json_decode(json_encode($result), true));
|
$this->assertEquals([], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassLike()
|
public function testDefinitionForClassLike()
|
||||||
{
|
{
|
||||||
// $obj = new TestClass();
|
// $obj = new TestClass();
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(4, 16));
|
$reference = $this->getReferenceLocations('TestClass')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testDefinitionForClassOnStaticMethodCall()
|
public function testDefinitionForClassOnStaticMethodCall()
|
||||||
{
|
{
|
||||||
// $obj = new TestClass();
|
// $obj = new TestClass();
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(7, 6));
|
$reference = $this->getReferenceLocations('TestClass')[1];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassOnStaticPropertyFetch()
|
public function testDefinitionForClassOnStaticPropertyFetch()
|
||||||
{
|
{
|
||||||
// $obj = new TestClass();
|
// echo TestClass::$staticTestProperty;
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(8, 10));
|
$reference = $this->getReferenceLocations('TestClass')[2];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassOnConstFetch()
|
public function testDefinitionForClassOnConstFetch()
|
||||||
{
|
{
|
||||||
// $obj = new TestClass();
|
// TestClass::TEST_CLASS_CONST;
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(9, 10));
|
$reference = $this->getReferenceLocations('TestClass')[3];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForImplements()
|
public function testDefinitionForImplements()
|
||||||
{
|
{
|
||||||
// class TestClass implements TestInterface
|
// class TestClass implements TestInterface
|
||||||
// Get definition for TestInterface
|
// Get definition for TestInterface
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('symbols'), new Position(6, 33));
|
$reference = $this->getReferenceLocations('TestInterface')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 28,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 31,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassConstants()
|
public function testDefinitionForClassConstants()
|
||||||
{
|
{
|
||||||
// echo TestClass::TEST_CLASS_CONST;
|
// echo TestClass::TEST_CLASS_CONST;
|
||||||
// Get definition for TEST_CLASS_CONST
|
// Get definition for TEST_CLASS_CONST
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(9, 21));
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 10
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 32
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForConstants()
|
public function testDefinitionForConstants()
|
||||||
{
|
{
|
||||||
// echo TEST_CONST;
|
// echo TEST_CONST;
|
||||||
// Get definition for TEST_CONST
|
// Get definition for TEST_CONST
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(23, 9));
|
$reference = $this->getReferenceLocations('TEST_CONST')[1];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 6
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 22
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForStaticMethods()
|
public function testDefinitionForStaticMethods()
|
||||||
{
|
{
|
||||||
// TestClass::staticTestMethod();
|
// TestClass::staticTestMethod();
|
||||||
// Get definition for staticTestMethod
|
// Get definition for staticTestMethod
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(7, 20));
|
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestMethod()'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForStaticProperties()
|
public function testDefinitionForStaticProperties()
|
||||||
{
|
{
|
||||||
// echo TestClass::$staticTestProperty;
|
// echo TestClass::$staticTestProperty;
|
||||||
// Get definition for staticTestProperty
|
// Get definition for staticTestProperty
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(8, 25));
|
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestProperty'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 37
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForMethods()
|
public function testDefinitionForMethods()
|
||||||
{
|
{
|
||||||
// $obj->testMethod();
|
// $obj->testMethod();
|
||||||
// Get definition for testMethod
|
// Get definition for testMethod
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(5, 11));
|
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 17,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForProperties()
|
public function testDefinitionForProperties()
|
||||||
{
|
{
|
||||||
// echo $obj->testProperty;
|
// echo $obj->testProperty;
|
||||||
// Get definition for testProperty
|
// Get definition for testProperty
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(6, 18));
|
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 11
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 24
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForVariables()
|
public function testDefinitionForVariables()
|
||||||
{
|
{
|
||||||
// echo $var;
|
// echo $var;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(13, 7));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(13, 7));
|
||||||
'uri' => 'references',
|
$this->assertEquals(new Location($uri, new Range(new Position(12, 0), new Position(12, 10))), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 10
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForParamTypeHints()
|
public function testDefinitionForParamTypeHints()
|
||||||
{
|
{
|
||||||
// function whatever(TestClass $param) {
|
// function whatever(TestClass $param) {
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(15, 23));
|
$reference = $this->getReferenceLocations('TestClass')[4];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForReturnTypeHints()
|
public function testDefinitionForReturnTypeHints()
|
||||||
{
|
{
|
||||||
// function whatever(TestClass $param) {
|
// function whatever(TestClass $param): TestClass {
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(15, 42));
|
$reference = $this->getReferenceLocations('TestClass')[5];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForParams()
|
public function testDefinitionForParams()
|
||||||
{
|
{
|
||||||
// echo $param;
|
// echo $param;
|
||||||
// Get definition for $param
|
// Get definition for $param
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(16, 13));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(16, 13));
|
||||||
'uri' => 'references',
|
$this->assertEquals(new Location($uri, new Range(new Position(15, 18), new Position(15, 34))), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 34
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForUsedVariables()
|
public function testDefinitionForUsedVariables()
|
||||||
{
|
{
|
||||||
// echo $var;
|
// echo $var;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(20, 11));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(20, 11));
|
||||||
'uri' => 'references',
|
$this->assertEquals(new Location($uri, new Range(new Position(19, 22), new Position(19, 26))), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 19,
|
|
||||||
'character' => 22
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 19,
|
|
||||||
'character' => 26
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForFunctions()
|
public function testDefinitionForFunctions()
|
||||||
{
|
{
|
||||||
// test_function();
|
// test_function();
|
||||||
// Get definition for test_function
|
// Get definition for test_function
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(10, 4));
|
$reference = $this->getReferenceLocations('test_function()')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 33,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 36,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,417 +3,45 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Location};
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position};
|
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class NamespacedTest extends TestCase
|
class NamespacedTest extends GlobalTest
|
||||||
{
|
{
|
||||||
/**
|
public function getReferenceLocations(string $fqn): array
|
||||||
* @var Server\TextDocument
|
|
||||||
*/
|
|
||||||
private $textDocument;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
{
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
return parent::getReferenceLocations('TestNamespace\\' . $fqn);
|
||||||
$project = new Project($client);
|
|
||||||
$this->textDocument = new Server\TextDocument($project, $client);
|
|
||||||
$project->openDocument('references', file_get_contents(__DIR__ . '/../../../../fixtures/references.php'));
|
|
||||||
$project->openDocument('symbols', file_get_contents(__DIR__ . '/../../../../fixtures/symbols.php'));
|
|
||||||
$project->openDocument('use', file_get_contents(__DIR__ . '/../../../../fixtures/use.php'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionFileBeginning() {
|
public function getDefinitionLocation(string $fqn): Location
|
||||||
// |<?php
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(0, 0));
|
|
||||||
$this->assertEquals([], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionEmptyResult() {
|
|
||||||
// namespace keyword
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(2, 4));
|
|
||||||
$this->assertEquals([], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForClassLike()
|
|
||||||
{
|
{
|
||||||
// $obj = new TestClass();
|
return parent::getDefinitionLocation('TestNamespace\\' . $fqn);
|
||||||
// Get definition for TestClass
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(4, 16));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForClassOnStaticMethodCall()
|
|
||||||
{
|
|
||||||
// $obj = new TestClass();
|
|
||||||
// Get definition for TestClass
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(7, 6));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForClassOnStaticPropertyFetch()
|
|
||||||
{
|
|
||||||
// $obj = new TestClass();
|
|
||||||
// Get definition for TestClass
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(8, 10));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForClassOnConstFetch()
|
|
||||||
{
|
|
||||||
// $obj = new TestClass();
|
|
||||||
// Get definition for TestClass
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(9, 10));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForClassLikeUseStatement()
|
|
||||||
{
|
|
||||||
// use TestNamespace\TestClass;
|
|
||||||
// Get definition for TestClass
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('use'), new Position(4, 22));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForClassLikeGroupUseStatement()
|
|
||||||
{
|
|
||||||
// use TestNamespace\{TestTrait, TestInterface};
|
|
||||||
// Get definition for TestInterface
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('use'), new Position(5, 37));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 28,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 31,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForImplements()
|
|
||||||
{
|
|
||||||
// class TestClass implements TestInterface
|
|
||||||
// Get definition for TestInterface
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('symbols'), new Position(6, 33));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 28,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 31,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForClassConstants()
|
|
||||||
{
|
|
||||||
// echo TestClass::TEST_CLASS_CONST;
|
|
||||||
// Get definition for TEST_CLASS_CONST
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(9, 21));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 10
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 32
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForConstants()
|
public function testDefinitionForConstants()
|
||||||
{
|
{
|
||||||
// echo TEST_CONST;
|
// echo TEST_CONST;
|
||||||
// Get definition for TEST_CONST
|
// Get definition for TEST_CONST
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(23, 9));
|
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 6
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 22
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForStaticMethods()
|
public function testDefinitionForClassLikeUseStatement()
|
||||||
{
|
{
|
||||||
// TestClass::staticTestMethod();
|
// use TestNamespace\TestClass;
|
||||||
// Get definition for staticTestMethod
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(7, 20));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForStaticProperties()
|
|
||||||
{
|
|
||||||
// echo TestClass::$staticTestProperty;
|
|
||||||
// Get definition for staticTestProperty
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(8, 25));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 37
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForMethods()
|
|
||||||
{
|
|
||||||
// $obj->testMethod();
|
|
||||||
// Get definition for testMethod
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(5, 11));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 17,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForProperties()
|
|
||||||
{
|
|
||||||
// echo $obj->testProperty;
|
|
||||||
// Get definition for testProperty
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(6, 18));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 11
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 24
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForVariables()
|
|
||||||
{
|
|
||||||
// echo $var;
|
|
||||||
// Get definition for $var
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(13, 7));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'references',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 10
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForParamTypeHints()
|
|
||||||
{
|
|
||||||
// function whatever(TestClass $param) {
|
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(15, 23));
|
$reference = $this->getReferenceLocations('TestClass')[6];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'symbols',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
public function testDefinitionForReturnTypeHints()
|
|
||||||
{
|
|
||||||
// function whatever(TestClass $param) {
|
|
||||||
// Get definition for TestClass
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(15, 42));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForParams()
|
public function testDefinitionForClassLikeGroupUseStatement()
|
||||||
{
|
{
|
||||||
// echo $param;
|
// use TestNamespace\{TestTrait, TestInterface};
|
||||||
// Get definition for $param
|
// Get definition for TestInterface
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(16, 13));
|
$reference = $this->getReferenceLocations('TestClass')[0];
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
'uri' => 'references',
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 34
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForUsedVariables()
|
|
||||||
{
|
|
||||||
// echo $var;
|
|
||||||
// Get definition for $var
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(20, 11));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'references',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 19,
|
|
||||||
'character' => 22
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 19,
|
|
||||||
'character' => 26
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefinitionForFunctions()
|
|
||||||
{
|
|
||||||
// test_function();
|
|
||||||
// Get definition for test_function
|
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(10, 4));
|
|
||||||
$this->assertEquals([
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 33,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 36,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,11 @@ namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
use PHPUnit\Framework\TestCase;
|
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};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
||||||
|
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
||||||
|
|
||||||
class GlobalFallbackTest extends TestCase
|
class GlobalFallbackTest extends TextDocumentTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var Server\TextDocument
|
|
||||||
*/
|
|
||||||
private $textDocument;
|
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
$client = new LanguageClient(new MockProtocolStream());
|
||||||
|
@ -37,21 +33,7 @@ class GlobalFallbackTest extends TestCase
|
||||||
// const TEST_CONST = 123;
|
// const TEST_CONST = 123;
|
||||||
// Get references for TEST_CONST
|
// Get references for TEST_CONST
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(4, 13));
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(4, 13));
|
||||||
$this->assertEquals([
|
$this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
|
||||||
[
|
|
||||||
'uri' => 'global_fallback',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 15
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFallsBackForFunctions()
|
public function testFallsBackForFunctions()
|
||||||
|
@ -59,20 +41,6 @@ class GlobalFallbackTest extends TestCase
|
||||||
// function test_function()
|
// function test_function()
|
||||||
// Get references for test_function
|
// Get references for test_function
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(33, 16));
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(33, 16));
|
||||||
$this->assertEquals([
|
$this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
|
||||||
[
|
|
||||||
'uri' => 'global_fallback',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 5,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 5,
|
|
||||||
'character' => 13
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,347 +3,104 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\References;
|
namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext};
|
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class GlobalTest extends TestCase
|
class GlobalTest extends TextDocumentTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var Server\TextDocument
|
|
||||||
*/
|
|
||||||
private $textDocument;
|
|
||||||
|
|
||||||
private $symbolsUri;
|
|
||||||
private $referencesUri;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
|
||||||
$project = new Project($client);
|
|
||||||
$this->textDocument = new Server\TextDocument($project, $client);
|
|
||||||
$this->symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
|
||||||
$this->referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_references.php'));
|
|
||||||
$project->loadDocument($this->referencesUri);
|
|
||||||
$project->loadDocument($this->symbolsUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForClassLike()
|
public function testReferencesForClassLike()
|
||||||
{
|
{
|
||||||
// class TestClass implements TestInterface
|
// class TestClass implements TestInterface
|
||||||
// Get references for TestClass
|
// Get references for TestClass
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(6, 9));
|
$definition = $this->getDefinitionLocation('TestClass');
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
// $obj = new TestClass();
|
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 11
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 20
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// TestClass::staticTestMethod();
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 9
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// echo TestClass::$staticTestProperty;
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 14
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// TestClass::TEST_CLASS_CONST;
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 14
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// function whatever(TestClass $param)
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 27
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// function whatever(TestClass $param): TestClass
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 37
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 46
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForClassConstants()
|
public function testReferencesForClassConstants()
|
||||||
{
|
{
|
||||||
// const TEST_CLASS_CONST = 123;
|
// const TEST_CLASS_CONST = 123;
|
||||||
// Get references for TEST_CLASS_CONST
|
// Get references for TEST_CLASS_CONST
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(8, 19));
|
$definition = $this->getDefinitionLocation('TestClass');
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
[
|
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 32
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForConstants()
|
public function testReferencesForConstants()
|
||||||
{
|
{
|
||||||
// const TEST_CONST = 123;
|
// const TEST_CONST = 123;
|
||||||
// Get references for TEST_CONST
|
// Get references for TEST_CONST
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(4, 13));
|
$definition = $this->getDefinitionLocation('TEST_CONST');
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
[
|
$this->assertEquals($this->getReferenceLocations('TEST_CONST'), $result);
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 23,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 23,
|
|
||||||
'character' => 15
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForStaticMethods()
|
public function testReferencesForStaticMethods()
|
||||||
{
|
{
|
||||||
// public static function staticTestMethod()
|
// public static function staticTestMethod()
|
||||||
// Get references for staticTestMethod
|
// Get references for staticTestMethod
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(12, 35));
|
$definition = $this->getDefinitionLocation('TestClass::staticTestMethod()');
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
[
|
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result);
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 29
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForStaticProperties()
|
public function testReferencesForStaticProperties()
|
||||||
{
|
{
|
||||||
// public static $staticTestProperty;
|
// public static $staticTestProperty;
|
||||||
// Get references for $staticTestProperty
|
// Get references for $staticTestProperty
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(9, 27));
|
$definition = $this->getDefinitionLocation('TestClass::staticTestProperty');
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
[
|
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result);
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 35
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForMethods()
|
public function testReferencesForMethods()
|
||||||
{
|
{
|
||||||
// public function testMethod($testParameter)
|
// public function testMethod($testParameter)
|
||||||
// Get references for testMethod
|
// Get references for testMethod
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(17, 24));
|
$definition = $this->getDefinitionLocation('TestClass::testMethod()');
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
[
|
$this->assertEquals($this->getReferenceLocations('TestClass::testMethod()'), $result);
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 5,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 5,
|
|
||||||
'character' => 18
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForProperties()
|
public function testReferencesForProperties()
|
||||||
{
|
{
|
||||||
// public $testProperty;
|
// public $testProperty;
|
||||||
// Get references for testProperty
|
// Get references for testProperty
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(10, 15));
|
$definition = $this->getDefinitionLocation('TestClass::testProperty');
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
[
|
$this->assertEquals($this->getReferenceLocations('TestClass::testProperty'), $result);
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 23
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForVariables()
|
public function testReferencesForVariables()
|
||||||
{
|
{
|
||||||
// $var = 123;
|
// $var = 123;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->referencesUri), new Position(13, 7));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(13, 7));
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
[
|
new Location($uri, new Range(new Position(12, 0), new Position(12, 4))),
|
||||||
'uri' => $this->referencesUri,
|
new Location($uri, new Range(new Position(13, 5), new Position(13, 9))),
|
||||||
'range' => [
|
new Location($uri, new Range(new Position(20, 9), new Position(20, 13)))
|
||||||
'start' => [
|
], $result);
|
||||||
'line' => 12,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 4
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 13,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 13,
|
|
||||||
'character' => 9
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 9
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 13
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForFunctionParams()
|
public function testReferencesForFunctionParams()
|
||||||
{
|
{
|
||||||
// function whatever(TestClass $param): TestClass
|
// function whatever(TestClass $param): TestClass
|
||||||
// Get references for $param
|
// Get references for $param
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->referencesUri), new Position(15, 32));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$this->assertEquals([
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(15, 32));
|
||||||
[
|
$this->assertEquals([new Location($uri, new Range(new Position(16, 9), new Position(16, 15)))], $result);
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 16,
|
|
||||||
'character' => 9
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 16,
|
|
||||||
'character' => 15
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForFunctions()
|
public function testReferencesForFunctions()
|
||||||
{
|
{
|
||||||
// function test_function()
|
// function test_function()
|
||||||
// Get references for test_function
|
// Get references for test_function
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(33, 16));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$this->assertEquals([
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
||||||
[
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($symbolsUri), new Position(33, 16));
|
||||||
'uri' => $this->referencesUri,
|
$this->assertEquals([new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13)))], $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 13
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,364 +3,18 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\References;
|
namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use LanguageServer\Protocol\Location;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext};
|
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class NamespacedTest extends TestCase
|
class NamespacedTest extends GlobalTest
|
||||||
{
|
{
|
||||||
/**
|
protected function getReferenceLocations(string $fqn): array
|
||||||
* @var Server\TextDocument
|
|
||||||
*/
|
|
||||||
private $textDocument;
|
|
||||||
|
|
||||||
private $symbolsUri;
|
|
||||||
private $referencesUri;
|
|
||||||
private $useUri;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
{
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
return parent::getReferenceLocations('TestNamespace\\' . $fqn);
|
||||||
$project = new Project($client);
|
|
||||||
$this->textDocument = new Server\TextDocument($project, $client);
|
|
||||||
$this->symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
|
||||||
$this->referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
|
||||||
$this->useUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/use.php'));
|
|
||||||
$project->loadDocument($this->referencesUri);
|
|
||||||
$project->loadDocument($this->symbolsUri);
|
|
||||||
$project->loadDocument($this->useUri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForClassLike()
|
protected function getDefinitionLocation(string $fqn): Location
|
||||||
{
|
{
|
||||||
// class TestClass implements TestInterface
|
return parent::getDefinitionLocation('TestNamespace\\' . $fqn);
|
||||||
// Get references for TestClass
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(6, 9));
|
|
||||||
$this->assertEquals([
|
|
||||||
// $obj = new TestClass();
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 11
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 20
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// TestClass::staticTestMethod();
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 9
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// echo TestClass::$staticTestProperty;
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 14
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// TestClass::TEST_CLASS_CONST;
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 14
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// function whatever(TestClass $param)
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 27
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// function whatever(TestClass $param): TestClass
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 37
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 46
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// use TestNamespace\TestClass;
|
|
||||||
[
|
|
||||||
'uri' => $this->useUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 27
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForClassConstants()
|
|
||||||
{
|
|
||||||
// const TEST_CLASS_CONST = 123;
|
|
||||||
// Get references for TEST_CLASS_CONST
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(8, 19));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 32
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForConstants()
|
|
||||||
{
|
|
||||||
// const TEST_CONST = 123;
|
|
||||||
// Get references for TEST_CONST
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(4, 13));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 23,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 23,
|
|
||||||
'character' => 15
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForStaticMethods()
|
|
||||||
{
|
|
||||||
// public static function staticTestMethod()
|
|
||||||
// Get references for staticTestMethod
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(12, 35));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 7,
|
|
||||||
'character' => 29
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForStaticProperties()
|
|
||||||
{
|
|
||||||
// public static $staticTestProperty;
|
|
||||||
// Get references for $staticTestProperty
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(9, 27));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 35
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForMethods()
|
|
||||||
{
|
|
||||||
// public function testMethod($testParameter)
|
|
||||||
// Get references for testMethod
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(17, 24));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 5,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 5,
|
|
||||||
'character' => 18
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForProperties()
|
|
||||||
{
|
|
||||||
// public $testProperty;
|
|
||||||
// Get references for testProperty
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(10, 15));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 23
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForVariables()
|
|
||||||
{
|
|
||||||
// $var = 123;
|
|
||||||
// Get definition for $var
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->referencesUri), new Position(13, 7));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 4
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 13,
|
|
||||||
'character' => 5
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 13,
|
|
||||||
'character' => 9
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 9
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 13
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForFunctionParams()
|
|
||||||
{
|
|
||||||
// function whatever(TestClass $param): TestClass
|
|
||||||
// Get references for $param
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->referencesUri), new Position(15, 32));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 16,
|
|
||||||
'character' => 9
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 16,
|
|
||||||
'character' => 15
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReferencesForFunctions()
|
|
||||||
{
|
|
||||||
// function test_function()
|
|
||||||
// Get references for test_function
|
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(33, 16));
|
|
||||||
$this->assertEquals([
|
|
||||||
[
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 13
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,164 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
|
use LanguageServer\Protocol\{Position, Location, Range};
|
||||||
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
|
abstract class TextDocumentTestCase extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Server\TextDocument
|
||||||
|
*/
|
||||||
|
protected $textDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Project
|
||||||
|
*/
|
||||||
|
protected $project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map from FQN to Location of definition
|
||||||
|
*
|
||||||
|
* @var Location[]
|
||||||
|
*/
|
||||||
|
private $definitionLocations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map from FQN to array of reference Locations
|
||||||
|
*
|
||||||
|
* @var Location[][]
|
||||||
|
*/
|
||||||
|
private $referenceLocations;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$client = new LanguageClient(new MockProtocolStream());
|
||||||
|
$this->project = new Project($client);
|
||||||
|
$this->textDocument = new Server\TextDocument($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'));
|
||||||
|
|
||||||
|
$this->project->loadDocument($symbolsUri);
|
||||||
|
$this->project->loadDocument($referencesUri);
|
||||||
|
$this->project->loadDocument($globalSymbolsUri);
|
||||||
|
$this->project->loadDocument($globalReferencesUri);
|
||||||
|
$this->project->loadDocument($useUri);
|
||||||
|
|
||||||
|
$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))),
|
||||||
|
|
||||||
|
// 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)))
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->referenceLocations = [
|
||||||
|
|
||||||
|
// Namespaced
|
||||||
|
'TestNamespace\\TEST_CONST' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position(23, 5), new Position(23, 15)))
|
||||||
|
],
|
||||||
|
'TestNamespace\\TestClass' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
|
||||||
|
1 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 9))), // TestClass::staticTestMethod();
|
||||||
|
2 => new Location($referencesUri, new Range(new Position( 8, 5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
|
||||||
|
3 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
|
||||||
|
4 => new Location($referencesUri, new Range(new Position(15, 18), new Position(15, 27))), // function whatever(TestClass $param)
|
||||||
|
5 => new Location($referencesUri, new Range(new Position(15, 37), new Position(15, 46))), // function whatever(TestClass $param): TestClass
|
||||||
|
6 => new Location($useUri, new Range(new Position( 4, 4), new Position( 4, 27))), // use TestNamespace\TestClass;
|
||||||
|
],
|
||||||
|
'TestNamespace\\TestInterface' => [
|
||||||
|
0 => new Location($symbolsUri, new Range(new Position( 6, 27), new Position( 6, 40))) // class TestClass implements TestInterface
|
||||||
|
],
|
||||||
|
'TestNamespace\\TestClass::TEST_CLASS_CONST' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position( 9, 16), new Position( 9, 32)))
|
||||||
|
],
|
||||||
|
'TestNamespace\\TestClass::testProperty' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position( 6, 5), new Position( 6, 23)))
|
||||||
|
],
|
||||||
|
'TestNamespace\\TestClass::staticTestProperty' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position( 8, 5), new Position( 8, 35)))
|
||||||
|
],
|
||||||
|
'TestNamespace\\TestClass::staticTestMethod()' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 29)))
|
||||||
|
],
|
||||||
|
'TestNamespace\\TestClass::testMethod()' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
|
||||||
|
],
|
||||||
|
'TestNamespace\\test_function()' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13)))
|
||||||
|
],
|
||||||
|
|
||||||
|
// Global
|
||||||
|
'TEST_CONST' => [
|
||||||
|
0 => new Location($referencesUri, new Range(new Position(23, 5), new Position(23, 15))),
|
||||||
|
1 => new Location($globalReferencesUri, new Range(new Position(23, 5), new Position(23, 15)))
|
||||||
|
],
|
||||||
|
'TestClass' => [
|
||||||
|
0 => new Location($globalReferencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
|
||||||
|
1 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 9))), // TestClass::staticTestMethod();
|
||||||
|
2 => new Location($globalReferencesUri, new Range(new Position( 8, 5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
|
||||||
|
3 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
|
||||||
|
4 => new Location($globalReferencesUri, new Range(new Position(15, 18), new Position(15, 27))), // function whatever(TestClass $param)
|
||||||
|
5 => new Location($globalReferencesUri, new Range(new Position(15, 37), new Position(15, 46))), // function whatever(TestClass $param): TestClass
|
||||||
|
],
|
||||||
|
'TestInterface' => [
|
||||||
|
0 => new Location($globalSymbolsUri, new Range(new Position( 6, 27), new Position( 6, 40))) // class TestClass implements TestInterface
|
||||||
|
],
|
||||||
|
'TestClass::TEST_CLASS_CONST' => [
|
||||||
|
0 => new Location($globalReferencesUri, new Range(new Position( 9, 16), new Position( 9, 32)))
|
||||||
|
],
|
||||||
|
'TestClass::testProperty' => [
|
||||||
|
0 => new Location($globalReferencesUri, new Range(new Position( 6, 5), new Position( 6, 23)))
|
||||||
|
],
|
||||||
|
'TestClass::staticTestProperty' => [
|
||||||
|
0 => new Location($globalReferencesUri, new Range(new Position( 8, 5), new Position( 8, 35)))
|
||||||
|
],
|
||||||
|
'TestClass::staticTestMethod()' => [
|
||||||
|
0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 29)))
|
||||||
|
],
|
||||||
|
'TestClass::testMethod()' => [
|
||||||
|
0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
|
||||||
|
],
|
||||||
|
'test_function()' => [
|
||||||
|
0 => new Location($globalReferencesUri, new Range(new Position(10, 0), new Position(10, 13)))
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDefinitionLocation(string $fqn): Location
|
||||||
|
{
|
||||||
|
return $this->definitionLocations[$fqn];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getReferenceLocations(string $fqn): array
|
||||||
|
{
|
||||||
|
return $this->referenceLocations[$fqn];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue