1
0
Fork 0

test: The inherited static methods and properties

pull/679/head
Martin Letáček 2018-12-22 23:11:37 +01:00
parent d231f425b9
commit 107c962df8
5 changed files with 56 additions and 16 deletions

View File

@ -41,3 +41,6 @@ TestClass::$staticTestProperty[123]->testProperty;
$child = new ChildClass; $child = new ChildClass;
echo $child->testMethod(); echo $child->testMethod();
ChildClass::staticTestMethod();
ChildClass::$staticTestProperty[123]->testProperty;

View File

@ -41,3 +41,6 @@ TestClass::$staticTestProperty[123]->testProperty;
$child = new ChildClass; $child = new ChildClass;
echo $child->testMethod(); echo $child->testMethod();
ChildClass::staticTestMethod();
ChildClass::$staticTestProperty[123]->testProperty;

View File

@ -494,19 +494,21 @@ class DefinitionResolver
$className = $scoped->scopeResolutionQualifier->getResolvedName(); $className = $scoped->scopeResolutionQualifier->getResolvedName();
} }
$origName = null; $origName = null;
do { $nameSuffix = null;
if ($scoped->memberName instanceof Node\Expression\Variable) { if ($scoped->memberName instanceof Node\Expression\Variable) {
if ($scoped->parent instanceof Node\Expression\CallExpression) { if ($scoped->parent instanceof Node\Expression\CallExpression) {
return null; return null;
}
$memberName = $scoped->memberName->getName();
if (empty($memberName)) {
return null;
}
$name = (string)$className . '::$' . $memberName;
} else {
$name = (string)$className . '::' . $scoped->memberName->getText($scoped->getFileContents());
} }
$memberName = $scoped->memberName->getName();
if (empty($memberName)) {
return null;
}
$nameSuffix = '::$' . $memberName;
} else {
$nameSuffix = '::' . $scoped->memberName->getText($scoped->getFileContents());
}
do {
$name = (string)$className . $nameSuffix;
if ($scoped->parent instanceof Node\Expression\CallExpression) { if ($scoped->parent instanceof Node\Expression\CallExpression) {
$name .= '()'; $name .= '()';
} }

View File

@ -84,6 +84,8 @@ abstract class ServerTestCase extends TestCase
'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))), 'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(57, 4), new Position(60, 5))), 'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(57, 4), new Position(60, 5))),
'ChildClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
'ChildClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
'test_function()' => new Location($globalSymbolsUri, new Range(new Position(78, 0), new Position(81, 1))), 'test_function()' => new Location($globalSymbolsUri, new Range(new Position(78, 0), new Position(81, 1))),
'UnusedClass' => new Location($globalSymbolsUri, new Range(new Position(111, 0), new Position(118, 1))), 'UnusedClass' => new Location($globalSymbolsUri, new Range(new Position(111, 0), new Position(118, 1))),
'UnusedClass::unusedProperty' => new Location($globalSymbolsUri, new Range(new Position(113,11), new Position(113, 26))), 'UnusedClass::unusedProperty' => new Location($globalSymbolsUri, new Range(new Position(113,11), new Position(113, 26))),
@ -103,6 +105,8 @@ abstract class ServerTestCase extends TestCase
'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))), 'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(57, 4), new Position(60, 5))), 'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(57, 4), new Position(60, 5))),
'TestNamespace\\ChildClass::staticTestProperty'=> new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
'TestNamespace\\ChildClass::staticTestMethod()'=> new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(78, 0), new Position(81, 1))), 'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(78, 0), new Position(81, 1))),
'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(21, 0), new Position(23, 1))), 'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(21, 0), new Position(23, 1))),
'TestNamespace\\Example' => new Location($symbolsUri, new Range(new Position(101, 0), new Position(104, 1))), 'TestNamespace\\Example' => new Location($symbolsUri, new Range(new Position(101, 0), new Position(104, 1))),
@ -153,10 +157,12 @@ abstract class ServerTestCase extends TestCase
], ],
'TestNamespace\\TestClass::staticTestProperty' => [ 'TestNamespace\\TestClass::staticTestProperty' => [
0 => new Location($referencesUri, new Range(new Position( 8, 16), new Position( 8, 35))), // echo TestClass::$staticTestProperty; 0 => new Location($referencesUri, new Range(new Position( 8, 16), new Position( 8, 35))), // echo TestClass::$staticTestProperty;
1 => new Location($referencesUri, new Range(new Position(39, 11), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty; 1 => new Location($referencesUri, new Range(new Position(39, 11), new Position(39, 30))), // TestClass::$staticTestProperty[123]->testProperty;
2 => new Location($referencesUri, new Range(new Position(45, 12), new Position(45, 31))) // ChildClass::$staticTestProperty[123]->testProperty;
], ],
'TestNamespace\\TestClass::staticTestMethod()' => [ 'TestNamespace\\TestClass::staticTestMethod()' => [
0 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 27))) 0 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 27))),
1 => new Location($referencesUri, new Range(new Position(44, 0), new Position(44, 28)))
], ],
'TestNamespace\\TestClass::testMethod()' => [ 'TestNamespace\\TestClass::testMethod()' => [
0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 16))), // $obj->testMethod(); 0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 16))), // $obj->testMethod();
@ -207,10 +213,12 @@ abstract class ServerTestCase extends TestCase
], ],
'TestClass::staticTestProperty' => [ 'TestClass::staticTestProperty' => [
0 => new Location($globalReferencesUri, new Range(new Position( 8, 16), new Position( 8, 35))), // echo TestClass::$staticTestProperty; 0 => new Location($globalReferencesUri, new Range(new Position( 8, 16), new Position( 8, 35))), // echo TestClass::$staticTestProperty;
1 => new Location($globalReferencesUri, new Range(new Position(39, 11), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty; 1 => new Location($globalReferencesUri, new Range(new Position(39, 11), new Position(39, 30))), // TestClass::$staticTestProperty[123]->testProperty;
2 => new Location($globalReferencesUri, new Range(new Position(45, 12), new Position(45, 31))) // ChildClass::$staticTestProperty[123]->testProperty;
], ],
'TestClass::staticTestMethod()' => [ 'TestClass::staticTestMethod()' => [
0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 27))) 0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 27))),
1 => new Location($globalReferencesUri, new Range(new Position(44, 0), new Position(44, 28)))
], ],
'TestClass::testMethod()' => [ 'TestClass::testMethod()' => [
0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 16))), // $obj->testMethod(); 0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 16))), // $obj->testMethod();

View File

@ -198,4 +198,28 @@ class GlobalTest extends ServerTestCase
)->wait(); )->wait();
$this->assertEquals([], $result); $this->assertEquals([], $result);
} }
public function testReferencesForInheritedStaticMethods()
{
// public static function staticTestMethod()
// Get references for staticTestMethod
$definition = $this->getDefinitionLocation('ChildClass::staticTestMethod()');
$result = $this->textDocument->references(
new ReferenceContext,
new TextDocumentIdentifier($definition->uri),
$definition->range->start
)->wait();
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result);
}
public function testReferencesForInheritedStaticProperties()
{
// public static $staticTestProperty;
// Get references for $staticTestProperty
$definition = $this->getDefinitionLocation('ChildClass::staticTestProperty');
$result = $this->textDocument->references(
new ReferenceContext,
new TextDocumentIdentifier($definition->uri),
$definition->range->start
)->wait();
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result);
}
} }