Add tests
parent
940eb9787d
commit
5b1b6bfabe
|
@ -5,10 +5,12 @@ namespace LanguageServer\Tests\Server;
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use LanguageServer\Tests\MockProtocolStream;
|
||||
use LanguageServer\{Server, LanguageClient, PhpDocumentLoader, DefinitionResolver};
|
||||
use LanguageServer\{Server, LanguageClient, PhpDocumentLoader, DefinitionResolver, Options, Indexer};
|
||||
use LanguageServer\Index\{ProjectIndex, StubsIndex, GlobalIndex, DependenciesIndex, Index};
|
||||
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
||||
use LanguageServer\Protocol\{Position, Location, Range, ClientCapabilities};
|
||||
use LanguageServer\FilesFinder\FileSystemFilesFinder;
|
||||
use LanguageServer\Cache\FileSystemCache;
|
||||
use function LanguageServer\pathToUri;
|
||||
use Sabre\Event\Promise;
|
||||
|
||||
|
@ -29,6 +31,10 @@ abstract class ServerTestCase extends TestCase
|
|||
*/
|
||||
protected $documentLoader;
|
||||
|
||||
protected $projectIndex;
|
||||
protected $input;
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* Map from FQN to Location of definition
|
||||
*
|
||||
|
@ -47,14 +53,22 @@ abstract class ServerTestCase extends TestCase
|
|||
{
|
||||
$sourceIndex = new Index;
|
||||
$dependenciesIndex = new DependenciesIndex;
|
||||
$projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
|
||||
$projectIndex->setComplete();
|
||||
$this->projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
|
||||
$this->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($projectIndex, $dependenciesIndex, $sourceIndex, null, $this->documentLoader);
|
||||
$rootPath = realpath(__DIR__ . '/../../fixtures/');
|
||||
$options = new Options;
|
||||
$filesFinder = new FileSystemFilesFinder;
|
||||
$cache = new FileSystemCache;
|
||||
|
||||
$this->input = new MockProtocolStream;
|
||||
$this->output = new MockProtocolStream;
|
||||
$definitionResolver = new DefinitionResolver($this->projectIndex);
|
||||
$client = new LanguageClient($this->input, $this->output);
|
||||
$this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $this->projectIndex, $definitionResolver);
|
||||
$this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $this->projectIndex);
|
||||
$indexer = new Indexer($filesFinder, $rootPath, $client, $cache, $dependenciesIndex, $sourceIndex, $this->documentLoader, null, null, $options);
|
||||
$this->workspace = new Server\Workspace($this->projectIndex, $dependenciesIndex, $sourceIndex, null, $this->documentLoader, null, $indexer, $options);
|
||||
|
||||
$globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_symbols.php'));
|
||||
$globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php'));
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace LanguageServer\Tests\Server\Workspace;
|
||||
|
||||
use LanguageServer\Tests\MockProtocolStream;
|
||||
use LanguageServer\Tests\Server\ServerTestCase;
|
||||
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument, Options};
|
||||
use LanguageServer\Protocol\{
|
||||
Message,
|
||||
MessageType,
|
||||
TextDocumentItem,
|
||||
TextDocumentIdentifier,
|
||||
SymbolInformation,
|
||||
SymbolKind,
|
||||
DiagnosticSeverity,
|
||||
FormattingOptions,
|
||||
Location,
|
||||
Range,
|
||||
Position
|
||||
};
|
||||
use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
|
||||
use function LanguageServer\pathToUri;
|
||||
use Sabre\Event\Promise;
|
||||
use Exception;
|
||||
|
||||
class DidChangeConfigurationTest extends ServerTestCase
|
||||
{
|
||||
public function testWipingIndex()
|
||||
{
|
||||
$promise = new Promise;
|
||||
|
||||
$this->projectIndex->on('wipe', function() use ($promise) {
|
||||
$promise->fulfill();
|
||||
});
|
||||
|
||||
$options = new Options;
|
||||
$options->fileTypes = [
|
||||
'.inc'
|
||||
];
|
||||
|
||||
$this->workspace->didChangeConfiguration($options);
|
||||
$promise->wait();
|
||||
}
|
||||
|
||||
public function testReindexingAfterWipe()
|
||||
{
|
||||
$promise = new Promise;
|
||||
|
||||
$this->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));
|
||||
} elseif (strpos($msg->body->params->message, 'All 0 PHP files parsed') !== false) {
|
||||
$promise->fulfill();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$options = new Options;
|
||||
$options->fileTypes = [
|
||||
'.inc'
|
||||
];
|
||||
|
||||
$this->workspace->didChangeConfiguration($options);
|
||||
$promise->wait();
|
||||
}
|
||||
|
||||
public function testGetChangedOptions()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue