1
0
Fork 0

Fixed issue #42 and added regression test

pull/43/head
Stephan Unverwerth 2016-09-30 15:00:36 +02:00
parent dfc80a5c66
commit e076d0ecf7
2 changed files with 72 additions and 0 deletions

View File

@ -73,6 +73,8 @@ class SymbolFinder extends NodeVisitorAbstract
}
} else {
$this->nameStack[] = $containerName;
// We are not interested in unnamed nodes, return
return;
}
$class = get_class($node);

70
tests/PhpDocumentTest.php Normal file
View File

@ -0,0 +1,70 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Tests\Server;
use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{LanguageClient, Project};
use LanguageServer\Protocol\SymbolKind;
class PhpDocumentTest extends TestCase
{
/**
* @var Project $project
*/
private $project;
public function setUp()
{
$this->project = new Project(new LanguageClient(new MockProtocolStream()));
}
public function testParsesVariableVariables()
{
$document = $this->project->getDocument('whatever');
$document->updateContent("<?php\n$\$a = 'foo';\n\$bar = 'baz';\n");
$symbols = $document->getSymbols();
$this->assertEquals([
[
'name' => 'a',
'kind' => SymbolKind::VARIABLE,
'location' => [
'uri' => 'whatever',
'range' => [
'start' => [
'line' => 1,
'character' => 0
],
'end' => [
'line' => 1,
'character' => 3
]
]
],
'containerName' => null
],
[
'name' => 'bar',
'kind' => SymbolKind::VARIABLE,
'location' => [
'uri' => 'whatever',
'range' => [
'start' => [
'line' => 2,
'character' => 0
],
'end' => [
'line' => 2,
'character' => 4
]
]
],
'containerName' => null
]
], json_decode(json_encode($symbols), true));
}
}