| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  | <?php | 
					
						
							|  |  |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 12:42:56 +00:00
										 |  |  |  | namespace LanguageServer\Tests\Server\Workspace; | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | use LanguageServer\Tests\MockProtocolStream; | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  |  | use LanguageServer\Tests\Server\ServerTestCase; | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  | use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument}; | 
					
						
							| 
									
										
										
										
											2016-11-30 21:23:51 +00:00
										 |  |  |  | use LanguageServer\Protocol\{ | 
					
						
							|  |  |  |  |     TextDocumentItem, | 
					
						
							|  |  |  |  |     TextDocumentIdentifier, | 
					
						
							|  |  |  |  |     SymbolInformation, | 
					
						
							|  |  |  |  |     SymbolKind, | 
					
						
							|  |  |  |  |     DiagnosticSeverity, | 
					
						
							|  |  |  |  |     FormattingOptions, | 
					
						
							|  |  |  |  |     Location, | 
					
						
							|  |  |  |  |     Range, | 
					
						
							|  |  |  |  |     Position | 
					
						
							|  |  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  | use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody}; | 
					
						
							| 
									
										
										
										
											2016-10-11 12:42:56 +00:00
										 |  |  |  | use function LanguageServer\pathToUri; | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  |  | class SymbolTest extends ServerTestCase | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-09 13:48:08 +00:00
										 |  |  |  |     public function testEmptyQueryReturnsAllSymbols() | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         // Request symbols
 | 
					
						
							| 
									
										
										
										
											2017-01-25 00:38:11 +00:00
										 |  |  |  |         $result = $this->workspace->symbol('')->wait(); | 
					
						
							| 
									
										
										
										
											2016-11-30 21:23:51 +00:00
										 |  |  |  |         $referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php')); | 
					
						
							| 
									
										
										
										
											2017-06-10 09:37:39 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 17:35:37 +00:00
										 |  |  |  |         // @codingStandardsIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  |         $this->assertEquals([ | 
					
						
							| 
									
										
										
										
											2017-06-09 18:25:30 +00:00
										 |  |  |  |             new SymbolInformation('TestNamespace',      SymbolKind::NAMESPACE, new Location($referencesUri, new Range(new Position(2, 0), new Position(2, 24))), ''), | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  |  |             // Namespaced
 | 
					
						
							| 
									
										
										
										
											2017-04-17 15:03:08 +00:00
										 |  |  |  |             new SymbolInformation('TEST_CONST',             SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestNamespace\\TEST_CONST'),                    'TestNamespace'), | 
					
						
							|  |  |  |  |             new SymbolInformation('TestClass',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\TestClass'),                     'TestNamespace'), | 
					
						
							|  |  |  |  |             new SymbolInformation('TEST_CLASS_CONST',       SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'),   'TestNamespace\\TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('staticTestProperty',     SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('testProperty',           SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'),       'TestNamespace\\TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('staticTestMethod',       SymbolKind::METHOD,      $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('testMethod',             SymbolKind::METHOD,      $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'),       'TestNamespace\\TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('TestTrait',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\TestTrait'),                     'TestNamespace'), | 
					
						
							|  |  |  |  |             new SymbolInformation('TestInterface',          SymbolKind::INTERFACE,   $this->getDefinitionLocation('TestNamespace\\TestInterface'),                 'TestNamespace'), | 
					
						
							|  |  |  |  |             new SymbolInformation('test_function',          SymbolKind::FUNCTION,    $this->getDefinitionLocation('TestNamespace\\test_function()'),               'TestNamespace'), | 
					
						
							|  |  |  |  |             new SymbolInformation('ChildClass',             SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\ChildClass'),                    'TestNamespace'), | 
					
						
							|  |  |  |  |             new SymbolInformation('Example',                SymbolKind::CLASS_,      $this->getDefinitionLocation('TestNamespace\\Example'),                       'TestNamespace'), | 
					
						
							|  |  |  |  |             new SymbolInformation('__construct',            SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__construct'),          'TestNamespace\\Example'), | 
					
						
							|  |  |  |  |             new SymbolInformation('__destruct',             SymbolKind::CONSTRUCTOR, $this->getDefinitionLocation('TestNamespace\\Example::__destruct'),           'TestNamespace\\Example'), | 
					
						
							|  |  |  |  |             new SymbolInformation('whatever',               SymbolKind::FUNCTION,    $this->getDefinitionLocation('TestNamespace\\whatever()'),                    'TestNamespace'), | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  |  |             // Global
 | 
					
						
							| 
									
										
										
										
											2017-04-17 15:03:08 +00:00
										 |  |  |  |             new SymbolInformation('TEST_CONST',             SymbolKind::CONSTANT,    $this->getDefinitionLocation('TEST_CONST'),                                   ''), | 
					
						
							|  |  |  |  |             new SymbolInformation('TestClass',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestClass'),                                    ''), | 
					
						
							|  |  |  |  |             new SymbolInformation('TEST_CLASS_CONST',       SymbolKind::CONSTANT,    $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'),                  'TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('staticTestProperty',     SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestClass::staticTestProperty'),                'TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('testProperty',           SymbolKind::PROPERTY,    $this->getDefinitionLocation('TestClass::testProperty'),                      'TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('staticTestMethod',       SymbolKind::METHOD,      $this->getDefinitionLocation('TestClass::staticTestMethod()'),                'TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('testMethod',             SymbolKind::METHOD,      $this->getDefinitionLocation('TestClass::testMethod()'),                      'TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('TestTrait',              SymbolKind::CLASS_,      $this->getDefinitionLocation('TestTrait'),                                    ''), | 
					
						
							|  |  |  |  |             new SymbolInformation('TestInterface',          SymbolKind::INTERFACE,   $this->getDefinitionLocation('TestInterface'),                                ''), | 
					
						
							|  |  |  |  |             new SymbolInformation('test_function',          SymbolKind::FUNCTION,    $this->getDefinitionLocation('test_function()'),                              ''), | 
					
						
							|  |  |  |  |             new SymbolInformation('ChildClass',             SymbolKind::CLASS_,      $this->getDefinitionLocation('ChildClass'),                                   ''), | 
					
						
							|  |  |  |  |             new SymbolInformation('TEST_DEFINE_CONSTANT',   SymbolKind::CONSTANT,    $this->getDefinitionLocation('TEST_DEFINE_CONSTANT'),                         ''), | 
					
						
							| 
									
										
										
										
											2017-06-10 09:37:39 +00:00
										 |  |  |  |             new SymbolInformation('UnusedClass',            SymbolKind::CLASS_,      $this->getDefinitionLocation('UnusedClass'),                                  ''), | 
					
						
							|  |  |  |  |             new SymbolInformation('unusedProperty',         SymbolKind::PROPERTY,    $this->getDefinitionLocation('UnusedClass::unusedProperty'),                  'UnusedClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('unusedMethod',           SymbolKind::METHOD,      $this->getDefinitionLocation('UnusedClass::unusedMethod'),                    'UnusedClass'), | 
					
						
							| 
									
										
										
										
											2017-04-17 15:03:08 +00:00
										 |  |  |  |             new SymbolInformation('whatever',               SymbolKind::FUNCTION,    $this->getDefinitionLocation('whatever()'),                                   ''), | 
					
						
							| 
									
										
										
										
											2016-11-30 21:23:51 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-10 09:37:39 +00:00
										 |  |  |  |             new SymbolInformation('SecondTestNamespace',    SymbolKind::NAMESPACE,   $this->getDefinitionLocation('SecondTestNamespace'),                          ''), | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  |  |         ], $result); | 
					
						
							| 
									
										
										
										
											2016-10-24 17:35:37 +00:00
										 |  |  |  |         // @codingStandardsIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2016-10-09 13:48:08 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public function testQueryFiltersResults() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         // Request symbols
 | 
					
						
							| 
									
										
										
										
											2017-01-25 00:38:11 +00:00
										 |  |  |  |         $result = $this->workspace->symbol('testmethod')->wait(); | 
					
						
							| 
									
										
										
										
											2016-10-24 17:35:37 +00:00
										 |  |  |  |         // @codingStandardsIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2016-10-09 13:48:08 +00:00
										 |  |  |  |         $this->assertEquals([ | 
					
						
							| 
									
										
										
										
											2016-10-18 21:09:51 +00:00
										 |  |  |  |             new SymbolInformation('staticTestMethod',   SymbolKind::METHOD,    $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('testMethod',         SymbolKind::METHOD,    $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'),       'TestNamespace\\TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('staticTestMethod',   SymbolKind::METHOD,    $this->getDefinitionLocation('TestClass::staticTestMethod()'),                'TestClass'), | 
					
						
							|  |  |  |  |             new SymbolInformation('testMethod',         SymbolKind::METHOD,    $this->getDefinitionLocation('TestClass::testMethod()'),                      'TestClass') | 
					
						
							|  |  |  |  |         ], $result); | 
					
						
							| 
									
										
										
										
											2016-10-24 17:35:37 +00:00
										 |  |  |  |         // @codingStandardsIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2016-09-30 09:30:08 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } |