fix tests
							parent
							
								
									60ed930a50
								
							
						
					
					
						commit
						a5433b211a
					
				| 
						 | 
				
			
			@ -1,43 +1,48 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\ClientHandler;
 | 
			
		||||
use LanguageServer\Message;
 | 
			
		||||
use AdvancedJsonRpc;
 | 
			
		||||
use Sabre\Event\Loop;
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\ClientHandler;
 | 
			
		||||
use LanguageServer\Event\MessageEvent;
 | 
			
		||||
use LanguageServer\Message;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
 | 
			
		||||
class ClientHandlerTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testRequest()
 | 
			
		||||
    {
 | 
			
		||||
        $reader = new MockProtocolStream;
 | 
			
		||||
        $writer = new MockProtocolStream;
 | 
			
		||||
        $handler = new ClientHandler($reader, $writer);
 | 
			
		||||
        $writer->once('message', function (Message $msg) use ($reader) {
 | 
			
		||||
            // Respond to request
 | 
			
		||||
            Loop\setTimeout(function () use ($reader, $msg) {
 | 
			
		||||
                $reader->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, 'pong')));
 | 
			
		||||
            }, 0);
 | 
			
		||||
        });
 | 
			
		||||
        $handler->request('testMethod', ['ping'])->then(function ($result) {
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $reader = new MockProtocolStream;
 | 
			
		||||
            $writer = new MockProtocolStream;
 | 
			
		||||
            $handler = new ClientHandler($reader, $writer);
 | 
			
		||||
            $writer->addOneTimeListener('message', function (MessageEvent $messageEvent) use ($reader) {
 | 
			
		||||
                $msg = $messageEvent->getMessage();
 | 
			
		||||
                // Respond to request
 | 
			
		||||
                Loop::defer(function () use ($reader, $msg) {
 | 
			
		||||
                    yield from $reader->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, 'pong')));
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
            $result = yield from $handler->request('testMethod', ['ping']);
 | 
			
		||||
            $this->assertEquals('pong', $result);
 | 
			
		||||
        })->wait();
 | 
			
		||||
        // No event listeners
 | 
			
		||||
        $this->assertEquals([], $reader->listeners('message'));
 | 
			
		||||
        $this->assertEquals([], $writer->listeners('message'));
 | 
			
		||||
            // No event listeners
 | 
			
		||||
            $this->assertEquals([], $reader->getListeners('message'));
 | 
			
		||||
            $this->assertEquals([], $writer->getListeners('message'));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testNotify()
 | 
			
		||||
    {
 | 
			
		||||
        $reader = new MockProtocolStream;
 | 
			
		||||
        $writer = new MockProtocolStream;
 | 
			
		||||
        $handler = new ClientHandler($reader, $writer);
 | 
			
		||||
        $handler->notify('testMethod', ['ping'])->wait();
 | 
			
		||||
        // No event listeners
 | 
			
		||||
        $this->assertEquals([], $reader->listeners('message'));
 | 
			
		||||
        $this->assertEquals([], $writer->listeners('message'));
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $reader = new MockProtocolStream;
 | 
			
		||||
            $writer = new MockProtocolStream;
 | 
			
		||||
            $handler = new ClientHandler($reader, $writer);
 | 
			
		||||
            yield from $handler->notify('testMethod', ['ping']);
 | 
			
		||||
            // No event listeners
 | 
			
		||||
            $this->assertEquals([], $reader->getListeners('message'));
 | 
			
		||||
            $this->assertEquals([], $writer->getListeners('message'));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,122 +1,132 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use AdvancedJsonRpc;
 | 
			
		||||
use Amp\Deferred;
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use Exception;
 | 
			
		||||
use LanguageServer\Event\MessageEvent;
 | 
			
		||||
use LanguageServer\LanguageServer;
 | 
			
		||||
use LanguageServer\Message;
 | 
			
		||||
use LanguageServerProtocol\{
 | 
			
		||||
    ClientCapabilities,
 | 
			
		||||
    TextDocumentSyncKind,
 | 
			
		||||
    MessageType,
 | 
			
		||||
    TextDocumentItem,
 | 
			
		||||
    TextDocumentIdentifier,
 | 
			
		||||
    InitializeResult,
 | 
			
		||||
    ServerCapabilities,
 | 
			
		||||
use LanguageServerProtocol\{ClientCapabilities,
 | 
			
		||||
    CompletionOptions,
 | 
			
		||||
    SignatureHelpOptions
 | 
			
		||||
};
 | 
			
		||||
use AdvancedJsonRpc;
 | 
			
		||||
    InitializeResult,
 | 
			
		||||
    MessageType,
 | 
			
		||||
    ServerCapabilities,
 | 
			
		||||
    SignatureHelpOptions,
 | 
			
		||||
    TextDocumentIdentifier,
 | 
			
		||||
    TextDocumentItem,
 | 
			
		||||
    TextDocumentSyncKind};
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Webmozart\Glob\Glob;
 | 
			
		||||
use Webmozart\PathUtil\Path;
 | 
			
		||||
use Sabre\Event\Promise;
 | 
			
		||||
use Exception;
 | 
			
		||||
use function LanguageServer\pathToUri;
 | 
			
		||||
 | 
			
		||||
class LanguageServerTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testInitialize()
 | 
			
		||||
    {
 | 
			
		||||
        $server = new LanguageServer(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
        $result = $server->initialize(new ClientCapabilities, __DIR__, getmypid())->wait();
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $server = new LanguageServer(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
            $result = yield $server->initialize(new ClientCapabilities, __DIR__, getmypid());
 | 
			
		||||
 | 
			
		||||
        $serverCapabilities = new ServerCapabilities();
 | 
			
		||||
        $serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL;
 | 
			
		||||
        $serverCapabilities->documentSymbolProvider = true;
 | 
			
		||||
        $serverCapabilities->workspaceSymbolProvider = true;
 | 
			
		||||
        $serverCapabilities->definitionProvider = true;
 | 
			
		||||
        $serverCapabilities->referencesProvider = true;
 | 
			
		||||
        $serverCapabilities->hoverProvider = true;
 | 
			
		||||
        $serverCapabilities->completionProvider = new CompletionOptions;
 | 
			
		||||
        $serverCapabilities->completionProvider->resolveProvider = false;
 | 
			
		||||
        $serverCapabilities->completionProvider->triggerCharacters = ['$', '>'];
 | 
			
		||||
        $serverCapabilities->signatureHelpProvider = new SignatureHelpOptions;
 | 
			
		||||
        $serverCapabilities->signatureHelpProvider->triggerCharacters = ['(', ','];
 | 
			
		||||
        $serverCapabilities->xworkspaceReferencesProvider = true;
 | 
			
		||||
        $serverCapabilities->xdefinitionProvider = true;
 | 
			
		||||
        $serverCapabilities->xdependenciesProvider = true;
 | 
			
		||||
            $serverCapabilities = new ServerCapabilities();
 | 
			
		||||
            $serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL;
 | 
			
		||||
            $serverCapabilities->documentSymbolProvider = true;
 | 
			
		||||
            $serverCapabilities->workspaceSymbolProvider = true;
 | 
			
		||||
            $serverCapabilities->definitionProvider = true;
 | 
			
		||||
            $serverCapabilities->referencesProvider = true;
 | 
			
		||||
            $serverCapabilities->hoverProvider = true;
 | 
			
		||||
            $serverCapabilities->completionProvider = new CompletionOptions;
 | 
			
		||||
            $serverCapabilities->completionProvider->resolveProvider = false;
 | 
			
		||||
            $serverCapabilities->completionProvider->triggerCharacters = ['$', '>'];
 | 
			
		||||
            $serverCapabilities->signatureHelpProvider = new SignatureHelpOptions;
 | 
			
		||||
            $serverCapabilities->signatureHelpProvider->triggerCharacters = ['(', ','];
 | 
			
		||||
            $serverCapabilities->xworkspaceReferencesProvider = true;
 | 
			
		||||
            $serverCapabilities->xdefinitionProvider = true;
 | 
			
		||||
            $serverCapabilities->xdependenciesProvider = true;
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(new InitializeResult($serverCapabilities), $result);
 | 
			
		||||
            $this->assertEquals(new InitializeResult($serverCapabilities), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIndexingWithDirectFileAccess()
 | 
			
		||||
    {
 | 
			
		||||
        $promise = new Promise;
 | 
			
		||||
        $input = new MockProtocolStream;
 | 
			
		||||
        $output = new MockProtocolStream;
 | 
			
		||||
        $output->on('message', function (Message $msg) use ($promise) {
 | 
			
		||||
            if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
 | 
			
		||||
                if ($msg->body->params->type === MessageType::ERROR) {
 | 
			
		||||
                    $promise->reject(new Exception($msg->body->params->message));
 | 
			
		||||
                } else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
 | 
			
		||||
                    $promise->fulfill();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $deferred = new Deferred();
 | 
			
		||||
            $input = new MockProtocolStream;
 | 
			
		||||
            $output = new MockProtocolStream;
 | 
			
		||||
            $output->addListener('message', function (MessageEvent $messageEvent) use ($deferred) {
 | 
			
		||||
                $msg = $messageEvent->getMessage();
 | 
			
		||||
                Loop::defer(function () use ($deferred, $msg) {
 | 
			
		||||
                    if ($msg->body->method === 'window/logMessage') {
 | 
			
		||||
                        if ($msg->body->params->type === MessageType::ERROR) {
 | 
			
		||||
                            $deferred->fail(new Exception($msg->body->params->message));
 | 
			
		||||
                        } else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
 | 
			
		||||
                            $deferred->resolve(true);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
            $server = new LanguageServer($input, $output);
 | 
			
		||||
            $capabilities = new ClientCapabilities;
 | 
			
		||||
            yield $server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid());
 | 
			
		||||
            $this->assertTrue(yield $deferred->promise());
 | 
			
		||||
        });
 | 
			
		||||
        $server = new LanguageServer($input, $output);
 | 
			
		||||
        $capabilities = new ClientCapabilities;
 | 
			
		||||
        $server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid());
 | 
			
		||||
        $promise->wait();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIndexingWithFilesAndContentRequests()
 | 
			
		||||
    {
 | 
			
		||||
        $promise = new Promise;
 | 
			
		||||
        $filesCalled = false;
 | 
			
		||||
        $contentCalled = false;
 | 
			
		||||
        $rootPath = realpath(__DIR__ . '/../fixtures');
 | 
			
		||||
        $input = new MockProtocolStream;
 | 
			
		||||
        $output = new MockProtocolStream;
 | 
			
		||||
        $run = 1;
 | 
			
		||||
        $output->on('message', function (Message $msg) use ($promise, $input, $rootPath, &$filesCalled, &$contentCalled, &$run) {
 | 
			
		||||
            if ($msg->body->method === 'textDocument/xcontent') {
 | 
			
		||||
                // Document content requested
 | 
			
		||||
                $contentCalled = true;
 | 
			
		||||
                $textDocumentItem = new TextDocumentItem;
 | 
			
		||||
                $textDocumentItem->uri = $msg->body->params->textDocument->uri;
 | 
			
		||||
                $textDocumentItem->version = 1;
 | 
			
		||||
                $textDocumentItem->languageId = 'php';
 | 
			
		||||
                $textDocumentItem->text = file_get_contents($msg->body->params->textDocument->uri);
 | 
			
		||||
                $input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $textDocumentItem)));
 | 
			
		||||
            } else if ($msg->body->method === 'workspace/xfiles') {
 | 
			
		||||
                // Files requested
 | 
			
		||||
                $filesCalled = true;
 | 
			
		||||
                $pattern = Path::makeAbsolute('**/*.php', $msg->body->params->base ?? $rootPath);
 | 
			
		||||
                $files = [];
 | 
			
		||||
                foreach (Glob::glob($pattern) as $path) {
 | 
			
		||||
                    $files[] = new TextDocumentIdentifier(pathToUri($path));
 | 
			
		||||
                }
 | 
			
		||||
                $input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $files)));
 | 
			
		||||
            } else if ($msg->body->method === 'window/logMessage') {
 | 
			
		||||
                // Message logged
 | 
			
		||||
                if ($msg->body->params->type === MessageType::ERROR) {
 | 
			
		||||
                    // Error happened during indexing, fail test
 | 
			
		||||
                    if ($promise->state === Promise::PENDING) {
 | 
			
		||||
                        $promise->reject(new Exception($msg->body->params->message));
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $deferred = new Deferred();
 | 
			
		||||
            $filesCalled = false;
 | 
			
		||||
            $contentCalled = false;
 | 
			
		||||
            $rootPath = realpath(__DIR__ . '/../fixtures');
 | 
			
		||||
            $input = new MockProtocolStream;
 | 
			
		||||
            $output = new MockProtocolStream;
 | 
			
		||||
            $run = 1;
 | 
			
		||||
            $output->addListener('message', function (MessageEvent $messageEvent) use ($deferred, $input, $rootPath, &$filesCalled, &$contentCalled, &$run) {
 | 
			
		||||
                $msg = $messageEvent->getMessage();
 | 
			
		||||
                Loop::defer(function () use ($msg, $deferred, $input, $rootPath, &$filesCalled, &$contentCalled, &$run) {
 | 
			
		||||
                    if ($msg->body->method === 'textDocument/xcontent') {
 | 
			
		||||
                        // Document content requested
 | 
			
		||||
                        $contentCalled = true;
 | 
			
		||||
                        $textDocumentItem = new TextDocumentItem;
 | 
			
		||||
                        $textDocumentItem->uri = $msg->body->params->textDocument->uri;
 | 
			
		||||
                        $textDocumentItem->version = 1;
 | 
			
		||||
                        $textDocumentItem->languageId = 'php';
 | 
			
		||||
                        $textDocumentItem->text = file_get_contents($msg->body->params->textDocument->uri);
 | 
			
		||||
                        yield from $input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $textDocumentItem)));
 | 
			
		||||
                    } else if ($msg->body->method === 'workspace/xfiles') {
 | 
			
		||||
                        // Files requested
 | 
			
		||||
                        $filesCalled = true;
 | 
			
		||||
                        $pattern = Path::makeAbsolute('**/*.php', $msg->body->params->base ?? $rootPath);
 | 
			
		||||
                        $files = [];
 | 
			
		||||
                        foreach (Glob::glob($pattern) as $path) {
 | 
			
		||||
                            $files[] = new TextDocumentIdentifier(pathToUri($path));
 | 
			
		||||
                        }
 | 
			
		||||
                        yield from $input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $files)));
 | 
			
		||||
                    } else if ($msg->body->method === 'window/logMessage') {
 | 
			
		||||
                        // Message logged
 | 
			
		||||
                        if ($msg->body->params->type === MessageType::ERROR) {
 | 
			
		||||
                            // Error happened during indexing, fail test
 | 
			
		||||
                            $deferred->fail(new Exception($msg->body->params->message));
 | 
			
		||||
                        } else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
 | 
			
		||||
                            $deferred->resolve(true);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                } else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
 | 
			
		||||
                    $promise->fulfill();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
            $server = new LanguageServer($input, $output);
 | 
			
		||||
            $capabilities = new ClientCapabilities;
 | 
			
		||||
            $capabilities->xfilesProvider = true;
 | 
			
		||||
            $capabilities->xcontentProvider = true;
 | 
			
		||||
            yield $server->initialize($capabilities, $rootPath, getmypid());
 | 
			
		||||
            yield $deferred->promise();
 | 
			
		||||
            $this->assertTrue($filesCalled);
 | 
			
		||||
            $this->assertTrue($contentCalled);
 | 
			
		||||
        });
 | 
			
		||||
        $server = new LanguageServer($input, $output);
 | 
			
		||||
        $capabilities = new ClientCapabilities;
 | 
			
		||||
        $capabilities->xfilesProvider = true;
 | 
			
		||||
        $capabilities->xcontentProvider = true;
 | 
			
		||||
        $server->initialize($capabilities, $rootPath, getmypid());
 | 
			
		||||
        $promise->wait();
 | 
			
		||||
        $this->assertTrue($filesCalled);
 | 
			
		||||
        $this->assertTrue($contentCalled);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,15 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests;
 | 
			
		||||
 | 
			
		||||
use LanguageServer\{ProtocolReader, ProtocolWriter};
 | 
			
		||||
use Amp\Deferred;
 | 
			
		||||
use Amp\Delayed;
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\{Event\MessageEvent, ProtocolReader, ProtocolWriter};
 | 
			
		||||
use LanguageServer\Message;
 | 
			
		||||
use Sabre\Event\{Loop, Emitter, Promise};
 | 
			
		||||
use League\Event\Emitter;
 | 
			
		||||
use League\Event\Event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A fake duplex protocol stream
 | 
			
		||||
| 
						 | 
				
			
			@ -18,11 +22,11 @@ class MockProtocolStream extends Emitter implements ProtocolReader, ProtocolWrit
 | 
			
		|||
     * @param Message $msg
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function write(Message $msg): Promise
 | 
			
		||||
    public function write(Message $msg): \Generator
 | 
			
		||||
    {
 | 
			
		||||
        Loop\nextTick(function () use ($msg) {
 | 
			
		||||
            $this->emit('message', [Message::parse((string)$msg)]);
 | 
			
		||||
        Loop::defer(function () use ($msg) {
 | 
			
		||||
            $this->emit(new MessageEvent('message', Message::parse((string)$msg)));
 | 
			
		||||
        });
 | 
			
		||||
        return Promise\resolve(null);
 | 
			
		||||
        yield new Delayed(0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
    PhpDocument, PhpDocumentLoader, Project, DefinitionResolver
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -32,10 +33,12 @@ class PhpDocumentLoaderTest extends TestCase
 | 
			
		|||
 | 
			
		||||
    public function testGetOrLoadLoadsDocument()
 | 
			
		||||
    {
 | 
			
		||||
        $document = $this->loader->getOrLoad(pathToUri(__FILE__))->wait();
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $document = yield from $this->loader->getOrLoad(pathToUri(__FILE__));
 | 
			
		||||
 | 
			
		||||
        $this->assertNotNull($document);
 | 
			
		||||
        $this->assertInstanceOf(PhpDocument::class, $document);
 | 
			
		||||
            $this->assertNotNull($document);
 | 
			
		||||
            $this->assertInstanceOf(PhpDocument::class, $document);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetReturnsOpenedInstance()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,32 +1,49 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\{LanguageServer, ProtocolStreamReader, ProtocolStreamWriter};
 | 
			
		||||
use AdvancedJsonRpc\{Request as RequestBody};
 | 
			
		||||
use Amp\ByteStream\ResourceInputStream;
 | 
			
		||||
use Amp\ByteStream\ResourceOutputStream;
 | 
			
		||||
use Amp\Deferred;
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\{Event\MessageEvent, ProtocolStreamReader};
 | 
			
		||||
use LanguageServer\Message;
 | 
			
		||||
use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
 | 
			
		||||
use Sabre\Event\Loop;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
 | 
			
		||||
class ProtocolStreamReaderTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function getStreamPair()
 | 
			
		||||
    {
 | 
			
		||||
        $domain = \stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX;
 | 
			
		||||
        list($left, $right) = @\stream_socket_pair($domain, \STREAM_SOCK_STREAM, \STREAM_IPPROTO_IP);
 | 
			
		||||
        $a = new ResourceOutputStream($left);
 | 
			
		||||
        $b = new ResourceInputStream($right);
 | 
			
		||||
        return [$a, $b];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParsingWorksAndListenerIsCalled()
 | 
			
		||||
    {
 | 
			
		||||
        $tmpfile = tempnam('', '');
 | 
			
		||||
        $writeHandle = fopen($tmpfile, 'w');
 | 
			
		||||
        $reader = new ProtocolStreamReader(fopen($tmpfile, 'r'));
 | 
			
		||||
        $msg = null;
 | 
			
		||||
        $reader->on('message', function (Message $message) use (&$msg) {
 | 
			
		||||
            $msg = $message;
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            /** @var ResourceOutputStream $outputStream */
 | 
			
		||||
            /** @var ResourceInputStream $inputStream */
 | 
			
		||||
            list($outputStream, $inputStream) = $this->getStreamPair();
 | 
			
		||||
 | 
			
		||||
            $reader = new ProtocolStreamReader($inputStream);
 | 
			
		||||
            $deferred = new Deferred();
 | 
			
		||||
            $reader->addListener('message', function (MessageEvent $messageEvent) use (&$deferred) {
 | 
			
		||||
                $deferred->resolve($messageEvent->getMessage());
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            yield $outputStream->write((string)new Message(new RequestBody(1, 'aMethod', ['arg' => 'Hello World'])));
 | 
			
		||||
            $msg = yield $deferred->promise();
 | 
			
		||||
            $this->assertNotNull($msg);
 | 
			
		||||
            $this->assertInstanceOf(Message::class, $msg);
 | 
			
		||||
            $this->assertInstanceOf(RequestBody::class, $msg->body);
 | 
			
		||||
            $this->assertEquals(1, $msg->body->id);
 | 
			
		||||
            $this->assertEquals('aMethod', $msg->body->method);
 | 
			
		||||
            $this->assertEquals((object)['arg' => 'Hello World'], $msg->body->params);
 | 
			
		||||
        });
 | 
			
		||||
        $ret = fwrite($writeHandle, (string)new Message(new RequestBody(1, 'aMethod', ['arg' => 'Hello World'])));
 | 
			
		||||
        Loop\tick();
 | 
			
		||||
        $this->assertNotNull($msg);
 | 
			
		||||
        $this->assertInstanceOf(Message::class, $msg);
 | 
			
		||||
        $this->assertInstanceOf(RequestBody::class, $msg->body);
 | 
			
		||||
        $this->assertEquals(1, $msg->body->id);
 | 
			
		||||
        $this->assertEquals('aMethod', $msg->body->method);
 | 
			
		||||
        $this->assertEquals((object)['arg' => 'Hello World'], $msg->body->params);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,35 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\ProtocolStreamWriter;
 | 
			
		||||
use LanguageServer\Message;
 | 
			
		||||
use AdvancedJsonRpc\{Request as RequestBody};
 | 
			
		||||
use Sabre\Event\Loop;
 | 
			
		||||
 | 
			
		||||
class ProtocolStreamWriterTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testLargeMessageIsSent()
 | 
			
		||||
    {
 | 
			
		||||
        $tmpfile = tempnam('', '');
 | 
			
		||||
        $writeHandle = fopen($tmpfile, 'w');
 | 
			
		||||
 | 
			
		||||
        stream_set_blocking($writeHandle, false);
 | 
			
		||||
 | 
			
		||||
        $writer = new ProtocolStreamWriter($writeHandle);
 | 
			
		||||
        $msg = new Message(new RequestBody(1, 'aMethod', ['arg' => str_repeat('X', 100000)]));
 | 
			
		||||
        $msgString = (string)$msg;
 | 
			
		||||
 | 
			
		||||
        $promise = $writer->write($msg);
 | 
			
		||||
 | 
			
		||||
        Loop\tick();
 | 
			
		||||
 | 
			
		||||
        $promise->wait();
 | 
			
		||||
 | 
			
		||||
        fclose($writeHandle);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(strlen($msgString), filesize($tmpfile));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
| 
						 | 
				
			
			@ -46,185 +47,187 @@ abstract class ServerTestCase extends TestCase
 | 
			
		|||
 | 
			
		||||
    public function setUp()
 | 
			
		||||
    {
 | 
			
		||||
        $sourceIndex       = new Index;
 | 
			
		||||
        $dependenciesIndex = new DependenciesIndex;
 | 
			
		||||
        $projectIndex      = new ProjectIndex($sourceIndex, $dependenciesIndex);
 | 
			
		||||
        $projectIndex->setComplete();
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $sourceIndex = new Index;
 | 
			
		||||
            $dependenciesIndex = new DependenciesIndex;
 | 
			
		||||
            $projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
 | 
			
		||||
            $projectIndex->setComplete();
 | 
			
		||||
 | 
			
		||||
        $definitionResolver   = new DefinitionResolver($projectIndex);
 | 
			
		||||
        $client               = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
        $this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
 | 
			
		||||
        $this->textDocument   = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
        $this->workspace      = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $this->documentLoader);
 | 
			
		||||
            $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
            $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
            $this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
 | 
			
		||||
            $this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
            $this->workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $this->documentLoader);
 | 
			
		||||
 | 
			
		||||
        $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'));
 | 
			
		||||
            $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->documentLoader->load($symbolsUri)->wait();
 | 
			
		||||
        $this->documentLoader->load($referencesUri)->wait();
 | 
			
		||||
        $this->documentLoader->load($globalSymbolsUri)->wait();
 | 
			
		||||
        $this->documentLoader->load($globalReferencesUri)->wait();
 | 
			
		||||
        $this->documentLoader->load($useUri)->wait();
 | 
			
		||||
            yield from $this->documentLoader->load($symbolsUri);
 | 
			
		||||
            yield from $this->documentLoader->load($referencesUri);
 | 
			
		||||
            yield from $this->documentLoader->load($globalSymbolsUri);
 | 
			
		||||
            yield from $this->documentLoader->load($globalReferencesUri);
 | 
			
		||||
            yield from $this->documentLoader->load($useUri);
 | 
			
		||||
 | 
			
		||||
        // @codingStandardsIgnoreStart
 | 
			
		||||
        $this->definitionLocations = [
 | 
			
		||||
            // @codingStandardsIgnoreStart
 | 
			
		||||
            $this->definitionLocations = [
 | 
			
		||||
 | 
			
		||||
            // Global
 | 
			
		||||
            'TEST_DEFINE_CONSTANT'                   => new Location($globalSymbolsUri,    new Range(new Position(104, 0), new Position(104, 37))),
 | 
			
		||||
            'TEST_CONST'                             => new Location($globalSymbolsUri,    new Range(new Position( 9,  6), new Position( 9,  22))),
 | 
			
		||||
            'TestClass'                              => new Location($globalSymbolsUri,    new Range(new Position(20,  0), new Position(61,   1))),
 | 
			
		||||
            'ChildClass'                             => new Location($globalSymbolsUri,    new Range(new Position(99,  0), new Position(99,  37))),
 | 
			
		||||
            'TestTrait'                              => new Location($globalSymbolsUri,    new Range(new Position(63,  0), new Position(66,   1))),
 | 
			
		||||
            'TestInterface'                          => new Location($globalSymbolsUri,    new Range(new Position(68,  0), new Position(71,   1))),
 | 
			
		||||
            'TestClass::TEST_CLASS_CONST'            => new Location($globalSymbolsUri,    new Range(new Position(27, 10), new Position(27,  32))),
 | 
			
		||||
            'TestClass::testProperty'                => new Location($globalSymbolsUri,    new Range(new Position(41, 11), new Position(41,  24))),
 | 
			
		||||
            'TestClass::staticTestProperty'          => new Location($globalSymbolsUri,    new Range(new Position(34, 18), new Position(34,  37))),
 | 
			
		||||
            'TestClass::staticTestMethod()'          => new Location($globalSymbolsUri,    new Range(new Position(46,  4), new Position(49,   5))),
 | 
			
		||||
            'TestClass::testMethod()'                => new Location($globalSymbolsUri,    new Range(new Position(57,  4), new Position(60,   5))),
 | 
			
		||||
            'test_function()'                        => new Location($globalSymbolsUri,    new Range(new Position(78,  0), new Position(81,   1))),
 | 
			
		||||
            'UnusedClass'                            => new Location($globalSymbolsUri,    new Range(new Position(111, 0), new Position(118,  1))),
 | 
			
		||||
            'UnusedClass::unusedProperty'            => new Location($globalSymbolsUri,    new Range(new Position(113,11), new Position(113, 26))),
 | 
			
		||||
            'UnusedClass::unusedMethod'              => new Location($globalSymbolsUri,    new Range(new Position(115, 4), new Position(117,  5))),
 | 
			
		||||
            'whatever()'                             => new Location($globalReferencesUri, new Range(new Position(21,  0), new Position(23,   1))),
 | 
			
		||||
                // Global
 | 
			
		||||
                'TEST_DEFINE_CONSTANT' => new Location($globalSymbolsUri, new Range(new Position(104, 0), new Position(104, 37))),
 | 
			
		||||
                'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position(9, 6), new Position(9, 22))),
 | 
			
		||||
                'TestClass' => new Location($globalSymbolsUri, new Range(new Position(20, 0), new Position(61, 1))),
 | 
			
		||||
                'ChildClass' => new Location($globalSymbolsUri, new Range(new Position(99, 0), new Position(99, 37))),
 | 
			
		||||
                'TestTrait' => new Location($globalSymbolsUri, new Range(new Position(63, 0), new Position(66, 1))),
 | 
			
		||||
                'TestInterface' => new Location($globalSymbolsUri, new Range(new Position(68, 0), new Position(71, 1))),
 | 
			
		||||
                'TestClass::TEST_CLASS_CONST' => new Location($globalSymbolsUri, new Range(new Position(27, 10), new Position(27, 32))),
 | 
			
		||||
                'TestClass::testProperty' => new Location($globalSymbolsUri, new Range(new Position(41, 11), new Position(41, 24))),
 | 
			
		||||
                'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
 | 
			
		||||
                'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
 | 
			
		||||
                'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(57, 4), new Position(60, 5))),
 | 
			
		||||
                'test_function()' => new Location($globalSymbolsUri, new Range(new Position(78, 0), new Position(81, 1))),
 | 
			
		||||
                'UnusedClass' => new Location($globalSymbolsUri, new Range(new Position(111, 0), new Position(118, 1))),
 | 
			
		||||
                'UnusedClass::unusedProperty' => new Location($globalSymbolsUri, new Range(new Position(113, 11), new Position(113, 26))),
 | 
			
		||||
                'UnusedClass::unusedMethod' => new Location($globalSymbolsUri, new Range(new Position(115, 4), new Position(117, 5))),
 | 
			
		||||
                'whatever()' => new Location($globalReferencesUri, new Range(new Position(21, 0), new Position(23, 1))),
 | 
			
		||||
 | 
			
		||||
            // Namespaced
 | 
			
		||||
            'TestNamespace'                                => new Location($symbolsUri,    new Range(new Position( 2, 0), new Position( 2, 24))),
 | 
			
		||||
            'SecondTestNamespace'                          => new Location($useUri,        new Range(new Position( 2, 0), new Position( 2, 30))),
 | 
			
		||||
            'TestNamespace\\TEST_CONST'                    => new Location($symbolsUri,    new Range(new Position( 9,  6), new Position( 9, 22))),
 | 
			
		||||
            'TestNamespace\\TestClass'                     => new Location($symbolsUri,    new Range(new Position(20,  0), new Position(61,  1))),
 | 
			
		||||
            'TestNamespace\\ChildClass'                    => new Location($symbolsUri,    new Range(new Position(99,  0), new Position(99, 37))),
 | 
			
		||||
            'TestNamespace\\TestTrait'                     => new Location($symbolsUri,    new Range(new Position(63,  0), new Position(66,  1))),
 | 
			
		||||
            'TestNamespace\\TestInterface'                 => new Location($symbolsUri,    new Range(new Position(68,  0), new Position(71,  1))),
 | 
			
		||||
            'TestNamespace\\TestClass::TEST_CLASS_CONST'   => new Location($symbolsUri,    new Range(new Position(27, 10), new Position(27,  32))),
 | 
			
		||||
            'TestNamespace\\TestClass::testProperty'       => new Location($symbolsUri,    new Range(new Position(41, 11), new Position(41,  24))),
 | 
			
		||||
            'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri,    new Range(new Position(34, 18), new Position(34,  37))),
 | 
			
		||||
            'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri,    new Range(new Position(46,  4), new Position(49,   5))),
 | 
			
		||||
            'TestNamespace\\TestClass::testMethod()'       => new Location($symbolsUri,    new Range(new Position(57,  4), new Position(60,   5))),
 | 
			
		||||
            'TestNamespace\\test_function()'               => new Location($symbolsUri,    new Range(new Position(78,  0), new Position(81,   1))),
 | 
			
		||||
            'TestNamespace\\whatever()'                    => new Location($referencesUri, new Range(new Position(21,  0), new Position(23,   1))),
 | 
			
		||||
            'TestNamespace\\Example'                       => new Location($symbolsUri,    new Range(new Position(101, 0), new Position(104,  1))),
 | 
			
		||||
            'TestNamespace\\Example::__construct'          => new Location($symbolsUri,    new Range(new Position(102, 4), new Position(102, 36))),
 | 
			
		||||
            'TestNamespace\\Example::__destruct'           => new Location($symbolsUri,    new Range(new Position(103, 4), new Position(103, 35))),
 | 
			
		||||
            'TestNamespace\\InnerNamespace'                => new Location($symbolsUri,    new Range(new Position(106, 0), new Position(106, 39))),
 | 
			
		||||
            'TestNamespace\\InnerNamespace\\InnerClass'    => new Location($symbolsUri,    new Range(new Position(108, 0), new Position(109,  1))),
 | 
			
		||||
        ];
 | 
			
		||||
                // Namespaced
 | 
			
		||||
                'TestNamespace' => new Location($symbolsUri, new Range(new Position(2, 0), new Position(2, 24))),
 | 
			
		||||
                'SecondTestNamespace' => new Location($useUri, new Range(new Position(2, 0), new Position(2, 30))),
 | 
			
		||||
                'TestNamespace\\TEST_CONST' => new Location($symbolsUri, new Range(new Position(9, 6), new Position(9, 22))),
 | 
			
		||||
                'TestNamespace\\TestClass' => new Location($symbolsUri, new Range(new Position(20, 0), new Position(61, 1))),
 | 
			
		||||
                'TestNamespace\\ChildClass' => new Location($symbolsUri, new Range(new Position(99, 0), new Position(99, 37))),
 | 
			
		||||
                'TestNamespace\\TestTrait' => new Location($symbolsUri, new Range(new Position(63, 0), new Position(66, 1))),
 | 
			
		||||
                'TestNamespace\\TestInterface' => new Location($symbolsUri, new Range(new Position(68, 0), new Position(71, 1))),
 | 
			
		||||
                'TestNamespace\\TestClass::TEST_CLASS_CONST' => new Location($symbolsUri, new Range(new Position(27, 10), new Position(27, 32))),
 | 
			
		||||
                'TestNamespace\\TestClass::testProperty' => new Location($symbolsUri, new Range(new Position(41, 11), new Position(41, 24))),
 | 
			
		||||
                'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
 | 
			
		||||
                'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
 | 
			
		||||
                'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(57, 4), new Position(60, 5))),
 | 
			
		||||
                'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(78, 0), new Position(81, 1))),
 | 
			
		||||
                'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(21, 0), new Position(23, 1))),
 | 
			
		||||
                'TestNamespace\\Example' => new Location($symbolsUri, new Range(new Position(101, 0), new Position(104, 1))),
 | 
			
		||||
                'TestNamespace\\Example::__construct' => new Location($symbolsUri, new Range(new Position(102, 4), new Position(102, 36))),
 | 
			
		||||
                'TestNamespace\\Example::__destruct' => new Location($symbolsUri, new Range(new Position(103, 4), new Position(103, 35))),
 | 
			
		||||
                'TestNamespace\\InnerNamespace' => new Location($symbolsUri, new Range(new Position(106, 0), new Position(106, 39))),
 | 
			
		||||
                'TestNamespace\\InnerNamespace\\InnerClass' => new Location($symbolsUri, new Range(new Position(108, 0), new Position(109, 1))),
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
        $this->referenceLocations = [
 | 
			
		||||
            $this->referenceLocations = [
 | 
			
		||||
 | 
			
		||||
            // Namespaced
 | 
			
		||||
            'TestNamespace' => [
 | 
			
		||||
                0 => new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40))), // use function TestNamespace\test_function;
 | 
			
		||||
                1 => new Location($useUri,        new Range(new Position( 4,  4), new Position( 4, 27))), // use TestNamespace\TestClass;
 | 
			
		||||
                2 => new Location($useUri,        new Range(new Position( 5,  4), new Position( 5, 18)))  // use TestNamespace\{TestTrait, TestInterface};
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TEST_CONST' => [
 | 
			
		||||
                0 => new Location($referencesUri, new Range(new Position(29,  5), new Position(29, 15)))
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestClass' => [
 | 
			
		||||
                0 => new Location($symbolsUri,    new Range(new Position(48, 13), new Position(48, 17))), // echo self::TEST_CLASS_CONST;
 | 
			
		||||
                1 => new Location($symbolsUri   , new Range(new Position(99, 25), new Position(99, 34))), // class ChildClass extends TestClass {}
 | 
			
		||||
                2 => new Location($referencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
 | 
			
		||||
                3 => new Location($referencesUri, new Range(new Position( 7,  0), new Position( 7,  9))), // TestClass::staticTestMethod();
 | 
			
		||||
                4 => new Location($referencesUri, new Range(new Position( 8,  5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                5 => new Location($referencesUri, new Range(new Position( 9,  5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
 | 
			
		||||
                6 => new Location($referencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param)
 | 
			
		||||
                7 => new Location($referencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass
 | 
			
		||||
                8 => new Location($referencesUri, new Range(new Position(39,  0), new Position(39,  9))), // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
                9 => new Location($useUri,        new Range(new Position( 4,  4), new Position( 4, 27))), // use TestNamespace\TestClass;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestChild' => [
 | 
			
		||||
                0 => new Location($referencesUri, new Range(new Position(42,  5), new Position(42, 25))), // echo $child->testProperty;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestInterface' => [
 | 
			
		||||
                0 => new Location($symbolsUri,    new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface
 | 
			
		||||
                1 => new Location($symbolsUri,    new Range(new Position(57, 48), new Position(57, 61))), // public function testMethod($testParameter): TestInterface
 | 
			
		||||
                2 => new Location($referencesUri, new Range(new Position(33, 20), new Position(33, 33)))  // if ($abc instanceof TestInterface)
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestClass::TEST_CLASS_CONST' => [
 | 
			
		||||
                0 => new Location($symbolsUri,    new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT
 | 
			
		||||
                1 => new Location($referencesUri, new Range(new Position( 9,  5), new Position( 9, 32)))
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestClass::testProperty' => [
 | 
			
		||||
                0 => new Location($symbolsUri,    new Range(new Position(59,  8), new Position(59, 27))), // $this->testProperty = $testParameter;
 | 
			
		||||
                1 => new Location($referencesUri, new Range(new Position( 6,  5), new Position( 6, 23))), // echo $obj->testProperty;
 | 
			
		||||
                2 => new Location($referencesUri, new Range(new Position(38,  0), new Position(38, 18))), // $obj->testProperty->testMethod();
 | 
			
		||||
                3 => new Location($referencesUri, new Range(new Position(39,  0), new Position(39, 49)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestClass::staticTestProperty' => [
 | 
			
		||||
                0 => new Location($referencesUri, new Range(new Position( 8,  16), new Position( 8, 35))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                1 => new Location($referencesUri, new Range(new Position(39,  11), new Position(39, 30)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestClass::staticTestMethod()' => [
 | 
			
		||||
                0 => new Location($referencesUri, new Range(new Position( 7,  0), new Position( 7, 27)))
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\TestClass::testMethod()' => [
 | 
			
		||||
                0 => new Location($referencesUri, new Range(new Position( 5,  0), new Position( 5, 16))), // $obj->testMethod();
 | 
			
		||||
                1 => new Location($referencesUri, new Range(new Position(38,  0), new Position(38, 30))), // $obj->testProperty->testMethod();
 | 
			
		||||
                2 => new Location($referencesUri, new Range(new Position(42,  5), new Position(42, 23)))  // $child->testMethod();
 | 
			
		||||
            ],
 | 
			
		||||
            'TestNamespace\\test_function()' => [
 | 
			
		||||
                0 => new Location($referencesUri, new Range(new Position(10,  0), new Position(10, 13))),
 | 
			
		||||
                1 => new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
 | 
			
		||||
            ],
 | 
			
		||||
                // Namespaced
 | 
			
		||||
                'TestNamespace' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40))), // use function TestNamespace\test_function;
 | 
			
		||||
                    1 => new Location($useUri, new Range(new Position(4, 4), new Position(4, 27))), // use TestNamespace\TestClass;
 | 
			
		||||
                    2 => new Location($useUri, new Range(new Position(5, 4), new Position(5, 18)))  // use TestNamespace\{TestTrait, TestInterface};
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TEST_CONST' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(29, 5), new Position(29, 15)))
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestClass' => [
 | 
			
		||||
                    0 => new Location($symbolsUri, new Range(new Position(48, 13), new Position(48, 17))), // echo self::TEST_CLASS_CONST;
 | 
			
		||||
                    1 => new Location($symbolsUri, new Range(new Position(99, 25), new Position(99, 34))), // class ChildClass extends TestClass {}
 | 
			
		||||
                    2 => new Location($referencesUri, new Range(new Position(4, 11), new Position(4, 20))), // $obj = new TestClass();
 | 
			
		||||
                    3 => new Location($referencesUri, new Range(new Position(7, 0), new Position(7, 9))), // TestClass::staticTestMethod();
 | 
			
		||||
                    4 => new Location($referencesUri, new Range(new Position(8, 5), new Position(8, 14))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                    5 => new Location($referencesUri, new Range(new Position(9, 5), new Position(9, 14))), // TestClass::TEST_CLASS_CONST;
 | 
			
		||||
                    6 => new Location($referencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param)
 | 
			
		||||
                    7 => new Location($referencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass
 | 
			
		||||
                    8 => new Location($referencesUri, new Range(new Position(39, 0), new Position(39, 9))), // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
                    9 => new Location($useUri, new Range(new Position(4, 4), new Position(4, 27))), // use TestNamespace\TestClass;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestChild' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(42, 5), new Position(42, 25))), // echo $child->testProperty;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestInterface' => [
 | 
			
		||||
                    0 => new Location($symbolsUri, new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface
 | 
			
		||||
                    1 => new Location($symbolsUri, new Range(new Position(57, 48), new Position(57, 61))), // public function testMethod($testParameter): TestInterface
 | 
			
		||||
                    2 => new Location($referencesUri, new Range(new Position(33, 20), new Position(33, 33)))  // if ($abc instanceof TestInterface)
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestClass::TEST_CLASS_CONST' => [
 | 
			
		||||
                    0 => new Location($symbolsUri, new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT
 | 
			
		||||
                    1 => new Location($referencesUri, new Range(new Position(9, 5), new Position(9, 32)))
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestClass::testProperty' => [
 | 
			
		||||
                    0 => new Location($symbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter;
 | 
			
		||||
                    1 => new Location($referencesUri, new Range(new Position(6, 5), new Position(6, 23))), // echo $obj->testProperty;
 | 
			
		||||
                    2 => new Location($referencesUri, new Range(new Position(38, 0), new Position(38, 18))), // $obj->testProperty->testMethod();
 | 
			
		||||
                    3 => new Location($referencesUri, new Range(new Position(39, 0), new Position(39, 49)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestClass::staticTestProperty' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(8, 16), new Position(8, 35))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                    1 => new Location($referencesUri, new Range(new Position(39, 11), new Position(39, 30)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestClass::staticTestMethod()' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(7, 0), new Position(7, 27)))
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\TestClass::testMethod()' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(5, 0), new Position(5, 16))), // $obj->testMethod();
 | 
			
		||||
                    1 => new Location($referencesUri, new Range(new Position(38, 0), new Position(38, 30))), // $obj->testProperty->testMethod();
 | 
			
		||||
                    2 => new Location($referencesUri, new Range(new Position(42, 5), new Position(42, 23)))  // $child->testMethod();
 | 
			
		||||
                ],
 | 
			
		||||
                'TestNamespace\\test_function()' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))),
 | 
			
		||||
                    1 => new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
            // Global
 | 
			
		||||
            'TEST_DEFINE_CONSTANT' => [
 | 
			
		||||
                0 => new Location($globalSymbolsUri,    new Range(new Position(106, 6), new Position(106, 26)))
 | 
			
		||||
            ],
 | 
			
		||||
            'TEST_CONST' => [
 | 
			
		||||
                0 => new Location($referencesUri,       new Range(new Position(29,  5), new Position(29, 15))),
 | 
			
		||||
                1 => new Location($globalReferencesUri, new Range(new Position(29,  5), new Position(29, 15)))
 | 
			
		||||
            ],
 | 
			
		||||
            'TestClass' => [
 | 
			
		||||
                0 => new Location($globalSymbolsUri,    new Range(new Position(48, 13), new Position(48, 17))), // echo self::TEST_CLASS_CONST;
 | 
			
		||||
                1 => new Location($globalSymbolsUri,    new Range(new Position(99, 25), new Position(99, 34))), // class ChildClass extends TestClass {}
 | 
			
		||||
                2 => new Location($globalReferencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
 | 
			
		||||
                3 => new Location($globalReferencesUri, new Range(new Position( 7,  0), new Position( 7,  9))), // TestClass::staticTestMethod();
 | 
			
		||||
                4 => new Location($globalReferencesUri, new Range(new Position( 8,  5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                5 => new Location($globalReferencesUri, new Range(new Position( 9,  5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
 | 
			
		||||
                6 => new Location($globalReferencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param)
 | 
			
		||||
                7 => new Location($globalReferencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass
 | 
			
		||||
                8 => new Location($globalReferencesUri, new Range(new Position(39,  0), new Position(39,  9))), // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestChild' => [
 | 
			
		||||
                0 => new Location($globalReferencesUri, new Range(new Position(42,  5), new Position(42, 25))), // echo $child->testProperty;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestInterface' => [
 | 
			
		||||
                0 => new Location($globalSymbolsUri,    new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface
 | 
			
		||||
                1 => new Location($globalSymbolsUri,    new Range(new Position(57, 49), new Position(57, 61))), // public function testMethod($testParameter) : TestInterface
 | 
			
		||||
                2 => new Location($globalReferencesUri, new Range(new Position(33, 20), new Position(33, 33)))  // if ($abc instanceof TestInterface)
 | 
			
		||||
            ],
 | 
			
		||||
            'TestClass::TEST_CLASS_CONST' => [
 | 
			
		||||
                0 => new Location($globalSymbolsUri,    new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT
 | 
			
		||||
                1 => new Location($globalReferencesUri, new Range(new Position( 9,  5), new Position( 9, 32)))
 | 
			
		||||
            ],
 | 
			
		||||
            'TestClass::testProperty' => [
 | 
			
		||||
                0 => new Location($globalSymbolsUri,    new Range(new Position(59,  8), new Position(59, 27))), // $this->testProperty = $testParameter;
 | 
			
		||||
                1 => new Location($globalReferencesUri, new Range(new Position( 6,  5), new Position( 6, 23))), // echo $obj->testProperty;
 | 
			
		||||
                2 => new Location($globalReferencesUri, new Range(new Position(38,  0), new Position(38, 18))), // $obj->testProperty->testMethod();
 | 
			
		||||
                3 => new Location($globalReferencesUri, new Range(new Position(39,  0), new Position(39, 49)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestClass::staticTestProperty' => [
 | 
			
		||||
                0 => new Location($globalReferencesUri, new Range(new Position( 8,  16), new Position( 8, 35))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                1 => new Location($globalReferencesUri, new Range(new Position(39,  11), new Position(39, 30)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
            ],
 | 
			
		||||
            'TestClass::staticTestMethod()' => [
 | 
			
		||||
                0 => new Location($globalReferencesUri, new Range(new Position( 7,  0), new Position( 7, 27)))
 | 
			
		||||
            ],
 | 
			
		||||
            'TestClass::testMethod()' => [
 | 
			
		||||
                0 => new Location($globalReferencesUri, new Range(new Position( 5,  0), new Position( 5, 16))), // $obj->testMethod();
 | 
			
		||||
                1 => new Location($globalReferencesUri, new Range(new Position(38,  0), new Position(38, 30))), // $obj->testProperty->testMethod();
 | 
			
		||||
                2 => new Location($globalReferencesUri, new Range(new Position(42,  5), new Position(42, 23)))  // $child->testMethod();
 | 
			
		||||
            ],
 | 
			
		||||
            'test_function()' => [
 | 
			
		||||
                0 => new Location($globalReferencesUri, new Range(new Position(10,  0), new Position(10, 13))),
 | 
			
		||||
                1 => new Location($globalReferencesUri, new Range(new Position(31, 13), new Position(31, 40)))
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        // @codingStandardsIgnoreEnd
 | 
			
		||||
                // Global
 | 
			
		||||
                'TEST_DEFINE_CONSTANT' => [
 | 
			
		||||
                    0 => new Location($globalSymbolsUri, new Range(new Position(106, 6), new Position(106, 26)))
 | 
			
		||||
                ],
 | 
			
		||||
                'TEST_CONST' => [
 | 
			
		||||
                    0 => new Location($referencesUri, new Range(new Position(29, 5), new Position(29, 15))),
 | 
			
		||||
                    1 => new Location($globalReferencesUri, new Range(new Position(29, 5), new Position(29, 15)))
 | 
			
		||||
                ],
 | 
			
		||||
                'TestClass' => [
 | 
			
		||||
                    0 => new Location($globalSymbolsUri, new Range(new Position(48, 13), new Position(48, 17))), // echo self::TEST_CLASS_CONST;
 | 
			
		||||
                    1 => new Location($globalSymbolsUri, new Range(new Position(99, 25), new Position(99, 34))), // class ChildClass extends TestClass {}
 | 
			
		||||
                    2 => new Location($globalReferencesUri, new Range(new Position(4, 11), new Position(4, 20))), // $obj = new TestClass();
 | 
			
		||||
                    3 => new Location($globalReferencesUri, new Range(new Position(7, 0), new Position(7, 9))), // TestClass::staticTestMethod();
 | 
			
		||||
                    4 => new Location($globalReferencesUri, new Range(new Position(8, 5), new Position(8, 14))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                    5 => new Location($globalReferencesUri, new Range(new Position(9, 5), new Position(9, 14))), // TestClass::TEST_CLASS_CONST;
 | 
			
		||||
                    6 => new Location($globalReferencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param)
 | 
			
		||||
                    7 => new Location($globalReferencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass
 | 
			
		||||
                    8 => new Location($globalReferencesUri, new Range(new Position(39, 0), new Position(39, 9))), // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestChild' => [
 | 
			
		||||
                    0 => new Location($globalReferencesUri, new Range(new Position(42, 5), new Position(42, 25))), // echo $child->testProperty;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestInterface' => [
 | 
			
		||||
                    0 => new Location($globalSymbolsUri, new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface
 | 
			
		||||
                    1 => new Location($globalSymbolsUri, new Range(new Position(57, 49), new Position(57, 61))), // public function testMethod($testParameter) : TestInterface
 | 
			
		||||
                    2 => new Location($globalReferencesUri, new Range(new Position(33, 20), new Position(33, 33)))  // if ($abc instanceof TestInterface)
 | 
			
		||||
                ],
 | 
			
		||||
                'TestClass::TEST_CLASS_CONST' => [
 | 
			
		||||
                    0 => new Location($globalSymbolsUri, new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT
 | 
			
		||||
                    1 => new Location($globalReferencesUri, new Range(new Position(9, 5), new Position(9, 32)))
 | 
			
		||||
                ],
 | 
			
		||||
                'TestClass::testProperty' => [
 | 
			
		||||
                    0 => new Location($globalSymbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter;
 | 
			
		||||
                    1 => new Location($globalReferencesUri, new Range(new Position(6, 5), new Position(6, 23))), // echo $obj->testProperty;
 | 
			
		||||
                    2 => new Location($globalReferencesUri, new Range(new Position(38, 0), new Position(38, 18))), // $obj->testProperty->testMethod();
 | 
			
		||||
                    3 => new Location($globalReferencesUri, new Range(new Position(39, 0), new Position(39, 49)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestClass::staticTestProperty' => [
 | 
			
		||||
                    0 => new Location($globalReferencesUri, new Range(new Position(8, 16), new Position(8, 35))), // echo TestClass::$staticTestProperty;
 | 
			
		||||
                    1 => new Location($globalReferencesUri, new Range(new Position(39, 11), new Position(39, 30)))  // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
                ],
 | 
			
		||||
                'TestClass::staticTestMethod()' => [
 | 
			
		||||
                    0 => new Location($globalReferencesUri, new Range(new Position(7, 0), new Position(7, 27)))
 | 
			
		||||
                ],
 | 
			
		||||
                'TestClass::testMethod()' => [
 | 
			
		||||
                    0 => new Location($globalReferencesUri, new Range(new Position(5, 0), new Position(5, 16))), // $obj->testMethod();
 | 
			
		||||
                    1 => new Location($globalReferencesUri, new Range(new Position(38, 0), new Position(38, 30))), // $obj->testProperty->testMethod();
 | 
			
		||||
                    2 => new Location($globalReferencesUri, new Range(new Position(42, 5), new Position(42, 23)))  // $child->testMethod();
 | 
			
		||||
                ],
 | 
			
		||||
                'test_function()' => [
 | 
			
		||||
                    0 => new Location($globalReferencesUri, new Range(new Position(10, 0), new Position(10, 13))),
 | 
			
		||||
                    1 => new Location($globalReferencesUri, new Range(new Position(31, 13), new Position(31, 40)))
 | 
			
		||||
                ]
 | 
			
		||||
            ];
 | 
			
		||||
            // @codingStandardsIgnoreEnd
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function getDefinitionLocation(string $fqn): Location
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\Tests\Server\ServerTestCase;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
| 
						 | 
				
			
			@ -29,34 +30,40 @@ class GlobalFallbackTest extends ServerTestCase
 | 
			
		|||
 | 
			
		||||
    public function testClassDoesNotFallback()
 | 
			
		||||
    {
 | 
			
		||||
        // $obj = new TestClass();
 | 
			
		||||
        // Get definition for TestClass should not fall back to global
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier('global_fallback'),
 | 
			
		||||
            new Position(9, 16)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $obj = new TestClass();
 | 
			
		||||
            // Get definition for TestClass should not fall back to global
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier('global_fallback'),
 | 
			
		||||
                new Position(9, 16)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFallsBackForConstants()
 | 
			
		||||
    {
 | 
			
		||||
        // echo TEST_CONST;
 | 
			
		||||
        // Get definition for TEST_CONST
 | 
			
		||||
        $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);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TEST_CONST;
 | 
			
		||||
            // Get definition for TEST_CONST
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier('global_fallback'),
 | 
			
		||||
                new Position(6, 10)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Location('global_symbols', new Range(new Position(9, 6), new Position(9, 22))), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFallsBackForFunctions()
 | 
			
		||||
    {
 | 
			
		||||
        // test_function();
 | 
			
		||||
        // Get definition for test_function
 | 
			
		||||
        $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);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // test_function();
 | 
			
		||||
            // Get definition for test_function
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier('global_fallback'),
 | 
			
		||||
                new Position(5, 6)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Location('global_symbols', new Range(new Position(78, 0), new Position(81, 1))), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\Tests\Server\ServerTestCase;
 | 
			
		||||
use LanguageServerProtocol\{TextDocumentIdentifier, Position, Location, Range};
 | 
			
		||||
use function LanguageServer\pathToUri;
 | 
			
		||||
| 
						 | 
				
			
			@ -11,333 +12,389 @@ class GlobalTest extends ServerTestCase
 | 
			
		|||
{
 | 
			
		||||
    public function testDefinitionFileBeginning()
 | 
			
		||||
    {
 | 
			
		||||
        // |<?php
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
 | 
			
		||||
            new Position(0, 0)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // |<?php
 | 
			
		||||
            $result = yield $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(1, 0)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // namespace keyword
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
 | 
			
		||||
                new Position(1, 0)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForSelfKeyword()
 | 
			
		||||
    {
 | 
			
		||||
        // echo self::TEST_CLASS_CONST;
 | 
			
		||||
        // Get definition for self
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[0];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo self::TEST_CLASS_CONST;
 | 
			
		||||
            // Get definition for self
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForClassLike()
 | 
			
		||||
    {
 | 
			
		||||
        // $obj = new TestClass();
 | 
			
		||||
        // Get definition for TestClass
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[1];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $obj = new TestClass();
 | 
			
		||||
            // Get definition for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[1];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForClassOnStaticMethodCall()
 | 
			
		||||
    {
 | 
			
		||||
        // TestClass::staticTestMethod();
 | 
			
		||||
        // Get definition for TestClass
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[2];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // TestClass::staticTestMethod();
 | 
			
		||||
            // Get definition for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[2];
 | 
			
		||||
            $result = yield $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')[3];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TestClass::$staticTestProperty;
 | 
			
		||||
            // Get definition for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[3];
 | 
			
		||||
            $result = yield $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')[4];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // TestClass::TEST_CLASS_CONST;
 | 
			
		||||
            // Get definition for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[4];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // class TestClass implements TestInterface
 | 
			
		||||
            // Get definition for TestInterface
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestInterface')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForClassConstants()
 | 
			
		||||
    {
 | 
			
		||||
        // echo TestClass::TEST_CLASS_CONST;
 | 
			
		||||
        // Get definition for TEST_CLASS_CONST
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[1];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TestClass::TEST_CLASS_CONST;
 | 
			
		||||
            // Get definition for TEST_CLASS_CONST
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[1];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForClassConstantsOnSelf()
 | 
			
		||||
    {
 | 
			
		||||
        // echo self::TEST_CLASS_CONST;
 | 
			
		||||
        // Get definition for TEST_CLASS_CONST
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo self::TEST_CLASS_CONST;
 | 
			
		||||
            // Get definition for TEST_CLASS_CONST
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TEST_CONST;
 | 
			
		||||
            // Get definition for TEST_CONST
 | 
			
		||||
            $reference = $this->getReferenceLocations('TEST_CONST')[1];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::staticTestMethod()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // TestClass::staticTestMethod();
 | 
			
		||||
            // Get definition for staticTestMethod
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::staticTestMethod()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::staticTestProperty'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TestClass::$staticTestProperty;
 | 
			
		||||
            // Get definition for staticTestProperty
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::staticTestProperty'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $obj->testMethod();
 | 
			
		||||
            // Get definition for testMethod
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForMethodOnChildClass()
 | 
			
		||||
    {
 | 
			
		||||
        // $child->testMethod();
 | 
			
		||||
        // Get definition for testMethod
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::testMethod()')[2];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $child->testMethod();
 | 
			
		||||
            // Get definition for testMethod
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testMethod()')[2];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForProperties()
 | 
			
		||||
    {
 | 
			
		||||
        // echo $obj->testProperty;
 | 
			
		||||
        // Get definition for testProperty
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::testProperty')[1];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo $obj->testProperty;
 | 
			
		||||
            // Get definition for testProperty
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testProperty')[1];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForPropertiesOnThis()
 | 
			
		||||
    {
 | 
			
		||||
        // $this->testProperty = $testParameter;
 | 
			
		||||
        // Get definition for testProperty
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::testProperty')[0];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $this->testProperty = $testParameter;
 | 
			
		||||
            // Get definition for testProperty
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testProperty')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Location($uri, new Range(new Position(12, 0), new Position(12, 10))), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo $var;
 | 
			
		||||
            // Get definition for $var
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
            $result = yield $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);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForParamTypeHints()
 | 
			
		||||
    {
 | 
			
		||||
        // function whatever(TestClass $param) {
 | 
			
		||||
        // Get definition for TestClass
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[5];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // function whatever(TestClass $param) {
 | 
			
		||||
            // Get definition for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[5];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForReturnTypeHints()
 | 
			
		||||
    {
 | 
			
		||||
        // function whatever(TestClass $param): TestClass {
 | 
			
		||||
        // Get definition for TestClass
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[6];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // function whatever(TestClass $param): TestClass {
 | 
			
		||||
            // Get definition for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[6];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForMethodReturnTypeHints()
 | 
			
		||||
    {
 | 
			
		||||
        // public function testMethod($testParameter): TestInterface
 | 
			
		||||
        // Get definition for TestInterface
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestInterface')[1];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // public function testMethod($testParameter): TestInterface
 | 
			
		||||
            // Get definition for TestInterface
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestInterface')[1];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Location($uri, new Range(new Position(21, 18), new Position(21, 34))), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo $param;
 | 
			
		||||
            // Get definition for $param
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
            $result = yield $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);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Location($uri, new Range(new Position(25, 22), new Position(25, 26))), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo $var;
 | 
			
		||||
            // Get definition for $var
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
            $result = yield $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);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // test_function();
 | 
			
		||||
            // Get definition for test_function
 | 
			
		||||
            $reference = $this->getReferenceLocations('test_function()')[0];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForUseFunctions()
 | 
			
		||||
    {
 | 
			
		||||
        // use function test_function;
 | 
			
		||||
        // Get definition for test_function
 | 
			
		||||
        $reference = $this->getReferenceLocations('test_function()')[1];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // use function test_function;
 | 
			
		||||
            // Get definition for test_function
 | 
			
		||||
            $reference = $this->getReferenceLocations('test_function()')[1];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForInstanceOf()
 | 
			
		||||
    {
 | 
			
		||||
        // if ($abc instanceof TestInterface) {
 | 
			
		||||
        // Get definition for TestInterface
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestInterface')[2];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // if ($abc instanceof TestInterface) {
 | 
			
		||||
            // Get definition for TestInterface
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestInterface')[2];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForNestedMethodCall()
 | 
			
		||||
    {
 | 
			
		||||
        // $obj->testProperty->testMethod();
 | 
			
		||||
        // Get definition for testMethod
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::testMethod()')[1];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $obj->testProperty->testMethod();
 | 
			
		||||
            // Get definition for testMethod
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testMethod()')[1];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForPropertyFetchOnArrayDimFetch()
 | 
			
		||||
    {
 | 
			
		||||
        // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
        // Get definition for testProperty
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::testProperty')[3];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // TestClass::$staticTestProperty[123]->testProperty;
 | 
			
		||||
            // Get definition for testProperty
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testProperty')[3];
 | 
			
		||||
            $result = yield $this->textDocument->definition(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServerProtocol\{TextDocumentIdentifier, Location};
 | 
			
		||||
use function LanguageServer\pathToUri;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -20,37 +21,43 @@ class NamespacedTest extends GlobalTest
 | 
			
		|||
 | 
			
		||||
    public function testDefinitionForConstants()
 | 
			
		||||
    {
 | 
			
		||||
        // echo TEST_CONST;
 | 
			
		||||
        // Get definition for TEST_CONST
 | 
			
		||||
        $reference = $this->getReferenceLocations('TEST_CONST')[0];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
 | 
			
		||||
        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);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForClassLikeUseStatement()
 | 
			
		||||
    {
 | 
			
		||||
        // use TestNamespace\TestClass;
 | 
			
		||||
        // Get definition for TestClass
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[7];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        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);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDefinitionForClassLikeGroupUseStatement()
 | 
			
		||||
    {
 | 
			
		||||
        // use TestNamespace\{TestTrait, TestInterface};
 | 
			
		||||
        // Get definition for TestInterface
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[1];
 | 
			
		||||
        $result = $this->textDocument->definition(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
 | 
			
		||||
        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);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
| 
						 | 
				
			
			@ -21,21 +22,23 @@ class DidChangeTest extends TestCase
 | 
			
		|||
{
 | 
			
		||||
    public function test()
 | 
			
		||||
    {
 | 
			
		||||
        $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
 | 
			
		||||
        $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
        $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
        $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
 | 
			
		||||
        $textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
        $phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n");
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
 | 
			
		||||
            $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
            $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
            $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
 | 
			
		||||
            $textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
            $phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n");
 | 
			
		||||
 | 
			
		||||
        $identifier = new VersionedTextDocumentIdentifier('whatever');
 | 
			
		||||
        $changeEvent = new TextDocumentContentChangeEvent();
 | 
			
		||||
        $changeEvent->range = new Range(new Position(0, 0), new Position(9999, 9999));
 | 
			
		||||
        $changeEvent->rangeLength = 9999;
 | 
			
		||||
        $changeEvent->text = "<?php\necho 'Goodbye, World'\n";
 | 
			
		||||
            $identifier = new VersionedTextDocumentIdentifier('whatever');
 | 
			
		||||
            $changeEvent = new TextDocumentContentChangeEvent();
 | 
			
		||||
            $changeEvent->range = new Range(new Position(0, 0), new Position(9999, 9999));
 | 
			
		||||
            $changeEvent->rangeLength = 9999;
 | 
			
		||||
            $changeEvent->text = "<?php\necho 'Goodbye, World'\n";
 | 
			
		||||
 | 
			
		||||
        $textDocument->didChange($identifier, [$changeEvent]);
 | 
			
		||||
            yield $textDocument->didChange($identifier, [$changeEvent]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals("<?php\necho 'Goodbye, World'\n", $phpDocument->getContent());
 | 
			
		||||
            $this->assertEquals("<?php\necho 'Goodbye, World'\n", $phpDocument->getContent());
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
| 
						 | 
				
			
			@ -16,22 +17,24 @@ class DidCloseTest extends TestCase
 | 
			
		|||
{
 | 
			
		||||
    public function test()
 | 
			
		||||
    {
 | 
			
		||||
        $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
 | 
			
		||||
        $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
        $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
        $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
 | 
			
		||||
        $textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
        $phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n");
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
 | 
			
		||||
            $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
            $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
            $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
 | 
			
		||||
            $textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
            $phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n");
 | 
			
		||||
 | 
			
		||||
        $textDocumentItem = new TextDocumentItem();
 | 
			
		||||
        $textDocumentItem->uri = 'whatever';
 | 
			
		||||
        $textDocumentItem->languageId = 'php';
 | 
			
		||||
        $textDocumentItem->version = 1;
 | 
			
		||||
        $textDocumentItem->text = 'hello world';
 | 
			
		||||
        $textDocument->didOpen($textDocumentItem);
 | 
			
		||||
            $textDocumentItem = new TextDocumentItem();
 | 
			
		||||
            $textDocumentItem->uri = 'whatever';
 | 
			
		||||
            $textDocumentItem->languageId = 'php';
 | 
			
		||||
            $textDocumentItem->version = 1;
 | 
			
		||||
            $textDocumentItem->text = 'hello world';
 | 
			
		||||
            $textDocument->didOpen($textDocumentItem);
 | 
			
		||||
 | 
			
		||||
        $textDocument->didClose(new TextDocumentIdentifier($textDocumentItem->uri));
 | 
			
		||||
            $textDocument->didClose(new TextDocumentIdentifier($textDocumentItem->uri));
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($loader->isOpen($textDocumentItem->uri));
 | 
			
		||||
            $this->assertFalse($loader->isOpen($textDocumentItem->uri));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\Tests\Server\ServerTestCase;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\{Server, LanguageClient, Project};
 | 
			
		||||
| 
						 | 
				
			
			@ -13,29 +14,31 @@ class DocumentSymbolTest extends ServerTestCase
 | 
			
		|||
{
 | 
			
		||||
    public function test()
 | 
			
		||||
    {
 | 
			
		||||
        // Request symbols
 | 
			
		||||
        $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
 | 
			
		||||
        $result = $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri))->wait();
 | 
			
		||||
        // @codingStandardsIgnoreStart
 | 
			
		||||
        $this->assertEquals([
 | 
			
		||||
            new SymbolInformation('TestNamespace',      SymbolKind::NAMESPACE,   $this->getDefinitionLocation('TestNamespace'),                                ''),
 | 
			
		||||
            new SymbolInformation('TEST_CONST',         SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestNamespace\\TEST_CONST'),                    'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('TestClass',          SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\TestClass'),                     'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('TEST_CLASS_CONST',   SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'),   'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('staticTestProperty', SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('testProperty',       SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'),       'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('staticTestMethod',   SymbolKind::METHOD,      $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('testMethod',         SymbolKind::METHOD,      $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'),       'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('TestTrait',          SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\TestTrait'),                     'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('TestInterface',      SymbolKind::INTERFACE,   $this->getDefinitionLocation('TestNamespace\\TestInterface'),                 'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('test_function',      SymbolKind::FUNCTION,    $this->getDefinitionLocation('TestNamespace\\test_function()'),               'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('ChildClass',         SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\ChildClass'),                    'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('Example',            SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\Example'),                       'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('__construct',        SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__construct'),          'TestNamespace\\Example'),
 | 
			
		||||
            new SymbolInformation('__destruct',         SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__destruct'),           'TestNamespace\\Example'),
 | 
			
		||||
            new SymbolInformation('TestNamespace\\InnerNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('TestNamespace\\InnerNamespace'),       'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('InnerClass',         SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\InnerNamespace\\InnerClass'),    'TestNamespace\\InnerNamespace'),
 | 
			
		||||
        ], $result);
 | 
			
		||||
        // @codingStandardsIgnoreEnd
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // Request symbols
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
 | 
			
		||||
            $result = yield $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri));
 | 
			
		||||
            // @codingStandardsIgnoreStart
 | 
			
		||||
            $this->assertEquals([
 | 
			
		||||
                new SymbolInformation('TestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('TestNamespace'), ''),
 | 
			
		||||
                new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('staticTestProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('testProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\ChildClass'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('Example', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\Example'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('__construct', SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__construct'), 'TestNamespace\\Example'),
 | 
			
		||||
                new SymbolInformation('__destruct', SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__destruct'), 'TestNamespace\\Example'),
 | 
			
		||||
                new SymbolInformation('TestNamespace\\InnerNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('TestNamespace\\InnerNamespace'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('InnerClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\InnerNamespace\\InnerClass'), 'TestNamespace\\InnerNamespace'),
 | 
			
		||||
            ], $result);
 | 
			
		||||
            // @codingStandardsIgnoreEnd
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\Tests\Server\ServerTestCase;
 | 
			
		||||
use LanguageServer\{Server, LanguageClient, Project};
 | 
			
		||||
| 
						 | 
				
			
			@ -13,206 +14,241 @@ class HoverTest extends ServerTestCase
 | 
			
		|||
{
 | 
			
		||||
    public function testHoverForClassLike()
 | 
			
		||||
    {
 | 
			
		||||
        // $obj = new TestClass();
 | 
			
		||||
        // Get hover for TestClass
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[1];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
 | 
			
		||||
            'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
 | 
			
		||||
            'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
 | 
			
		||||
            'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
 | 
			
		||||
            'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
 | 
			
		||||
            'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
 | 
			
		||||
            'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $obj = new TestClass();
 | 
			
		||||
            // Get hover for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[1];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
 | 
			
		||||
                'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
 | 
			
		||||
                'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
 | 
			
		||||
                'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
 | 
			
		||||
                'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
 | 
			
		||||
                'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
 | 
			
		||||
                'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForClassLikeDefinition()
 | 
			
		||||
    {
 | 
			
		||||
        // class TestClass implements TestInterface
 | 
			
		||||
        // Get hover for TestClass
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TestClass');
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
 | 
			
		||||
            'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
 | 
			
		||||
            'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
 | 
			
		||||
            'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
 | 
			
		||||
            'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
 | 
			
		||||
            'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
 | 
			
		||||
            'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
 | 
			
		||||
        ], $definition->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // class TestClass implements TestInterface
 | 
			
		||||
            // Get hover for TestClass
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TestClass');
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
 | 
			
		||||
                'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
 | 
			
		||||
                'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
 | 
			
		||||
                'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
 | 
			
		||||
                'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
 | 
			
		||||
                'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
 | 
			
		||||
                'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
 | 
			
		||||
            ], $definition->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForMethod()
 | 
			
		||||
    {
 | 
			
		||||
        // $obj->testMethod();
 | 
			
		||||
        // Get hover for testMethod
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\npublic function testMethod(\$testParameter): TestInterface"),
 | 
			
		||||
            'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $obj->testMethod();
 | 
			
		||||
            // Get hover for testMethod
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\npublic function testMethod(\$testParameter): TestInterface"),
 | 
			
		||||
                'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForProperty()
 | 
			
		||||
    {
 | 
			
		||||
        // echo $obj->testProperty;
 | 
			
		||||
        // Get hover for testProperty
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::testProperty')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\npublic \$testProperty;"),
 | 
			
		||||
            'Reprehenderit magna velit mollit ipsum do.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo $obj->testProperty;
 | 
			
		||||
            // Get hover for testProperty
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::testProperty')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\npublic \$testProperty;"),
 | 
			
		||||
                'Reprehenderit magna velit mollit ipsum do.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForStaticMethod()
 | 
			
		||||
    {
 | 
			
		||||
        // TestClass::staticTestMethod();
 | 
			
		||||
        // Get hover for staticTestMethod
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\npublic static function staticTestMethod()"),
 | 
			
		||||
            'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // TestClass::staticTestMethod();
 | 
			
		||||
            // Get hover for staticTestMethod
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\npublic static function staticTestMethod()"),
 | 
			
		||||
                'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForStaticProperty()
 | 
			
		||||
    {
 | 
			
		||||
        // echo TestClass::staticTestProperty;
 | 
			
		||||
        // Get hover for staticTestProperty
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\npublic static \$staticTestProperty;"),
 | 
			
		||||
            'Lorem excepteur officia sit anim velit veniam enim.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TestClass::staticTestProperty;
 | 
			
		||||
            // Get hover for staticTestProperty
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\npublic static \$staticTestProperty;"),
 | 
			
		||||
                'Lorem excepteur officia sit anim velit veniam enim.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForClassConstant()
 | 
			
		||||
    {
 | 
			
		||||
        // echo TestClass::TEST_CLASS_CONST;
 | 
			
		||||
        // Get hover for TEST_CLASS_CONST
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\nconst TEST_CLASS_CONST = 123;"),
 | 
			
		||||
            'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TestClass::TEST_CLASS_CONST;
 | 
			
		||||
            // Get hover for TEST_CLASS_CONST
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\nconst TEST_CLASS_CONST = 123;"),
 | 
			
		||||
                'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForFunction()
 | 
			
		||||
    {
 | 
			
		||||
        // test_function();
 | 
			
		||||
        // Get hover for test_function
 | 
			
		||||
        $reference = $this->getReferenceLocations('test_function()')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\nfunction test_function()"),
 | 
			
		||||
            'Officia aliquip adipisicing et nulla et laboris dolore labore.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // test_function();
 | 
			
		||||
            // Get hover for test_function
 | 
			
		||||
            $reference = $this->getReferenceLocations('test_function()')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\nfunction test_function()"),
 | 
			
		||||
                'Officia aliquip adipisicing et nulla et laboris dolore labore.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForConstant()
 | 
			
		||||
    {
 | 
			
		||||
        // echo TEST_CONST;
 | 
			
		||||
        // Get hover for TEST_CONST
 | 
			
		||||
        $reference = $this->getReferenceLocations('TEST_CONST')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\nconst TEST_CONST = 123;"),
 | 
			
		||||
            'Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo TEST_CONST;
 | 
			
		||||
            // Get hover for TEST_CONST
 | 
			
		||||
            $reference = $this->getReferenceLocations('TEST_CONST')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\nconst TEST_CONST = 123;"),
 | 
			
		||||
                'Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForGlobalConstant()
 | 
			
		||||
    {
 | 
			
		||||
        // print TEST_DEFINE_CONSTANT ? 'true' : 'false';
 | 
			
		||||
        // Get hover for TEST_DEFINE_CONSTANT
 | 
			
		||||
        $reference = $this->getReferenceLocations('TEST_DEFINE_CONSTANT')[0];
 | 
			
		||||
        $result = $this->textDocument->hover(
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        // TODO - should pretty print with fqns, like \define, \false. Not yet supported by tolerant-php-parser
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\ndefine('TEST_DEFINE_CONSTANT', false)"),
 | 
			
		||||
            'Lorem ipsum dolor sit amet, consectetur.'
 | 
			
		||||
        ], $reference->range), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // print TEST_DEFINE_CONSTANT ? 'true' : 'false';
 | 
			
		||||
            // Get hover for TEST_DEFINE_CONSTANT
 | 
			
		||||
            $reference = $this->getReferenceLocations('TEST_DEFINE_CONSTANT')[0];
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->end
 | 
			
		||||
            );
 | 
			
		||||
            // TODO - should pretty print with fqns, like \define, \false. Not yet supported by tolerant-php-parser
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\ndefine('TEST_DEFINE_CONSTANT', false)"),
 | 
			
		||||
                'Lorem ipsum dolor sit amet, consectetur.'
 | 
			
		||||
            ], $reference->range), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForVariable()
 | 
			
		||||
    {
 | 
			
		||||
        // echo $var;
 | 
			
		||||
        // Get hover for $var
 | 
			
		||||
        $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
 | 
			
		||||
        $result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(13, 7))->wait();
 | 
			
		||||
        $this->assertEquals(new Hover(
 | 
			
		||||
            [new MarkedString('php', "<?php\n\$var = 123")],
 | 
			
		||||
            new Range(new Position(13, 5), new Position(13, 9))
 | 
			
		||||
        ), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo $var;
 | 
			
		||||
            // Get hover for $var
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($uri),
 | 
			
		||||
                new Position(13, 7)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover(
 | 
			
		||||
                [new MarkedString('php', "<?php\n\$var = 123")],
 | 
			
		||||
                new Range(new Position(13, 5), new Position(13, 9))
 | 
			
		||||
            ), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForParam()
 | 
			
		||||
    {
 | 
			
		||||
        // echo $param;
 | 
			
		||||
        // Get hover for $param
 | 
			
		||||
        $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
 | 
			
		||||
        $result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(22, 11))->wait();
 | 
			
		||||
        $this->assertEquals(new Hover(
 | 
			
		||||
            [
 | 
			
		||||
                new MarkedString('php', "<?php\nTestClass \$param"),
 | 
			
		||||
                'Adipisicing non non cillum sint incididunt cillum enim mollit.'
 | 
			
		||||
            ],
 | 
			
		||||
            new Range(new Position(22, 9), new Position(22, 15))
 | 
			
		||||
        ), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // echo $param;
 | 
			
		||||
            // Get hover for $param
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($uri),
 | 
			
		||||
                new Position(22, 11)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover(
 | 
			
		||||
                [
 | 
			
		||||
                    new MarkedString('php', "<?php\nTestClass \$param"),
 | 
			
		||||
                    'Adipisicing non non cillum sint incididunt cillum enim mollit.'
 | 
			
		||||
                ],
 | 
			
		||||
                new Range(new Position(22, 9), new Position(22, 15))
 | 
			
		||||
            ), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHoverForThis()
 | 
			
		||||
    {
 | 
			
		||||
        // $this;
 | 
			
		||||
        // Get hover for $this
 | 
			
		||||
        $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_symbols.php'));
 | 
			
		||||
        $result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(59, 11))->wait();
 | 
			
		||||
        $this->assertEquals(new Hover([
 | 
			
		||||
            new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
 | 
			
		||||
            'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
 | 
			
		||||
            'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
 | 
			
		||||
            'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
 | 
			
		||||
            'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
 | 
			
		||||
            'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
 | 
			
		||||
            'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
 | 
			
		||||
        ], new Range(new Position(59, 8), new Position(59, 13))), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $this;
 | 
			
		||||
            // Get hover for $this
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_symbols.php'));
 | 
			
		||||
            $result = yield $this->textDocument->hover(
 | 
			
		||||
                new TextDocumentIdentifier($uri),
 | 
			
		||||
                new Position(59, 11)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(new Hover([
 | 
			
		||||
                new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
 | 
			
		||||
                'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
 | 
			
		||||
                'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
 | 
			
		||||
                'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
 | 
			
		||||
                'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
 | 
			
		||||
                'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
 | 
			
		||||
                'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
 | 
			
		||||
            ], new Range(new Position(59, 8), new Position(59, 13))), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,18 +1,18 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
    Server, Client, LanguageClient, ClientHandler, PhpDocumentLoader, DefinitionResolver
 | 
			
		||||
};
 | 
			
		||||
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
 | 
			
		||||
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
 | 
			
		||||
use LanguageServerProtocol\{TextDocumentItem, DiagnosticSeverity};
 | 
			
		||||
use Sabre\Event\Promise;
 | 
			
		||||
use Amp\Deferred;
 | 
			
		||||
use Amp\Delayed;
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use JsonMapper;
 | 
			
		||||
use LanguageServer\{Client, ClientHandler, DefinitionResolver, LanguageClient, PhpDocumentLoader, Server};
 | 
			
		||||
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
 | 
			
		||||
use LanguageServer\Index\{DependenciesIndex, Index, ProjectIndex};
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServerProtocol\{DiagnosticSeverity, TextDocumentItem};
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
 | 
			
		||||
class ParseErrorsTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -21,22 +21,31 @@ class ParseErrorsTest extends TestCase
 | 
			
		|||
     */
 | 
			
		||||
    private $textDocument;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Deferred
 | 
			
		||||
     */
 | 
			
		||||
    private $args;
 | 
			
		||||
 | 
			
		||||
    public function setUp()
 | 
			
		||||
    {
 | 
			
		||||
        $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
        $client->textDocument = new class($this->args) extends Client\TextDocument {
 | 
			
		||||
        $this->args = new Deferred();
 | 
			
		||||
        $client->textDocument = new class($this->args) extends Client\TextDocument
 | 
			
		||||
        {
 | 
			
		||||
            /** @var Deferred */
 | 
			
		||||
            private $args;
 | 
			
		||||
            public function __construct(&$args)
 | 
			
		||||
 | 
			
		||||
            public function __construct($args)
 | 
			
		||||
            {
 | 
			
		||||
                parent::__construct(new ClientHandler(new MockProtocolStream, new MockProtocolStream), new JsonMapper);
 | 
			
		||||
                $this->args = &$args;
 | 
			
		||||
                $this->args = $args;
 | 
			
		||||
            }
 | 
			
		||||
            public function publishDiagnostics(string $uri, array $diagnostics): Promise
 | 
			
		||||
 | 
			
		||||
            public function publishDiagnostics(string $uri, array $diagnostics): \Generator
 | 
			
		||||
            {
 | 
			
		||||
                $this->args = func_get_args();
 | 
			
		||||
                return Promise\resolve(null);
 | 
			
		||||
                $this->args->resolve(func_get_args());
 | 
			
		||||
                yield new Delayed(0);
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
 | 
			
		||||
| 
						 | 
				
			
			@ -57,98 +66,102 @@ class ParseErrorsTest extends TestCase
 | 
			
		|||
 | 
			
		||||
    public function testParseErrorsArePublishedAsDiagnostics()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openFile(__DIR__ . '/../../../fixtures/invalid_file.php');
 | 
			
		||||
        $this->assertEquals([
 | 
			
		||||
            'whatever',
 | 
			
		||||
            [[
 | 
			
		||||
                'range' => [
 | 
			
		||||
                    'start' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 9
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $this->openFile(__DIR__ . '/../../../fixtures/invalid_file.php');
 | 
			
		||||
            $this->assertEquals([
 | 
			
		||||
                'whatever',
 | 
			
		||||
                [[
 | 
			
		||||
                    'range' => [
 | 
			
		||||
                        'start' => [
 | 
			
		||||
                            'line' => 2,
 | 
			
		||||
                            'character' => 9
 | 
			
		||||
                        ],
 | 
			
		||||
                        'end' => [
 | 
			
		||||
                            'line' => 2,
 | 
			
		||||
                            'character' => 9
 | 
			
		||||
                        ]
 | 
			
		||||
                    ],
 | 
			
		||||
                    'end' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 9
 | 
			
		||||
                    ]
 | 
			
		||||
                    'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                    'code' => null,
 | 
			
		||||
                    'source' => 'php',
 | 
			
		||||
                    'message' => "'Name' expected."
 | 
			
		||||
                ],
 | 
			
		||||
                'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                'code' => null,
 | 
			
		||||
                'source' => 'php',
 | 
			
		||||
                'message' => "'Name' expected."
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'range' => [
 | 
			
		||||
                    'start' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 9
 | 
			
		||||
                    [
 | 
			
		||||
                        'range' => [
 | 
			
		||||
                            'start' => [
 | 
			
		||||
                                'line' => 2,
 | 
			
		||||
                                'character' => 9
 | 
			
		||||
                            ],
 | 
			
		||||
                            'end' => [
 | 
			
		||||
                                'line' => 2,
 | 
			
		||||
                                'character' => 9
 | 
			
		||||
                            ]
 | 
			
		||||
                        ],
 | 
			
		||||
                        'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                        'code' => null,
 | 
			
		||||
                        'source' => 'php',
 | 
			
		||||
                        'message' => "'{' expected."
 | 
			
		||||
                    ],
 | 
			
		||||
                    'end' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 9
 | 
			
		||||
                    ]
 | 
			
		||||
                ],
 | 
			
		||||
                'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                'code' => null,
 | 
			
		||||
                'source' => 'php',
 | 
			
		||||
                'message' => "'{' expected."
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'range' => [
 | 
			
		||||
                    'start' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 9
 | 
			
		||||
                    [
 | 
			
		||||
                        'range' => [
 | 
			
		||||
                            'start' => [
 | 
			
		||||
                                'line' => 2,
 | 
			
		||||
                                'character' => 9
 | 
			
		||||
                            ],
 | 
			
		||||
                            'end' => [
 | 
			
		||||
                                'line' => 2,
 | 
			
		||||
                                'character' => 9
 | 
			
		||||
                            ]
 | 
			
		||||
                        ],
 | 
			
		||||
                        'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                        'code' => null,
 | 
			
		||||
                        'source' => 'php',
 | 
			
		||||
                        'message' => "'}' expected."
 | 
			
		||||
                    ],
 | 
			
		||||
                    'end' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 9
 | 
			
		||||
                    ]
 | 
			
		||||
                ],
 | 
			
		||||
                'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                'code' => null,
 | 
			
		||||
                'source' => 'php',
 | 
			
		||||
                'message' => "'}' expected."
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'range' => [
 | 
			
		||||
                    'start' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 15
 | 
			
		||||
                    ],
 | 
			
		||||
                    'end' => [
 | 
			
		||||
                        'line' => 2,
 | 
			
		||||
                        'character' => 15
 | 
			
		||||
                    ]
 | 
			
		||||
                ],
 | 
			
		||||
                'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                'code' => null,
 | 
			
		||||
                'source' => 'php',
 | 
			
		||||
                'message' => "'Name' expected."
 | 
			
		||||
            ]]
 | 
			
		||||
        ], json_decode(json_encode($this->args), true));
 | 
			
		||||
                    [
 | 
			
		||||
                        'range' => [
 | 
			
		||||
                            'start' => [
 | 
			
		||||
                                'line' => 2,
 | 
			
		||||
                                'character' => 15
 | 
			
		||||
                            ],
 | 
			
		||||
                            'end' => [
 | 
			
		||||
                                'line' => 2,
 | 
			
		||||
                                'character' => 15
 | 
			
		||||
                            ]
 | 
			
		||||
                        ],
 | 
			
		||||
                        'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                        'code' => null,
 | 
			
		||||
                        'source' => 'php',
 | 
			
		||||
                        'message' => "'Name' expected."
 | 
			
		||||
                    ]]
 | 
			
		||||
            ], json_decode(json_encode(yield $this->args->promise()), true));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseErrorsWithOnlyStartLine()
 | 
			
		||||
    {
 | 
			
		||||
        $this->markTestIncomplete('This diagnostic not yet implemented in tolerant-php-parser');
 | 
			
		||||
        $this->openFile(__DIR__ . '/../../../fixtures/namespace_not_first.php');
 | 
			
		||||
        $this->assertEquals([
 | 
			
		||||
            'whatever',
 | 
			
		||||
            [[
 | 
			
		||||
                'range' => [
 | 
			
		||||
                    'start' => [
 | 
			
		||||
                        'line' => 4,
 | 
			
		||||
                        'character' => 0
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $this->markTestIncomplete('This diagnostic not yet implemented in tolerant-php-parser');
 | 
			
		||||
            yield $this->openFile(__DIR__ . '/../../../fixtures/namespace_not_first.php');
 | 
			
		||||
            $this->assertEquals([
 | 
			
		||||
                'whatever',
 | 
			
		||||
                [[
 | 
			
		||||
                    'range' => [
 | 
			
		||||
                        'start' => [
 | 
			
		||||
                            'line' => 4,
 | 
			
		||||
                            'character' => 0
 | 
			
		||||
                        ],
 | 
			
		||||
                        'end' => [
 | 
			
		||||
                            'line' => 4,
 | 
			
		||||
                            'character' => 0
 | 
			
		||||
                        ]
 | 
			
		||||
                    ],
 | 
			
		||||
                    'end' => [
 | 
			
		||||
                        'line' => 4,
 | 
			
		||||
                        'character' => 0
 | 
			
		||||
                    ]
 | 
			
		||||
                ],
 | 
			
		||||
                'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                'code' => null,
 | 
			
		||||
                'source' => 'php',
 | 
			
		||||
                'message' => "Namespace declaration statement has to be the very first statement in the script"
 | 
			
		||||
            ]]
 | 
			
		||||
        ], json_decode(json_encode($this->args), true));
 | 
			
		||||
                    'severity' => DiagnosticSeverity::ERROR,
 | 
			
		||||
                    'code' => null,
 | 
			
		||||
                    'source' => 'php',
 | 
			
		||||
                    'message' => "Namespace declaration statement has to be the very first statement in the script"
 | 
			
		||||
                ]]
 | 
			
		||||
            ], json_decode(json_encode(yield $this->args->promise()), true));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument\References;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
    LanguageClient, PhpDocumentLoader, Server, DefinitionResolver
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -20,49 +21,55 @@ class GlobalFallbackTest extends ServerTestCase
 | 
			
		|||
{
 | 
			
		||||
    public function setUp()
 | 
			
		||||
    {
 | 
			
		||||
        $projectIndex         = new ProjectIndex(new Index, new DependenciesIndex);
 | 
			
		||||
        $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
 | 
			
		||||
        $projectIndex->setComplete();
 | 
			
		||||
        $definitionResolver   = new DefinitionResolver($projectIndex);
 | 
			
		||||
        $client               = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
        $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
        $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
 | 
			
		||||
        $this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
 | 
			
		||||
        $this->textDocument   = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
        $this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);
 | 
			
		||||
        $this->documentLoader->open('global_fallback', file_get_contents(__DIR__ . '/../../../../fixtures/global_fallback.php'));
 | 
			
		||||
        $this->documentLoader->open('global_symbols', file_get_contents(__DIR__ . '/../../../../fixtures/global_symbols.php'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testClassDoesNotFallback()
 | 
			
		||||
    {
 | 
			
		||||
        // class TestClass implements TestInterface
 | 
			
		||||
        // Get references for TestClass
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier('global_symbols'),
 | 
			
		||||
            new Position(6, 9)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // class TestClass implements TestInterface
 | 
			
		||||
            // Get references for TestClass
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier('global_symbols'),
 | 
			
		||||
                new Position(6, 9)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFallsBackForConstants()
 | 
			
		||||
    {
 | 
			
		||||
        // const TEST_CONST = 123;
 | 
			
		||||
        // Get references for TEST_CONST
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier('global_symbols'),
 | 
			
		||||
            new Position(9, 13)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // const TEST_CONST = 123;
 | 
			
		||||
            // Get references for TEST_CONST
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier('global_symbols'),
 | 
			
		||||
                new Position(9, 13)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFallsBackForFunctions()
 | 
			
		||||
    {
 | 
			
		||||
        // function test_function()
 | 
			
		||||
        // Get references for test_function
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier('global_symbols'),
 | 
			
		||||
            new Position(78, 16)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // function test_function()
 | 
			
		||||
            // Get references for test_function
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier('global_symbols'),
 | 
			
		||||
                new Position(78, 16)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument\References;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
 | 
			
		||||
use LanguageServer\Tests\Server\ServerTestCase;
 | 
			
		||||
use function LanguageServer\pathToUri;
 | 
			
		||||
| 
						 | 
				
			
			@ -11,191 +12,219 @@ class GlobalTest extends ServerTestCase
 | 
			
		|||
{
 | 
			
		||||
    public function testReferencesForClassLike()
 | 
			
		||||
    {
 | 
			
		||||
        // class TestClass implements TestInterface
 | 
			
		||||
        // Get references for TestClass
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TestClass');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // class TestClass implements TestInterface
 | 
			
		||||
            // Get references for TestClass
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TestClass');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TestClass'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForClassConstants()
 | 
			
		||||
    {
 | 
			
		||||
        // const TEST_CLASS_CONST = 123;
 | 
			
		||||
        // Get references for TEST_CLASS_CONST
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TestClass::TEST_CLASS_CONST'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // const TEST_CLASS_CONST = 123;
 | 
			
		||||
            // Get references for TEST_CLASS_CONST
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TestClass::TEST_CLASS_CONST'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForConstants()
 | 
			
		||||
    {
 | 
			
		||||
        // const TEST_CONST = 123;
 | 
			
		||||
        // Get references for TEST_CONST
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TEST_CONST');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TEST_CONST'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // const TEST_CONST = 123;
 | 
			
		||||
            // Get references for TEST_CONST
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TEST_CONST');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TEST_CONST'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForStaticMethods()
 | 
			
		||||
    {
 | 
			
		||||
        // public static function staticTestMethod()
 | 
			
		||||
        // Get references for staticTestMethod
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TestClass::staticTestMethod()');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // public static function staticTestMethod()
 | 
			
		||||
            // Get references for staticTestMethod
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TestClass::staticTestMethod()');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForStaticProperties()
 | 
			
		||||
    {
 | 
			
		||||
        // public static $staticTestProperty;
 | 
			
		||||
        // Get references for $staticTestProperty
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TestClass::staticTestProperty');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // public static $staticTestProperty;
 | 
			
		||||
            // Get references for $staticTestProperty
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TestClass::staticTestProperty');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForMethods()
 | 
			
		||||
    {
 | 
			
		||||
        // public function testMethod($testParameter)
 | 
			
		||||
        // Get references for testMethod
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TestClass::testMethod()');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TestClass::testMethod()'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // public function testMethod($testParameter)
 | 
			
		||||
            // Get references for testMethod
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TestClass::testMethod()');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TestClass::testMethod()'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForProperties()
 | 
			
		||||
    {
 | 
			
		||||
        // public $testProperty;
 | 
			
		||||
        // Get references for testProperty
 | 
			
		||||
        $definition = $this->getDefinitionLocation('TestClass::testProperty');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TestClass::testProperty'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // public $testProperty;
 | 
			
		||||
            // Get references for testProperty
 | 
			
		||||
            $definition = $this->getDefinitionLocation('TestClass::testProperty');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TestClass::testProperty'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForVariables()
 | 
			
		||||
    {
 | 
			
		||||
        // $var = 123;
 | 
			
		||||
        // Get definition for $var
 | 
			
		||||
        $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($uri),
 | 
			
		||||
            new Position(12, 3)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([
 | 
			
		||||
            new Location($uri, new Range(new Position(12, 0), new Position(12, 4))),
 | 
			
		||||
            new Location($uri, new Range(new Position(13, 5), new Position(13, 9))),
 | 
			
		||||
            new Location($uri, new Range(new Position(26, 9), new Position(26, 13)))
 | 
			
		||||
        ], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $var = 123;
 | 
			
		||||
            // Get definition for $var
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($uri),
 | 
			
		||||
                new Position(12, 3)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([
 | 
			
		||||
                new Location($uri, new Range(new Position(12, 0), new Position(12, 4))),
 | 
			
		||||
                new Location($uri, new Range(new Position(13, 5), new Position(13, 9))),
 | 
			
		||||
                new Location($uri, new Range(new Position(26, 9), new Position(26, 13)))
 | 
			
		||||
            ], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForFunctionParams()
 | 
			
		||||
    {
 | 
			
		||||
        // function whatever(TestClass $param): TestClass
 | 
			
		||||
        // Get references for $param
 | 
			
		||||
        $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($uri),
 | 
			
		||||
            new Position(21, 32)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([new Location($uri, new Range(new Position(22, 9), new Position(22, 15)))], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // function whatever(TestClass $param): TestClass
 | 
			
		||||
            // Get references for $param
 | 
			
		||||
            $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($uri),
 | 
			
		||||
                new Position(21, 32)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([new Location($uri, new Range(new Position(22, 9), new Position(22, 15)))], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForFunctions()
 | 
			
		||||
    {
 | 
			
		||||
        // function test_function()
 | 
			
		||||
        // Get references for test_function
 | 
			
		||||
        $referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
        $symbolsUri    = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
            new Position(78, 16)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([
 | 
			
		||||
            new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))),
 | 
			
		||||
            new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
 | 
			
		||||
        ], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // function test_function()
 | 
			
		||||
            // Get references for test_function
 | 
			
		||||
            $referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
 | 
			
		||||
            $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
                new Position(78, 16)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([
 | 
			
		||||
                new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))),
 | 
			
		||||
                new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
 | 
			
		||||
            ], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForReference()
 | 
			
		||||
    {
 | 
			
		||||
        // $obj = new TestClass();
 | 
			
		||||
        // Get references for TestClass
 | 
			
		||||
        $reference = $this->getReferenceLocations('TestClass')[1];
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
            $reference->range->start
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($this->getReferenceLocations('TestClass'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // $obj = new TestClass();
 | 
			
		||||
            // Get references for TestClass
 | 
			
		||||
            $reference = $this->getReferenceLocations('TestClass')[1];
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($reference->uri),
 | 
			
		||||
                $reference->range->start
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($this->getReferenceLocations('TestClass'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForUnusedClass()
 | 
			
		||||
    {
 | 
			
		||||
        // class UnusedClass
 | 
			
		||||
        // Get references for UnusedClass
 | 
			
		||||
        $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
            new Position(111, 10)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // class UnusedClass
 | 
			
		||||
            // Get references for UnusedClass
 | 
			
		||||
            $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
                new Position(111, 10)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForUnusedProperty()
 | 
			
		||||
    {
 | 
			
		||||
        // public $unusedProperty
 | 
			
		||||
        // Get references for unusedProperty
 | 
			
		||||
        $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
            new Position(113, 18)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // public $unusedProperty
 | 
			
		||||
            // Get references for unusedProperty
 | 
			
		||||
            $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
                new Position(113, 18)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReferencesForUnusedMethod()
 | 
			
		||||
    {
 | 
			
		||||
        // public function unusedMethod()
 | 
			
		||||
        // Get references for unusedMethod
 | 
			
		||||
        $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
            new Position(115, 26)
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals([], $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // public function unusedMethod()
 | 
			
		||||
            // Get references for unusedMethod
 | 
			
		||||
            $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($symbolsUri),
 | 
			
		||||
                new Position(115, 26)
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals([], $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument\References;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
 | 
			
		||||
use function LanguageServer\pathToUri;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -20,14 +21,16 @@ class NamespacedTest extends GlobalTest
 | 
			
		|||
 | 
			
		||||
    public function testReferencesForNamespaces()
 | 
			
		||||
    {
 | 
			
		||||
        // namespace TestNamespace;
 | 
			
		||||
        // Get references for TestNamespace
 | 
			
		||||
        $definition = parent::getDefinitionLocation('TestNamespace');
 | 
			
		||||
        $result = $this->textDocument->references(
 | 
			
		||||
            new ReferenceContext,
 | 
			
		||||
            new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
            $definition->range->end
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals(parent::getReferenceLocations('TestNamespace'), $result);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // namespace TestNamespace;
 | 
			
		||||
            // Get references for TestNamespace
 | 
			
		||||
            $definition = parent::getDefinitionLocation('TestNamespace');
 | 
			
		||||
            $result = yield $this->textDocument->references(
 | 
			
		||||
                new ReferenceContext,
 | 
			
		||||
                new TextDocumentIdentifier($definition->uri),
 | 
			
		||||
                $definition->range->end
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals(parent::getReferenceLocations('TestNamespace'), $result);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\TextDocument;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\{
 | 
			
		||||
| 
						 | 
				
			
			@ -50,13 +51,15 @@ class SignatureHelpTest extends TestCase
 | 
			
		|||
     */
 | 
			
		||||
    public function testSignatureHelp(Position $position, SignatureHelp $expectedSignature)
 | 
			
		||||
    {
 | 
			
		||||
        $callsUri = pathToUri(__DIR__ . '/../../../fixtures/signature_help/calls.php');
 | 
			
		||||
        $this->loader->open($callsUri, file_get_contents($callsUri));
 | 
			
		||||
        $signatureHelp = $this->textDocument->signatureHelp(
 | 
			
		||||
            new TextDocumentIdentifier($callsUri),
 | 
			
		||||
            $position
 | 
			
		||||
        )->wait();
 | 
			
		||||
        $this->assertEquals($expectedSignature, $signatureHelp);
 | 
			
		||||
        Loop::run(function () use ($position, $expectedSignature) {
 | 
			
		||||
            $callsUri = pathToUri(__DIR__ . '/../../../fixtures/signature_help/calls.php');
 | 
			
		||||
            $this->loader->open($callsUri, file_get_contents($callsUri));
 | 
			
		||||
            $signatureHelp = yield $this->textDocument->signatureHelp(
 | 
			
		||||
                new TextDocumentIdentifier($callsUri),
 | 
			
		||||
                $position
 | 
			
		||||
            );
 | 
			
		||||
            $this->assertEquals($expectedSignature, $signatureHelp);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function signatureHelpProvider(): array
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,42 +1,46 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\Workspace;
 | 
			
		||||
 | 
			
		||||
use Amp\Deferred;
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
 | 
			
		||||
use LanguageServer\{DefinitionResolver, LanguageClient, PhpDocumentLoader, Server};
 | 
			
		||||
use LanguageServer\{DefinitionResolver, Event\MessageEvent, LanguageClient, PhpDocumentLoader, Server};
 | 
			
		||||
use LanguageServer\Index\{DependenciesIndex, Index, ProjectIndex};
 | 
			
		||||
use LanguageServerProtocol\{FileChangeType, FileEvent};
 | 
			
		||||
use LanguageServer\Message;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\Tests\Server\ServerTestCase;
 | 
			
		||||
use LanguageServer\Server\Workspace;
 | 
			
		||||
use Sabre\Event\Loop;
 | 
			
		||||
 | 
			
		||||
class DidChangeWatchedFilesTest extends ServerTestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testDeletingFileClearsAllDiagnostics()
 | 
			
		||||
    {
 | 
			
		||||
        $client = new LanguageClient(new MockProtocolStream(), $writer = new MockProtocolStream());
 | 
			
		||||
        $projectIndex = new ProjectIndex($sourceIndex = new Index(), $dependenciesIndex = new DependenciesIndex());
 | 
			
		||||
        $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
        $loader = new PhpDocumentLoader(new FileSystemContentRetriever(), $projectIndex, $definitionResolver);
 | 
			
		||||
        $workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $loader, null);
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            $client = new LanguageClient(new MockProtocolStream(), $writer = new MockProtocolStream());
 | 
			
		||||
            $projectIndex = new ProjectIndex($sourceIndex = new Index(), $dependenciesIndex = new DependenciesIndex());
 | 
			
		||||
            $definitionResolver = new DefinitionResolver($projectIndex);
 | 
			
		||||
            $loader = new PhpDocumentLoader(new FileSystemContentRetriever(), $projectIndex, $definitionResolver);
 | 
			
		||||
            $workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $loader, null);
 | 
			
		||||
 | 
			
		||||
        $fileEvent = new FileEvent('my uri', FileChangeType::DELETED);
 | 
			
		||||
            $fileEvent = new FileEvent('my uri', FileChangeType::DELETED);
 | 
			
		||||
 | 
			
		||||
        $isDiagnosticsCleared = false;
 | 
			
		||||
        $writer->on('message', function (Message $message) use ($fileEvent, &$isDiagnosticsCleared) {
 | 
			
		||||
            if ($message->body->method === "textDocument/publishDiagnostics") {
 | 
			
		||||
                $this->assertEquals($message->body->params->uri, $fileEvent->uri);
 | 
			
		||||
                $this->assertEquals($message->body->params->diagnostics, []);
 | 
			
		||||
                $isDiagnosticsCleared = true;
 | 
			
		||||
            }
 | 
			
		||||
            $isDiagnosticsCleared = false;
 | 
			
		||||
            $deferred = new Deferred();
 | 
			
		||||
            $writer->addListener('message', function (MessageEvent $messageEvent) use ($deferred, $fileEvent, &$isDiagnosticsCleared) {
 | 
			
		||||
                $message = $messageEvent->getMessage();
 | 
			
		||||
                if ($message->body->method === "textDocument/publishDiagnostics") {
 | 
			
		||||
                    $this->assertEquals($message->body->params->uri, $fileEvent->uri);
 | 
			
		||||
                    $this->assertEquals($message->body->params->diagnostics, []);
 | 
			
		||||
                    $deferred->resolve(true);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            $workspace->didChangeWatchedFiles([$fileEvent]);
 | 
			
		||||
 | 
			
		||||
            $this->assertTrue(yield $deferred->promise(), "Deleting file should clear all diagnostics.");
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $workspace->didChangeWatchedFiles([$fileEvent]);
 | 
			
		||||
        Loop\tick(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($isDiagnosticsCleared, "Deleting file should clear all diagnostics.");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
<?php
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace LanguageServer\Tests\Server\Workspace;
 | 
			
		||||
 | 
			
		||||
use Amp\Loop;
 | 
			
		||||
use LanguageServer\Tests\MockProtocolStream;
 | 
			
		||||
use LanguageServer\Tests\Server\ServerTestCase;
 | 
			
		||||
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument};
 | 
			
		||||
| 
						 | 
				
			
			@ -24,65 +25,69 @@ class SymbolTest extends ServerTestCase
 | 
			
		|||
{
 | 
			
		||||
    public function testEmptyQueryReturnsAllSymbols()
 | 
			
		||||
    {
 | 
			
		||||
        // Request symbols
 | 
			
		||||
        $result = $this->workspace->symbol('')->wait();
 | 
			
		||||
        $referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // Request symbols
 | 
			
		||||
            $result = yield $this->workspace->symbol('');
 | 
			
		||||
            $referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
 | 
			
		||||
 | 
			
		||||
        // @codingStandardsIgnoreStart
 | 
			
		||||
        $this->assertEquals([
 | 
			
		||||
            new SymbolInformation('TestNamespace',          SymbolKind::NAMESPACE,   new Location($referencesUri, new Range(new Position(2, 0), new Position(2, 24))), ''),
 | 
			
		||||
            // Namespaced
 | 
			
		||||
            new SymbolInformation('TEST_CONST',             SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestNamespace\\TEST_CONST'),                    'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('TestClass',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\TestClass'),                     'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('TEST_CLASS_CONST',       SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'),   'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('staticTestProperty',     SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('testProperty',           SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'),       'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('staticTestMethod',       SymbolKind::METHOD,      $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('testMethod',             SymbolKind::METHOD,      $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'),       'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('TestTrait',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\TestTrait'),                     'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('TestInterface',          SymbolKind::INTERFACE,   $this->getDefinitionLocation('TestNamespace\\TestInterface'),                 'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('test_function',          SymbolKind::FUNCTION,    $this->getDefinitionLocation('TestNamespace\\test_function()'),               'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('ChildClass',             SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\ChildClass'),                    'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('Example',                SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\Example'),                       'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('__construct',            SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__construct'),          'TestNamespace\\Example'),
 | 
			
		||||
            new SymbolInformation('__destruct',             SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__destruct'),           'TestNamespace\\Example'),
 | 
			
		||||
            new SymbolInformation('TestNamespace\\InnerNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('TestNamespace\\InnerNamespace'),           'TestNamespace'),
 | 
			
		||||
            new SymbolInformation('InnerClass',             SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\InnerNamespace\\InnerClass'),    'TestNamespace\\InnerNamespace'),
 | 
			
		||||
            new SymbolInformation('whatever',               SymbolKind::FUNCTION,    $this->getDefinitionLocation('TestNamespace\\whatever()'),                    'TestNamespace'),
 | 
			
		||||
            // Global
 | 
			
		||||
            new SymbolInformation('TEST_CONST',             SymbolKind::CONSTANT,    $this->getDefinitionLocation('TEST_CONST'),                                   ''),
 | 
			
		||||
            new SymbolInformation('TestClass',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestClass'),                                    ''),
 | 
			
		||||
            new SymbolInformation('TEST_CLASS_CONST',       SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'),                  'TestClass'),
 | 
			
		||||
            new SymbolInformation('staticTestProperty',     SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestClass::staticTestProperty'),                'TestClass'),
 | 
			
		||||
            new SymbolInformation('testProperty',           SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestClass::testProperty'),                      'TestClass'),
 | 
			
		||||
            new SymbolInformation('staticTestMethod',       SymbolKind::METHOD,      $this->getDefinitionLocation('TestClass::staticTestMethod()'),                'TestClass'),
 | 
			
		||||
            new SymbolInformation('testMethod',             SymbolKind::METHOD,      $this->getDefinitionLocation('TestClass::testMethod()'),                      'TestClass'),
 | 
			
		||||
            new SymbolInformation('TestTrait',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestTrait'),                                    ''),
 | 
			
		||||
            new SymbolInformation('TestInterface',          SymbolKind::INTERFACE,   $this->getDefinitionLocation('TestInterface'),                                ''),
 | 
			
		||||
            new SymbolInformation('test_function',          SymbolKind::FUNCTION,    $this->getDefinitionLocation('test_function()'),                              ''),
 | 
			
		||||
            new SymbolInformation('ChildClass',             SymbolKind::CLASS_,      $this->getDefinitionLocation('ChildClass'),                                   ''),
 | 
			
		||||
            new SymbolInformation('TEST_DEFINE_CONSTANT',   SymbolKind::CONSTANT,    $this->getDefinitionLocation('TEST_DEFINE_CONSTANT'),                         ''),
 | 
			
		||||
            new SymbolInformation('UnusedClass',            SymbolKind::CLASS_,      $this->getDefinitionLocation('UnusedClass'),                                  ''),
 | 
			
		||||
            new SymbolInformation('unusedProperty',         SymbolKind::PROPERTY,    $this->getDefinitionLocation('UnusedClass::unusedProperty'),                  'UnusedClass'),
 | 
			
		||||
            new SymbolInformation('unusedMethod',           SymbolKind::METHOD,      $this->getDefinitionLocation('UnusedClass::unusedMethod'),                    'UnusedClass'),
 | 
			
		||||
            new SymbolInformation('whatever',               SymbolKind::FUNCTION,    $this->getDefinitionLocation('whatever()'),                                   ''),
 | 
			
		||||
            // @codingStandardsIgnoreStart
 | 
			
		||||
            $this->assertEquals([
 | 
			
		||||
                new SymbolInformation('TestNamespace', SymbolKind::NAMESPACE, new Location($referencesUri, new Range(new Position(2, 0), new Position(2, 24))), ''),
 | 
			
		||||
                // Namespaced
 | 
			
		||||
                new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('staticTestProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('testProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\ChildClass'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('Example', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\Example'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('__construct', SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__construct'), 'TestNamespace\\Example'),
 | 
			
		||||
                new SymbolInformation('__destruct', SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__destruct'), 'TestNamespace\\Example'),
 | 
			
		||||
                new SymbolInformation('TestNamespace\\InnerNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('TestNamespace\\InnerNamespace'), 'TestNamespace'),
 | 
			
		||||
                new SymbolInformation('InnerClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\InnerNamespace\\InnerClass'), 'TestNamespace\\InnerNamespace'),
 | 
			
		||||
                new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\whatever()'), 'TestNamespace'),
 | 
			
		||||
                // Global
 | 
			
		||||
                new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_CONST'), ''),
 | 
			
		||||
                new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestClass'), ''),
 | 
			
		||||
                new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), 'TestClass'),
 | 
			
		||||
                new SymbolInformation('staticTestProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestClass::staticTestProperty'), 'TestClass'),
 | 
			
		||||
                new SymbolInformation('testProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestClass::testProperty'), 'TestClass'),
 | 
			
		||||
                new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'),
 | 
			
		||||
                new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass'),
 | 
			
		||||
                new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestTrait'), ''),
 | 
			
		||||
                new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''),
 | 
			
		||||
                new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''),
 | 
			
		||||
                new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('ChildClass'), ''),
 | 
			
		||||
                new SymbolInformation('TEST_DEFINE_CONSTANT', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_DEFINE_CONSTANT'), ''),
 | 
			
		||||
                new SymbolInformation('UnusedClass', SymbolKind::CLASS_, $this->getDefinitionLocation('UnusedClass'), ''),
 | 
			
		||||
                new SymbolInformation('unusedProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('UnusedClass::unusedProperty'), 'UnusedClass'),
 | 
			
		||||
                new SymbolInformation('unusedMethod', SymbolKind::METHOD, $this->getDefinitionLocation('UnusedClass::unusedMethod'), 'UnusedClass'),
 | 
			
		||||
                new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), ''),
 | 
			
		||||
 | 
			
		||||
            new SymbolInformation('SecondTestNamespace',    SymbolKind::NAMESPACE,   $this->getDefinitionLocation('SecondTestNamespace'),                          ''),
 | 
			
		||||
        ], $result);
 | 
			
		||||
        // @codingStandardsIgnoreEnd
 | 
			
		||||
                new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), ''),
 | 
			
		||||
            ], $result);
 | 
			
		||||
            // @codingStandardsIgnoreEnd
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testQueryFiltersResults()
 | 
			
		||||
    {
 | 
			
		||||
        // Request symbols
 | 
			
		||||
        $result = $this->workspace->symbol('testmethod')->wait();
 | 
			
		||||
        // @codingStandardsIgnoreStart
 | 
			
		||||
        $this->assertEquals([
 | 
			
		||||
            new SymbolInformation('staticTestMethod',   SymbolKind::METHOD,    $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('testMethod',         SymbolKind::METHOD,    $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'),       'TestNamespace\\TestClass'),
 | 
			
		||||
            new SymbolInformation('staticTestMethod',   SymbolKind::METHOD,    $this->getDefinitionLocation('TestClass::staticTestMethod()'),                'TestClass'),
 | 
			
		||||
            new SymbolInformation('testMethod',         SymbolKind::METHOD,    $this->getDefinitionLocation('TestClass::testMethod()'),                      'TestClass')
 | 
			
		||||
        ], $result);
 | 
			
		||||
        // @codingStandardsIgnoreEnd
 | 
			
		||||
        Loop::run(function () {
 | 
			
		||||
            // Request symbols
 | 
			
		||||
            $result = yield $this->workspace->symbol('testmethod');
 | 
			
		||||
            // @codingStandardsIgnoreStart
 | 
			
		||||
            $this->assertEquals([
 | 
			
		||||
                new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
 | 
			
		||||
                new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'),
 | 
			
		||||
                new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass')
 | 
			
		||||
            ], $result);
 | 
			
		||||
            // @codingStandardsIgnoreEnd
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
use function LanguageServer\{pathToUri, timeout};
 | 
			
		||||
use function LanguageServer\{pathToUri};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,9 +5,6 @@
 | 
			
		|||
        ],
 | 
			
		||||
        "LanguageServer\\pathToUri()": [
 | 
			
		||||
            "./functionUse2.php"
 | 
			
		||||
        ],
 | 
			
		||||
        "LanguageServer\\timeout()": [
 | 
			
		||||
            "./functionUse2.php"
 | 
			
		||||
        ]
 | 
			
		||||
    },
 | 
			
		||||
    "definitions": []
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue