2016-10-11 23:45:15 +00:00
|
|
|
<?php
|
2018-11-27 16:51:40 +00:00
|
|
|
declare(strict_types=1);
|
2016-10-11 23:45:15 +00:00
|
|
|
|
|
|
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
|
|
|
|
|
|
|
use LanguageServer\Tests\MockProtocolStream;
|
2016-10-18 21:09:51 +00:00
|
|
|
use LanguageServer\Tests\Server\ServerTestCase;
|
2018-11-27 16:51:40 +00:00
|
|
|
use LanguageServer\{Server, LanguageClient, PhpDocumentLoader, DefinitionResolver};
|
2016-12-13 00:51:02 +00:00
|
|
|
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
|
2016-12-08 01:33:48 +00:00
|
|
|
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
2018-09-09 12:37:35 +00:00
|
|
|
use LanguageServerProtocol\{TextDocumentIdentifier, Position, Range, Location};
|
2016-10-11 23:45:15 +00:00
|
|
|
|
2016-10-18 21:09:51 +00:00
|
|
|
class GlobalFallbackTest extends ServerTestCase
|
2016-10-11 23:45:15 +00:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
2018-11-27 16:51:40 +00:00
|
|
|
$projectIndex = new ProjectIndex(new Index(), new DependenciesIndex());
|
2017-01-25 00:38:11 +00:00
|
|
|
$projectIndex->setComplete();
|
2018-11-27 16:51:40 +00:00
|
|
|
$client = new LanguageClient(new MockProtocolStream(), new MockProtocolStream());
|
2016-12-13 00:51:02 +00:00
|
|
|
$definitionResolver = new DefinitionResolver($projectIndex);
|
2018-11-27 16:51:40 +00:00
|
|
|
$contentRetriever = new FileSystemContentRetriever();
|
2016-12-13 00:51:02 +00:00
|
|
|
$loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver);
|
|
|
|
$this->textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
|
|
|
|
$loader->open('global_fallback', file_get_contents(__DIR__ . '/../../../../fixtures/global_fallback.php'));
|
|
|
|
$loader->open('global_symbols', file_get_contents(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
2016-10-11 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testClassDoesNotFallback()
|
|
|
|
{
|
|
|
|
// $obj = new TestClass();
|
|
|
|
// Get definition for TestClass should not fall back to global
|
2018-11-27 16:51:40 +00:00
|
|
|
$result = $this->textDocument
|
|
|
|
->definition(new TextDocumentIdentifier('global_fallback'), new Position(9, 16))
|
|
|
|
->wait();
|
2016-10-11 23:45:15 +00:00
|
|
|
$this->assertEquals([], $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFallsBackForConstants()
|
|
|
|
{
|
|
|
|
// echo TEST_CONST;
|
|
|
|
// Get definition for TEST_CONST
|
2018-11-27 16:51:40 +00:00
|
|
|
$result = $this->textDocument
|
|
|
|
->definition(new TextDocumentIdentifier('global_fallback'), new Position(6, 10))
|
|
|
|
->wait();
|
|
|
|
$this->assertEquals(
|
|
|
|
new Location('global_symbols', new Range(new Position(9, 6), new Position(9, 22))),
|
|
|
|
$result
|
|
|
|
);
|
2016-10-11 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFallsBackForFunctions()
|
|
|
|
{
|
|
|
|
// test_function();
|
|
|
|
// Get definition for test_function
|
2018-11-27 16:51:40 +00:00
|
|
|
$result = $this->textDocument
|
|
|
|
->definition(new TextDocumentIdentifier('global_fallback'), new Position(5, 6))
|
|
|
|
->wait();
|
|
|
|
$this->assertEquals(
|
|
|
|
new Location('global_symbols', new Range(new Position(78, 0), new Position(81, 1))),
|
|
|
|
$result
|
|
|
|
);
|
2016-10-11 23:45:15 +00:00
|
|
|
}
|
|
|
|
}
|