From 241960a4f78938cd60246ea1057f651ce94d1d73 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Fri, 18 Nov 2016 11:27:24 +0100 Subject: [PATCH] Add test for array access --- fixtures/global_references.php | 1 + fixtures/global_symbols.php | 2 +- fixtures/references.php | 1 + fixtures/symbols.php | 2 +- tests/Server/ServerTestCase.php | 16 +++++++++++----- .../TextDocument/Definition/GlobalTest.php | 12 ++++++++++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/fixtures/global_references.php b/fixtures/global_references.php index b4ec0f1..0ac117b 100644 --- a/fixtures/global_references.php +++ b/fixtures/global_references.php @@ -37,3 +37,4 @@ if ($abc instanceof TestInterface) { // Nested expression $obj->testProperty->testMethod(); +TestClass::$staticTestProperty[123]->testProperty; diff --git a/fixtures/global_symbols.php b/fixtures/global_symbols.php index 6eba8bb..f5c755b 100644 --- a/fixtures/global_symbols.php +++ b/fixtures/global_symbols.php @@ -30,7 +30,7 @@ class TestClass implements TestInterface /** * Lorem excepteur officia sit anim velit veniam enim. * - * @var TestClass + * @var TestClass[] */ public static $staticTestProperty; diff --git a/fixtures/references.php b/fixtures/references.php index 992ec00..2ac1a63 100644 --- a/fixtures/references.php +++ b/fixtures/references.php @@ -37,3 +37,4 @@ if ($abc instanceof TestInterface) { // Nested expressions $obj->testProperty->testMethod(); +TestClass::$staticTestProperty[123]->testProperty; diff --git a/fixtures/symbols.php b/fixtures/symbols.php index 8911101..4b0a6d9 100644 --- a/fixtures/symbols.php +++ b/fixtures/symbols.php @@ -30,7 +30,7 @@ class TestClass implements TestInterface /** * Lorem excepteur officia sit anim velit veniam enim. * - * @var TestClass + * @var TestClass[] */ public static $staticTestProperty; diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 2fc4db1..1a608ca 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -105,7 +105,8 @@ abstract class ServerTestCase extends TestCase 3 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST; 4 => new Location($referencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param) 5 => new Location($referencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass - 6 => new Location($useUri, new Range(new Position( 4, 4), new Position( 4, 27))), // use TestNamespace\TestClass; + 6 => new Location($referencesUri, new Range(new Position(39, 0), new Position(39, 9))), // TestClass::$staticTestProperty[123]->testProperty; + 7 => new Location($useUri, new Range(new Position( 4, 4), new Position( 4, 27))), // use TestNamespace\TestClass; ], 'TestNamespace\\TestInterface' => [ 0 => new Location($symbolsUri, new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface @@ -119,10 +120,12 @@ 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))), // echo $obj->testProperty; - 2 => new Location($referencesUri, new Range(new Position(38, 0), new Position(38, 18))) // $obj->testProperty->testMethod(); + 2 => new Location($referencesUri, new Range(new Position(38, 0), new Position(38, 18))), // $obj->testProperty->testMethod(); + 3 => new Location($referencesUri, new Range(new Position(39, 0), new Position(39, 49))) // TestClass::$staticTestProperty[123]->testProperty; ], 'TestNamespace\\TestClass::staticTestProperty' => [ - 0 => new Location($referencesUri, new Range(new Position( 8, 5), new Position( 8, 35))) + 0 => new Location($referencesUri, new Range(new Position( 8, 5), new Position( 8, 35))), // echo TestClass::$staticTestProperty; + 1 => new Location($referencesUri, new Range(new Position(39, 0), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty; ], 'TestNamespace\\TestClass::staticTestMethod()' => [ 0 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 29))) @@ -148,6 +151,7 @@ abstract class ServerTestCase extends TestCase 3 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST; 4 => new Location($globalReferencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param) 5 => new Location($globalReferencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass + 6 => new Location($globalReferencesUri, new Range(new Position(39, 0), new Position(39, 9))), // TestClass::$staticTestProperty[123]->testProperty; ], 'TestInterface' => [ 0 => new Location($globalSymbolsUri, new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface @@ -161,10 +165,12 @@ 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))), // echo $obj->testProperty; - 2 => new Location($globalReferencesUri, new Range(new Position(38, 0), new Position(38, 18))) // $obj->testProperty->testMethod(); + 2 => new Location($globalReferencesUri, new Range(new Position(38, 0), new Position(38, 18))), // $obj->testProperty->testMethod(); + 3 => new Location($globalReferencesUri, new Range(new Position(39, 0), new Position(39, 49))) // TestClass::$staticTestProperty[123]->testProperty; ], 'TestClass::staticTestProperty' => [ - 0 => new Location($globalReferencesUri, new Range(new Position( 8, 5), new Position( 8, 35))) + 0 => new Location($globalReferencesUri, new Range(new Position( 8, 5), new Position( 8, 35))), // echo TestClass::$staticTestProperty; + 1 => new Location($globalReferencesUri, new Range(new Position(39, 0), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty; ], 'TestClass::staticTestMethod()' => [ 0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 29))) diff --git a/tests/Server/TextDocument/Definition/GlobalTest.php b/tests/Server/TextDocument/Definition/GlobalTest.php index 94d278b..553cdc0 100644 --- a/tests/Server/TextDocument/Definition/GlobalTest.php +++ b/tests/Server/TextDocument/Definition/GlobalTest.php @@ -304,4 +304,16 @@ class GlobalTest extends ServerTestCase )->wait(); $this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result); } + + public function testDefinitionForPropertyFetchOnArrayDimFetch() + { + // $obj->testProperty->testMethod(); + // Get definition for testProperty + $reference = $this->getReferenceLocations('TestClass::testProperty')[3]; + $result = $this->textDocument->definition( + new TextDocumentIdentifier($reference->uri), + $reference->range->end + )->wait(); + $this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result); + } }