| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace LanguageServer\Tests\Server\TextDocument\References; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  | use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range}; | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  | use LanguageServer\Tests\Server\ServerTestCase; | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  | use function LanguageServer\pathToUri; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  | class GlobalTest extends ServerTestCase | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     public function testReferencesForClassLike() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // class TestClass implements TestInterface
 | 
					
						
							|  |  |  |         // Get references for TestClass
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $definition = $this->getDefinitionLocation('TestClass'); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($definition->uri), | 
					
						
							|  |  |  |             $definition->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $this->assertEquals($this->getReferenceLocations('TestClass'), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForClassConstants() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // const TEST_CLASS_CONST = 123;
 | 
					
						
							|  |  |  |         // Get references for TEST_CLASS_CONST
 | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:19 +00:00
										 |  |  |         $definition = $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($definition->uri), | 
					
						
							|  |  |  |             $definition->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:19 +00:00
										 |  |  |         $this->assertEquals($this->getReferenceLocations('TestClass::TEST_CLASS_CONST'), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForConstants() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // const TEST_CONST = 123;
 | 
					
						
							|  |  |  |         // Get references for TEST_CONST
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $definition = $this->getDefinitionLocation('TEST_CONST'); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($definition->uri), | 
					
						
							|  |  |  |             $definition->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $this->assertEquals($this->getReferenceLocations('TEST_CONST'), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForStaticMethods() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // public static function staticTestMethod()
 | 
					
						
							|  |  |  |         // Get references for staticTestMethod
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $definition = $this->getDefinitionLocation('TestClass::staticTestMethod()'); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($definition->uri), | 
					
						
							|  |  |  |             $definition->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForStaticProperties() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // public static $staticTestProperty;
 | 
					
						
							|  |  |  |         // Get references for $staticTestProperty
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $definition = $this->getDefinitionLocation('TestClass::staticTestProperty'); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($definition->uri), | 
					
						
							|  |  |  |             $definition->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForMethods() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // public function testMethod($testParameter)
 | 
					
						
							|  |  |  |         // Get references for testMethod
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $definition = $this->getDefinitionLocation('TestClass::testMethod()'); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($definition->uri), | 
					
						
							|  |  |  |             $definition->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $this->assertEquals($this->getReferenceLocations('TestClass::testMethod()'), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForProperties() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // public $testProperty;
 | 
					
						
							|  |  |  |         // Get references for testProperty
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $definition = $this->getDefinitionLocation('TestClass::testProperty'); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($definition->uri), | 
					
						
							|  |  |  |             $definition->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $this->assertEquals($this->getReferenceLocations('TestClass::testProperty'), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForVariables() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // $var = 123;
 | 
					
						
							|  |  |  |         // Get definition for $var
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php')); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($uri), | 
					
						
							|  |  |  |             new Position(12, 3) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |         $this->assertEquals([ | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |             new Location($uri, new Range(new Position(12, 0), new Position(12, 4))), | 
					
						
							|  |  |  |             new Location($uri, new Range(new Position(13, 5), new Position(13, 9))), | 
					
						
							| 
									
										
										
										
											2016-10-19 10:31:32 +00:00
										 |  |  |             new Location($uri, new Range(new Position(26, 9), new Position(26, 13))) | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         ], $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForFunctionParams() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // function whatever(TestClass $param): TestClass
 | 
					
						
							|  |  |  |         // Get references for $param
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php')); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($uri), | 
					
						
							|  |  |  |             new Position(21, 32) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-19 10:31:32 +00:00
										 |  |  |         $this->assertEquals([new Location($uri, new Range(new Position(22, 9), new Position(22, 15)))], $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForFunctions() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // function test_function()
 | 
					
						
							|  |  |  |         // Get references for test_function
 | 
					
						
							| 
									
										
										
										
											2016-10-18 08:48:16 +00:00
										 |  |  |         $referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php')); | 
					
						
							|  |  |  |         $symbolsUri    = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php')); | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($symbolsUri), | 
					
						
							|  |  |  |             new Position(78, 16) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-26 09:47:02 +00:00
										 |  |  |         $this->assertEquals([ | 
					
						
							|  |  |  |             new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))), | 
					
						
							|  |  |  |             new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40))) | 
					
						
							|  |  |  |         ], $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-12-13 01:53:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForReference() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // $obj = new TestClass();
 | 
					
						
							|  |  |  |         // Get references for TestClass
 | 
					
						
							| 
									
										
										
										
											2017-11-19 00:59:57 +00:00
										 |  |  |         $reference = $this->getReferenceLocations('TestClass')[1]; | 
					
						
							| 
									
										
										
										
											2016-12-13 01:53:01 +00:00
										 |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($reference->uri), | 
					
						
							|  |  |  |             $reference->range->start | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							|  |  |  |         $this->assertEquals($this->getReferenceLocations('TestClass'), $result); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-06-10 09:37:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForUnusedClass() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // class UnusedClass
 | 
					
						
							|  |  |  |         // Get references for UnusedClass
 | 
					
						
							|  |  |  |         $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php')); | 
					
						
							|  |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($symbolsUri), | 
					
						
							|  |  |  |             new Position(111, 10) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							|  |  |  |         $this->assertEquals([], $result); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForUnusedProperty() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // public $unusedProperty
 | 
					
						
							|  |  |  |         // Get references for unusedProperty
 | 
					
						
							|  |  |  |         $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php')); | 
					
						
							|  |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($symbolsUri), | 
					
						
							|  |  |  |             new Position(113, 18) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							|  |  |  |         $this->assertEquals([], $result); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReferencesForUnusedMethod() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // public function unusedMethod()
 | 
					
						
							|  |  |  |         // Get references for unusedMethod
 | 
					
						
							|  |  |  |         $symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php')); | 
					
						
							|  |  |  |         $result = $this->textDocument->references( | 
					
						
							|  |  |  |             new ReferenceContext, | 
					
						
							|  |  |  |             new TextDocumentIdentifier($symbolsUri), | 
					
						
							|  |  |  |             new Position(115, 26) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							|  |  |  |         $this->assertEquals([], $result); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  | } |