From d764b7d6cc2d1a65e23828bfe6f88cbb4b8c5416 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Fri, 18 Nov 2016 10:11:11 +0100 Subject: [PATCH] Add test for nested method call --- fixtures/global_references.php | 3 +++ fixtures/references.php | 3 +++ tests/Server/ServerTestCase.php | 12 ++++++++---- tests/Server/TextDocument/Definition/GlobalTest.php | 12 ++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/fixtures/global_references.php b/fixtures/global_references.php index 8346923..b4ec0f1 100644 --- a/fixtures/global_references.php +++ b/fixtures/global_references.php @@ -34,3 +34,6 @@ use function test_function; if ($abc instanceof TestInterface) { } + +// Nested expression +$obj->testProperty->testMethod(); diff --git a/fixtures/references.php b/fixtures/references.php index ca27443..992ec00 100644 --- a/fixtures/references.php +++ b/fixtures/references.php @@ -34,3 +34,6 @@ use function TestNamespace\test_function; if ($abc instanceof TestInterface) { } + +// Nested expressions +$obj->testProperty->testMethod(); diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index c5818a9..2fc4db1 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -118,7 +118,8 @@ abstract class ServerTestCase extends TestCase ], 'TestNamespace\\TestClass::testProperty' => [ 0 => new Location($symbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter; - 1 => new Location($referencesUri, new Range(new Position( 6, 5), new Position( 6, 23))) + 1 => new Location($referencesUri, new Range(new Position( 6, 5), new Position( 6, 23))), // echo $obj->testProperty; + 2 => new Location($referencesUri, new Range(new Position(38, 0), new Position(38, 18))) // $obj->testProperty->testMethod(); ], 'TestNamespace\\TestClass::staticTestProperty' => [ 0 => new Location($referencesUri, new Range(new Position( 8, 5), new Position( 8, 35))) @@ -127,7 +128,8 @@ abstract class ServerTestCase extends TestCase 0 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 29))) ], 'TestNamespace\\TestClass::testMethod()' => [ - 0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 18))) + 0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 18))), // $obj->testMethod(); + 1 => new Location($referencesUri, new Range(new Position(38, 0), new Position(38, 32))) // $obj->testProperty->testMethod(); ], 'TestNamespace\\test_function()' => [ 0 => new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))), @@ -158,7 +160,8 @@ abstract class ServerTestCase extends TestCase ], 'TestClass::testProperty' => [ 0 => new Location($globalSymbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter; - 1 => new Location($globalReferencesUri, new Range(new Position( 6, 5), new Position( 6, 23))) + 1 => new Location($globalReferencesUri, new Range(new Position( 6, 5), new Position( 6, 23))), // echo $obj->testProperty; + 2 => new Location($globalReferencesUri, new Range(new Position(38, 0), new Position(38, 18))) // $obj->testProperty->testMethod(); ], 'TestClass::staticTestProperty' => [ 0 => new Location($globalReferencesUri, new Range(new Position( 8, 5), new Position( 8, 35))) @@ -167,7 +170,8 @@ abstract class ServerTestCase extends TestCase 0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 29))) ], 'TestClass::testMethod()' => [ - 0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18))) + 0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18))), // $obj->testMethod(); + 1 => new Location($globalReferencesUri, new Range(new Position(38, 0), new Position(38, 32))) // $obj->testProperty->testMethod(); ], 'test_function()' => [ 0 => new Location($globalReferencesUri, new Range(new Position(10, 0), new Position(10, 13))), diff --git a/tests/Server/TextDocument/Definition/GlobalTest.php b/tests/Server/TextDocument/Definition/GlobalTest.php index bc5f6e6..94d278b 100644 --- a/tests/Server/TextDocument/Definition/GlobalTest.php +++ b/tests/Server/TextDocument/Definition/GlobalTest.php @@ -292,4 +292,16 @@ class GlobalTest extends ServerTestCase )->wait(); $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result); } + + public function testDefinitionForNestedMethodCall() + { + // $obj->testProperty->testMethod(); + // Get definition for testMethod + $reference = $this->getReferenceLocations('TestClass::testMethod()')[1]; + $result = $this->textDocument->definition( + new TextDocumentIdentifier($reference->uri), + $reference->range->end + )->wait(); + $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result); + } }