From 51de0b5dfceb980a67bfdfdfa13ea1de32c16490 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Tue, 22 Nov 2016 17:33:56 +0100 Subject: [PATCH] Add tests for static access --- .../completion/class_const_with_prefix.php | 3 ++ .../completion/static_method_with_prefix.php | 3 ++ .../static_property_with_prefix.php | 3 ++ src/PhpDocument.php | 3 ++ tests/Server/TextDocument/CompletionTest.php | 54 +++++++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 fixtures/completion/class_const_with_prefix.php create mode 100644 fixtures/completion/static_method_with_prefix.php create mode 100644 fixtures/completion/static_property_with_prefix.php diff --git a/fixtures/completion/class_const_with_prefix.php b/fixtures/completion/class_const_with_prefix.php new file mode 100644 index 0000000..36c71d4 --- /dev/null +++ b/fixtures/completion/class_const_with_prefix.php @@ -0,0 +1,3 @@ +stmts === null) { + return null; + } $traverser = new NodeTraverser; $finder = new NodeAtPositionFinder($position); $traverser->addVisitor($finder); diff --git a/tests/Server/TextDocument/CompletionTest.php b/tests/Server/TextDocument/CompletionTest.php index 8f22ad0..3b57c82 100644 --- a/tests/Server/TextDocument/CompletionTest.php +++ b/tests/Server/TextDocument/CompletionTest.php @@ -131,6 +131,60 @@ class CompletionTest extends TestCase ], $items); } + public function testStaticPropertyWithPrefix() + { + $completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_property_with_prefix.php'); + $this->project->openDocument($completionUri, file_get_contents($completionUri)); + $items = $this->textDocument->completion( + new TextDocumentIdentifier($completionUri), + new Position(2, 14) + )->wait(); + $this->assertEquals([ + new CompletionItem( + 'staticTestProperty', + CompletionItemKind::PROPERTY, + '\TestClass[]', + 'Lorem excepteur officia sit anim velit veniam enim.' + ) + ], $items); + } + + public function testStaticMethodWithPrefix() + { + $completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_method_with_prefix.php'); + $this->project->openDocument($completionUri, file_get_contents($completionUri)); + $items = $this->textDocument->completion( + new TextDocumentIdentifier($completionUri), + new Position(2, 13) + )->wait(); + $this->assertEquals([ + new CompletionItem( + 'staticTestMethod', + CompletionItemKind::METHOD, + 'mixed', // Method return type + 'Do magna consequat veniam minim proident eiusmod incididunt aute proident.' + ) + ], $items); + } + + public function testClassConstWithPrefix() + { + $completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/class_const_with_prefix.php'); + $this->project->openDocument($completionUri, file_get_contents($completionUri)); + $items = $this->textDocument->completion( + new TextDocumentIdentifier($completionUri), + new Position(2, 13) + )->wait(); + $this->assertEquals([ + new CompletionItem( + 'TEST_CLASS_CONST', + CompletionItemKind::VARIABLE, + 'int', + 'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.' + ) + ], $items); + } + public function testFullyQualifiedClass() { $completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/fully_qualified_class.php');