1
0
Fork 0
php-language-server/tests/Server/TextDocument/Definition/NamespacedTest.php

64 lines
2.1 KiB
PHP
Raw Normal View History

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
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;
use LanguageServerProtocol\{TextDocumentIdentifier, Location};
use function LanguageServer\pathToUri;
2016-10-08 12:59:08 +00:00
class NamespacedTest extends GlobalTest
2016-10-08 12:59:08 +00:00
{
public function getReferenceLocations(string $fqn): array
2016-10-08 12:59:08 +00:00
{
return parent::getReferenceLocations('TestNamespace\\' . $fqn);
}
public function getDefinitionLocation(string $fqn): Location
{
return parent::getDefinitionLocation('TestNamespace\\' . $fqn);
}
public function testDefinitionForConstants()
{
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-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
}
}