diff --git a/tests/Server/TextDocument/DidChangeTest.php b/tests/Server/TextDocument/DidChangeTest.php new file mode 100644 index 0000000..081978f --- /dev/null +++ b/tests/Server/TextDocument/DidChangeTest.php @@ -0,0 +1,38 @@ +getDocument('whatever'); + $phpDocument->updateContent("range = new Range(new Position(0, 0), new Position(9999, 9999)); + $changeEvent->rangeLength = 9999; + $changeEvent->text = "didChange($identifier, [$changeEvent]); + + $this->assertEquals("getContent()); + } +} diff --git a/tests/Server/TextDocumentTest.php b/tests/Server/TextDocument/DocumentSymbolTest.php similarity index 53% rename from tests/Server/TextDocumentTest.php rename to tests/Server/TextDocument/DocumentSymbolTest.php index 17d8031..b46648b 100644 --- a/tests/Server/TextDocumentTest.php +++ b/tests/Server/TextDocument/DocumentSymbolTest.php @@ -1,36 +1,38 @@ uri = 'whatever'; - $textDocumentItem->languageId = 'php'; - $textDocumentItem->version = 1; - $textDocumentItem->text = file_get_contents(__DIR__ . '/../../fixtures/symbols.php'); - $textDocument->didOpen($textDocumentItem); + $this->textDocument = new Server\TextDocument($project, $client); + $project->getDocument('symbols')->updateContent(file_get_contents(__DIR__ . '/../../../fixtures/symbols.php')); + } + + public function test() + { // Request symbols - $result = $textDocument->documentSymbol(new TextDocumentIdentifier('whatever')); + $result = $this->textDocument->documentSymbol(new TextDocumentIdentifier('symbols')); $this->assertEquals([ [ 'name' => 'TestNamespace', 'kind' => SymbolKind::NAMESPACE, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 2, @@ -48,7 +50,7 @@ class TextDocumentTest extends TestCase 'name' => 'TEST_CONST', 'kind' => SymbolKind::CONSTANT, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 4, @@ -66,7 +68,7 @@ class TextDocumentTest extends TestCase 'name' => 'TestClass', 'kind' => SymbolKind::CLASS_, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 6, @@ -84,7 +86,7 @@ class TextDocumentTest extends TestCase 'name' => 'TEST_CLASS_CONST', 'kind' => SymbolKind::CONSTANT, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 8, @@ -102,7 +104,7 @@ class TextDocumentTest extends TestCase 'name' => 'staticTestProperty', 'kind' => SymbolKind::PROPERTY, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 9, @@ -120,7 +122,7 @@ class TextDocumentTest extends TestCase 'name' => 'testProperty', 'kind' => SymbolKind::PROPERTY, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 10, @@ -138,7 +140,7 @@ class TextDocumentTest extends TestCase 'name' => 'staticTestMethod', 'kind' => SymbolKind::METHOD, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 12, @@ -156,7 +158,7 @@ class TextDocumentTest extends TestCase 'name' => 'testMethod', 'kind' => SymbolKind::METHOD, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 17, @@ -174,7 +176,7 @@ class TextDocumentTest extends TestCase 'name' => 'TestTrait', 'kind' => SymbolKind::CLASS_, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 23, @@ -192,7 +194,7 @@ class TextDocumentTest extends TestCase 'name' => 'TestInterface', 'kind' => SymbolKind::INTERFACE, 'location' => [ - 'uri' => 'whatever', + 'uri' => 'symbols', 'range' => [ 'start' => [ 'line' => 28, @@ -208,106 +210,4 @@ class TextDocumentTest extends TestCase ] ], json_decode(json_encode($result), true)); } - - public function testParseErrorsArePublishedAsDiagnostics() - { - $args = null; - $client = new LanguageClient(new MockProtocolStream()); - $client->textDocument = new class($args) extends Client\TextDocument { - private $args; - public function __construct(&$args) - { - parent::__construct(new MockProtocolStream()); - $this->args = &$args; - } - public function publishDiagnostics(string $uri, array $diagnostics) - { - $this->args = func_get_args(); - } - }; - - $project = new Project($client); - - $textDocument = new Server\TextDocument($project, $client); - - // Trigger parsing of source - $textDocumentItem = new TextDocumentItem(); - $textDocumentItem->uri = 'whatever'; - $textDocumentItem->languageId = 'php'; - $textDocumentItem->version = 1; - $textDocumentItem->text = file_get_contents(__DIR__ . '/../../fixtures/invalid_file.php'); - $textDocument->didOpen($textDocumentItem); - $this->assertEquals([ - 'whatever', - [[ - 'range' => [ - 'start' => [ - 'line' => 2, - 'character' => 10 - ], - 'end' => [ - 'line' => 2, - 'character' => 15 - ] - ], - 'severity' => DiagnosticSeverity::ERROR, - 'code' => null, - 'source' => 'php', - 'message' => "Syntax error, unexpected T_CLASS, expecting T_STRING" - ]] - ], json_decode(json_encode($args), true)); - } - - public function testFormatting() - { - $client = new LanguageClient(new MockProtocolStream()); - $project = new Project($client); - $textDocument = new Server\TextDocument($project, $client); - - // Trigger parsing of source - $textDocumentItem = new TextDocumentItem(); - $textDocumentItem->uri = 'whatever'; - $textDocumentItem->languageId = 'php'; - $textDocumentItem->version = 1; - $textDocumentItem->text = file_get_contents(__DIR__ . '/../../fixtures/format.php'); - $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('whatever'), new FormattingOptions()); - $this->assertEquals([0 => [ - 'range' => [ - 'start' => [ - 'line' => 0, - 'character' => 0 - ], - 'end' => [ - 'line' => PHP_INT_MAX, - 'character' => PHP_INT_MAX - ] - ], - 'newText' => $expected - ]], json_decode(json_encode($result), true)); - } - - public function testDidChange() - { - $client = new LanguageClient(new MockProtocolStream()); - $project = new Project($client); - $textDocument = new Server\TextDocument($project, $client); - - $phpDocument = $project->getDocument('whatever'); - $phpDocument->updateContent("range = new Range(new Position(0,0), new Position(9999,9999)); - $changeEvent->rangeLength = 9999; - $changeEvent->text = "didChange($identifier, [$changeEvent]); - - $this->assertEquals("getContent()); - } } diff --git a/tests/Server/TextDocument/FormattingTest.php b/tests/Server/TextDocument/FormattingTest.php new file mode 100644 index 0000000..2dcc46e --- /dev/null +++ b/tests/Server/TextDocument/FormattingTest.php @@ -0,0 +1,57 @@ +textDocument = new Server\TextDocument($project, $client); + } + + public function test() + { + $client = new LanguageClient(new MockProtocolStream()); + $project = new Project($client); + $textDocument = new Server\TextDocument($project, $client); + + // Trigger parsing of source + $textDocumentItem = new TextDocumentItem(); + $textDocumentItem->uri = 'whatever'; + $textDocumentItem->languageId = 'php'; + $textDocumentItem->version = 1; + $textDocumentItem->text = file_get_contents(__DIR__ . '/../../../fixtures/format.php'); + $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('whatever'), new FormattingOptions()); + $this->assertEquals([0 => [ + 'range' => [ + 'start' => [ + 'line' => 0, + 'character' => 0 + ], + 'end' => [ + 'line' => PHP_INT_MAX, + 'character' => PHP_INT_MAX + ] + ], + 'newText' => $expected + ]], json_decode(json_encode($result), true)); + } +} diff --git a/tests/Server/TextDocument/ParseErrorsTest.php b/tests/Server/TextDocument/ParseErrorsTest.php new file mode 100644 index 0000000..24d155c --- /dev/null +++ b/tests/Server/TextDocument/ParseErrorsTest.php @@ -0,0 +1,73 @@ +textDocument = new Server\TextDocument($project, $client); + } + + public function testParseErrorsArePublishedAsDiagnostics() + { + $args = null; + $client = new LanguageClient(new MockProtocolStream()); + $client->textDocument = new class($args) extends Client\TextDocument { + private $args; + public function __construct(&$args) + { + parent::__construct(new MockProtocolStream()); + $this->args = &$args; + } + public function publishDiagnostics(string $uri, array $diagnostics) + { + $this->args = func_get_args(); + } + }; + + $project = new Project($client); + + $textDocument = new Server\TextDocument($project, $client); + + // Trigger parsing of source + $textDocumentItem = new TextDocumentItem(); + $textDocumentItem->uri = 'whatever'; + $textDocumentItem->languageId = 'php'; + $textDocumentItem->version = 1; + $textDocumentItem->text = file_get_contents(__DIR__ . '/../../../fixtures/invalid_file.php'); + $textDocument->didOpen($textDocumentItem); + $this->assertEquals([ + 'whatever', + [[ + 'range' => [ + 'start' => [ + 'line' => 2, + 'character' => 10 + ], + 'end' => [ + 'line' => 2, + 'character' => 15 + ] + ], + 'severity' => DiagnosticSeverity::ERROR, + 'code' => null, + 'source' => 'php', + 'message' => "Syntax error, unexpected T_CLASS, expecting T_STRING" + ]] + ], json_decode(json_encode($args), true)); + } +}