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

58 lines
2.0 KiB
PHP
Raw Normal View History

<?php
declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument;
use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{Server, Client, LanguageClient, Project};
2016-12-08 01:33:48 +00:00
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Protocol\{
TextDocumentIdentifier,
TextDocumentItem,
FormattingOptions,
ClientCapabilities,
TextEdit,
Range,
Position
};
use function LanguageServer\{pathToUri, uriToPath};
class FormattingTest extends TestCase
{
/**
* @var Server\TextDocument
*/
private $textDocument;
public function setUp()
{
2016-10-31 10:47:21 +00:00
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
2016-12-08 01:33:48 +00:00
$project = new Project($client, new FileSystemContentRetriever);
$this->textDocument = new Server\TextDocument($project, $client);
}
public function testFormatting()
{
2016-10-31 10:47:21 +00:00
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
2016-12-08 01:33:48 +00:00
$project = new Project($client, new FileSystemContentRetriever);
$textDocument = new Server\TextDocument($project, $client);
$path = realpath(__DIR__ . '/../../../fixtures/format.php');
$uri = pathToUri($path);
// Trigger parsing of source
$textDocumentItem = new TextDocumentItem();
$textDocumentItem->uri = $uri;
$textDocumentItem->languageId = 'php';
$textDocumentItem->version = 1;
$textDocumentItem->text = file_get_contents($path);
$textDocument->didOpen($textDocumentItem);
// how code should look after formatting
$expected = file_get_contents(__DIR__ . '/../../../fixtures/format_expected.php');
// Request formatting
$result = $textDocument->formatting(new TextDocumentIdentifier($uri), new FormattingOptions())->wait();
$this->assertEquals([new TextEdit(new Range(new Position(0, 0), new Position(20, 0)), $expected)], $result);
}
}