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

177 lines
8.1 KiB
PHP
Raw Normal View History

2016-10-08 12:59:08 +00:00
<?php
declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument\Definition;
2016-10-08 12:59:08 +00:00
use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Location, Range};
use function LanguageServer\pathToUri;
2016-10-08 12:59:08 +00:00
class GlobalTest extends ServerTestCase
2016-10-08 12:59:08 +00:00
{
public function testDefinitionFileBeginning() {
// |<?php
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(0, 0));
$this->assertEquals([], $result);
}
public function testDefinitionEmptyResult() {
// namespace keyword
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(2, 4));
$this->assertEquals([], $result);
}
2016-10-08 12:59:08 +00:00
public function testDefinitionForClassLike()
{
// $obj = new TestClass();
// Get definition for TestClass
$reference = $this->getReferenceLocations('TestClass')[0];
$result = $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 testDefinitionForClassOnStaticMethodCall()
{
// TestClass::staticTestMethod();
// Get definition for TestClass
$reference = $this->getReferenceLocations('TestClass')[1];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
}
public function testDefinitionForClassOnStaticPropertyFetch()
{
// echo TestClass::$staticTestProperty;
// Get definition for TestClass
$reference = $this->getReferenceLocations('TestClass')[2];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
}
public function testDefinitionForClassOnConstFetch()
{
// TestClass::TEST_CLASS_CONST;
// Get definition for TestClass
$reference = $this->getReferenceLocations('TestClass')[3];
$result = $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 testDefinitionForImplements()
{
// class TestClass implements TestInterface
// Get definition for TestInterface
$reference = $this->getReferenceLocations('TestInterface')[0];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForClassConstants()
{
// echo TestClass::TEST_CLASS_CONST;
// Get definition for TEST_CLASS_CONST
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
2016-10-19 09:17:19 +00:00
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForConstants()
{
// echo TEST_CONST;
// Get definition for TEST_CONST
$reference = $this->getReferenceLocations('TEST_CONST')[1];
$result = $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 testDefinitionForStaticMethods()
{
// TestClass::staticTestMethod();
// Get definition for staticTestMethod
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestMethod()'), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForStaticProperties()
{
// echo TestClass::$staticTestProperty;
// Get definition for staticTestProperty
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestProperty'), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForMethods()
{
// $obj->testMethod();
// Get definition for testMethod
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForProperties()
{
// echo $obj->testProperty;
// Get definition for testProperty
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForVariables()
{
// echo $var;
// Get definition for $var
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(13, 7));
$this->assertEquals(new Location($uri, new Range(new Position(12, 0), new Position(12, 10))), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForParamTypeHints()
{
// function whatever(TestClass $param) {
// Get definition for TestClass
$reference = $this->getReferenceLocations('TestClass')[4];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
2016-10-08 12:59:08 +00:00
}
2016-10-08 12:59:08 +00:00
public function testDefinitionForReturnTypeHints()
{
// function whatever(TestClass $param): TestClass {
2016-10-08 12:59:08 +00:00
// Get definition for TestClass
$reference = $this->getReferenceLocations('TestClass')[5];
$result = $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 testDefinitionForParams()
{
// echo $param;
// Get definition for $param
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(22, 13));
$this->assertEquals(new Location($uri, new Range(new Position(21, 18), new Position(21, 34))), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForUsedVariables()
{
// echo $var;
// Get definition for $var
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(26, 11));
$this->assertEquals(new Location($uri, new Range(new Position(25, 22), new Position(25, 26))), $result);
2016-10-08 12:59:08 +00:00
}
public function testDefinitionForFunctions()
{
// test_function();
// Get definition for test_function
$reference = $this->getReferenceLocations('test_function()')[0];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
2016-10-08 12:59:08 +00:00
}
}