1
0
Fork 0

Add tests

pull/668/head
Jürgen Steitz 2017-03-02 23:12:19 +01:00
parent 940eb9787d
commit 5b1b6bfabe
2 changed files with 94 additions and 8 deletions

View File

@ -5,10 +5,12 @@ namespace LanguageServer\Tests\Server;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; 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\Index\{ProjectIndex, StubsIndex, GlobalIndex, DependenciesIndex, Index};
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Protocol\{Position, Location, Range, ClientCapabilities}; use LanguageServer\Protocol\{Position, Location, Range, ClientCapabilities};
use LanguageServer\FilesFinder\FileSystemFilesFinder;
use LanguageServer\Cache\FileSystemCache;
use function LanguageServer\pathToUri; use function LanguageServer\pathToUri;
use Sabre\Event\Promise; use Sabre\Event\Promise;
@ -29,6 +31,10 @@ abstract class ServerTestCase extends TestCase
*/ */
protected $documentLoader; protected $documentLoader;
protected $projectIndex;
protected $input;
protected $output;
/** /**
* Map from FQN to Location of definition * Map from FQN to Location of definition
* *
@ -47,14 +53,22 @@ abstract class ServerTestCase extends TestCase
{ {
$sourceIndex = new Index; $sourceIndex = new Index;
$dependenciesIndex = new DependenciesIndex; $dependenciesIndex = new DependenciesIndex;
$projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex); $this->projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
$projectIndex->setComplete(); $this->projectIndex->setComplete();
$definitionResolver = new DefinitionResolver($projectIndex); $rootPath = realpath(__DIR__ . '/../../fixtures/');
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $options = new Options;
$this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $filesFinder = new FileSystemFilesFinder;
$this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex); $cache = new FileSystemCache;
$this->workspace = new Server\Workspace($projectIndex, $dependenciesIndex, $sourceIndex, null, $this->documentLoader);
$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')); $globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_symbols.php'));
$globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php')); $globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php'));

View File

@ -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()
{
}
}