2016-10-08 12:59:08 +00:00
|
|
|
<?php
|
2019-06-18 08:59:40 +00:00
|
|
|
declare(strict_types=1);
|
2016-10-08 12:59:08 +00:00
|
|
|
|
2016-10-11 23:45:15 +00:00
|
|
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
2016-10-08 12:59:08 +00:00
|
|
|
|
2019-06-18 08:59:40 +00:00
|
|
|
use Amp\Loop;
|
2018-09-09 12:37:35 +00:00
|
|
|
use LanguageServerProtocol\{TextDocumentIdentifier, Location};
|
2016-10-11 23:45:15 +00:00
|
|
|
use function LanguageServer\pathToUri;
|
2016-10-08 12:59:08 +00:00
|
|
|
|
2016-10-18 08:48:16 +00:00
|
|
|
class NamespacedTest extends GlobalTest
|
2016-10-08 12:59:08 +00:00
|
|
|
{
|
2016-10-18 08:48:16 +00:00
|
|
|
public function getReferenceLocations(string $fqn): array
|
2016-10-08 12:59:08 +00:00
|
|
|
{
|
2016-10-18 08:48:16 +00:00
|
|
|
return parent::getReferenceLocations('TestNamespace\\' . $fqn);
|
2016-10-12 10:40:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 08:48:16 +00:00
|
|
|
public function getDefinitionLocation(string $fqn): Location
|
2016-10-12 10:40:13 +00:00
|
|
|
{
|
2016-10-18 08:48:16 +00:00
|
|
|
return parent::getDefinitionLocation('TestNamespace\\' . $fqn);
|
2016-10-12 10:40:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 08:48:16 +00:00
|
|
|
public function testDefinitionForConstants()
|
2016-10-12 10:40:13 +00:00
|
|
|
{
|
2019-06-18 08:59:40 +00:00
|
|
|
Loop::run(function () {
|
|
|
|
// echo TEST_CONST;
|
|
|
|
// Get definition for TEST_CONST
|
|
|
|
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
|
|
|
$result = yield $this->textDocument->definition(
|
|
|
|
new TextDocumentIdentifier($reference->uri),
|
|
|
|
$reference->range->start
|
|
|
|
);
|
|
|
|
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
|
|
|
});
|
2016-10-12 10:40:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 12:59:08 +00:00
|
|
|
public function testDefinitionForClassLikeUseStatement()
|
|
|
|
{
|
2019-06-18 08:59:40 +00:00
|
|
|
Loop::run(function () {
|
|
|
|
// use TestNamespace\TestClass;
|
|
|
|
// Get definition for TestClass
|
|
|
|
$reference = $this->getReferenceLocations('TestClass')[7];
|
|
|
|
$result = yield $this->textDocument->definition(
|
|
|
|
new TextDocumentIdentifier($reference->uri),
|
|
|
|
$reference->range->start
|
|
|
|
);
|
|
|
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
|
|
|
});
|
2016-10-08 12:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefinitionForClassLikeGroupUseStatement()
|
|
|
|
{
|
2019-06-18 08:59:40 +00:00
|
|
|
Loop::run(function () {
|
|
|
|
// use TestNamespace\{TestTrait, TestInterface};
|
|
|
|
// Get definition for TestInterface
|
|
|
|
$reference = $this->getReferenceLocations('TestClass')[1];
|
|
|
|
$result = yield $this->textDocument->definition(
|
|
|
|
new TextDocumentIdentifier($reference->uri),
|
|
|
|
$reference->range->start
|
|
|
|
);
|
|
|
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
|
|
|
});
|
2016-10-08 12:59:08 +00:00
|
|
|
}
|
|
|
|
}
|