1
0
Fork 0

Don't use json_decode in symbol tests

pull/92/head
Felix Becker 2016-10-18 19:17:05 +02:00
parent cdcfaf7849
commit 6019b023e9
2 changed files with 28 additions and 189 deletions

View File

@ -73,4 +73,18 @@ class SymbolInformation
} }
return $symbol; return $symbol;
} }
/**
* @param string $name
* @param int $kind
* @param Location $location
* @param string $containerName
*/
public function __construct($name = null, $kind = null, $location = null, $containerName = null)
{
$this->name = $name;
$this->kind = $kind;
$this->location = $location;
$this->containerName = $containerName;
}
} }

View File

@ -3,18 +3,13 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument; namespace LanguageServer\Tests\Server\TextDocument;
use PHPUnit\Framework\TestCase; use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{Server, LanguageClient, Project}; use LanguageServer\{Server, LanguageClient, Project};
use LanguageServer\Protocol\{TextDocumentIdentifier, SymbolKind}; use LanguageServer\Protocol\{TextDocumentIdentifier, SymbolInformation, SymbolKind, Position, Location, Range};
class DocumentSymbolTest extends TestCase class DocumentSymbolTest extends TextDocumentTestCase
{ {
/**
* @var Server\TextDocument
*/
private $textDocument;
public function setUp() public function setUp()
{ {
$client = new LanguageClient(new MockProtocolStream()); $client = new LanguageClient(new MockProtocolStream());
@ -28,186 +23,16 @@ class DocumentSymbolTest extends TestCase
// Request symbols // Request symbols
$result = $this->textDocument->documentSymbol(new TextDocumentIdentifier('symbols')); $result = $this->textDocument->documentSymbol(new TextDocumentIdentifier('symbols'));
$this->assertEquals([ $this->assertEquals([
[ new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, new Location('symbols', new Range(new Position( 4, 6), new Position( 4, 22))), 'TestNamespace'),
'name' => 'TEST_CONST', new SymbolInformation('TestClass', SymbolKind::CLASS_, new Location('symbols', new Range(new Position( 6, 0), new Position(21, 1))), 'TestNamespace'),
'kind' => SymbolKind::CONSTANT, new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, new Location('symbols', new Range(new Position( 8, 10), new Position( 8, 32))), 'TestNamespace\\TestClass'),
'location' => [ new SymbolInformation('staticTestProperty', SymbolKind::FIELD, new Location('symbols', new Range(new Position( 9, 18), new Position( 9, 37))), 'TestNamespace\\TestClass'),
'uri' => 'symbols', new SymbolInformation('testProperty', SymbolKind::FIELD, new Location('symbols', new Range(new Position(10, 11), new Position(10, 24))), 'TestNamespace\\TestClass'),
'range' => [ new SymbolInformation('staticTestMethod', SymbolKind::METHOD, new Location('symbols', new Range(new Position(12, 4), new Position(15, 5))), 'TestNamespace\\TestClass'),
'start' => [ new SymbolInformation('testMethod', SymbolKind::METHOD, new Location('symbols', new Range(new Position(17, 4), new Position(20, 5))), 'TestNamespace\\TestClass'),
'line' => 4, new SymbolInformation('TestTrait', SymbolKind::CLASS_, new Location('symbols', new Range(new Position(23, 0), new Position(26, 1))), 'TestNamespace'),
'character' => 6 new SymbolInformation('TestInterface', SymbolKind::INTERFACE, new Location('symbols', new Range(new Position(28, 0), new Position(31, 1))), 'TestNamespace'),
], new SymbolInformation('test_function', SymbolKind::FUNCTION, new Location('symbols', new Range(new Position(33, 0), new Position(36, 1))), 'TestNamespace')
'end' => [ ], $result);
'line' => 4,
'character' => 22
]
]
],
'containerName' => 'TestNamespace'
],
[
'name' => 'TestClass',
'kind' => SymbolKind::CLASS_,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 6,
'character' => 0
],
'end' => [
'line' => 21,
'character' => 1
]
]
],
'containerName' => 'TestNamespace'
],
[
'name' => 'TEST_CLASS_CONST',
'kind' => SymbolKind::CONSTANT,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 8,
'character' => 10
],
'end' => [
'line' => 8,
'character' => 32
]
]
],
'containerName' => 'TestNamespace\\TestClass'
],
[
'name' => 'staticTestProperty',
'kind' => SymbolKind::FIELD,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 9,
'character' => 18
],
'end' => [
'line' => 9,
'character' => 37
]
]
],
'containerName' => 'TestNamespace\\TestClass'
],
[
'name' => 'testProperty',
'kind' => SymbolKind::FIELD,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 10,
'character' => 11
],
'end' => [
'line' => 10,
'character' => 24
]
]
],
'containerName' => 'TestNamespace\\TestClass'
],
[
'name' => 'staticTestMethod',
'kind' => SymbolKind::METHOD,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 12,
'character' => 4
],
'end' => [
'line' => 15,
'character' => 5
]
]
],
'containerName' => 'TestNamespace\\TestClass'
],
[
'name' => 'testMethod',
'kind' => SymbolKind::METHOD,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 17,
'character' => 4
],
'end' => [
'line' => 20,
'character' => 5
]
]
],
'containerName' => 'TestNamespace\\TestClass'
],
[
'name' => 'TestTrait',
'kind' => SymbolKind::CLASS_,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 23,
'character' => 0
],
'end' => [
'line' => 26,
'character' => 1
]
]
],
'containerName' => 'TestNamespace'
],
[
'name' => 'TestInterface',
'kind' => SymbolKind::INTERFACE,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 28,
'character' => 0
],
'end' => [
'line' => 31,
'character' => 1
]
]
],
'containerName' => 'TestNamespace'
],
[
'name' => 'test_function',
'kind' => SymbolKind::FUNCTION,
'location' => [
'uri' => 'symbols',
'range' => [
'start' => [
'line' => 33,
'character' => 0
],
'end' => [
'line' => 36,
'character' => 1
]
]
],
'containerName' => 'TestNamespace'
]
], json_decode(json_encode($result), true));
} }
} }