| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace LanguageServer\Tests\Server\TextDocument\Definition; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use LanguageServer\Tests\MockProtocolStream; | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  | use LanguageServer\Tests\Server\ServerTestCase; | 
					
						
							| 
									
										
										
										
											2017-06-09 18:25:30 +00:00
										 |  |  | use LanguageServer\{ | 
					
						
							|  |  |  |     Server, LanguageClient, PhpDocumentLoader, DefinitionResolver | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-12-13 00:51:02 +00:00
										 |  |  | use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex}; | 
					
						
							| 
									
										
										
										
											2016-12-08 01:33:48 +00:00
										 |  |  | use LanguageServer\ContentRetriever\FileSystemContentRetriever; | 
					
						
							| 
									
										
										
										
											2017-06-09 18:25:30 +00:00
										 |  |  | use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location}; | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  | class GlobalFallbackTest extends ServerTestCase | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     public function setUp() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-12-13 00:51:02 +00:00
										 |  |  |         $projectIndex = new ProjectIndex(new Index, new DependenciesIndex); | 
					
						
							| 
									
										
										
										
											2017-01-25 00:38:11 +00:00
										 |  |  |         $projectIndex->setComplete(); | 
					
						
							| 
									
										
										
										
											2016-10-31 10:47:21 +00:00
										 |  |  |         $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); | 
					
						
							| 
									
										
										
										
											2016-12-13 00:51:02 +00:00
										 |  |  |         $definitionResolver = new DefinitionResolver($projectIndex); | 
					
						
							|  |  |  |         $contentRetriever = new FileSystemContentRetriever; | 
					
						
							|  |  |  |         $loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver); | 
					
						
							|  |  |  |         $this->textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex); | 
					
						
							|  |  |  |         $loader->open('global_fallback', file_get_contents(__DIR__ . '/../../../../fixtures/global_fallback.php')); | 
					
						
							|  |  |  |         $loader->open('global_symbols', file_get_contents(__DIR__ . '/../../../../fixtures/global_symbols.php')); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testClassDoesNotFallback() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // $obj = new TestClass();
 | 
					
						
							|  |  |  |         // Get definition for TestClass should not fall back to global
 | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->definition( | 
					
						
							|  |  |  |             new TextDocumentIdentifier('global_fallback'), | 
					
						
							|  |  |  |             new Position(9, 16) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |         $this->assertEquals([], $result); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testFallsBackForConstants() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // echo TEST_CONST;
 | 
					
						
							|  |  |  |         // Get definition for TEST_CONST
 | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->definition( | 
					
						
							|  |  |  |             new TextDocumentIdentifier('global_fallback'), | 
					
						
							|  |  |  |             new Position(6, 10) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-19 10:31:32 +00:00
										 |  |  |         $this->assertEquals(new Location('global_symbols', new Range(new Position(9, 6), new Position(9, 22))), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testFallsBackForFunctions() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // test_function();
 | 
					
						
							|  |  |  |         // Get definition for test_function
 | 
					
						
							| 
									
										
										
										
											2016-11-14 09:25:44 +00:00
										 |  |  |         $result = $this->textDocument->definition( | 
					
						
							|  |  |  |             new TextDocumentIdentifier('global_fallback'), | 
					
						
							|  |  |  |             new Position(5, 6) | 
					
						
							|  |  |  |         )->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-19 10:31:32 +00:00
										 |  |  |         $this->assertEquals(new Location('global_symbols', new Range(new Position(78, 0), new Position(81, 1))), $result); | 
					
						
							| 
									
										
										
										
											2016-10-11 23:45:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |