Add test case for DefinitionResolver
parent
2a19995dc4
commit
6752c26bf1
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace LanguageServer\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use LanguageServer\Index\Index;
|
||||
use LanguageServer\{DefinitionResolver, Parser};
|
||||
|
||||
class DefinitionResolverTest extends TestCase
|
||||
{
|
||||
public function testCreateDefinitionFromNode()
|
||||
{
|
||||
$parser = new Parser;
|
||||
$stmts = $parser->parse("<?php\ndefine('TEST_DEFINE', true);");
|
||||
$stmts[0]->setAttribute('ownerDocument', new MockPhpDocument);
|
||||
|
||||
$index = new Index;
|
||||
$definitionResolver = new DefinitionResolver($index);
|
||||
$def = $definitionResolver->createDefinitionFromNode($stmts[0], '\TEST_DEFINE');
|
||||
|
||||
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\Boolean::class, $def->type);
|
||||
}
|
||||
|
||||
public function testGetTypeFromNode()
|
||||
{
|
||||
$parser = new Parser;
|
||||
$stmts = $parser->parse("<?php\ndefine('TEST_DEFINE', true);");
|
||||
$stmts[0]->setAttribute('ownerDocument', new MockPhpDocument);
|
||||
|
||||
$index = new Index;
|
||||
$definitionResolver = new DefinitionResolver($index);
|
||||
$type = $definitionResolver->getTypeFromNode($stmts[0]);
|
||||
|
||||
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\Boolean::class, $type);
|
||||
}
|
||||
|
||||
public function testGetDefinedFqn()
|
||||
{
|
||||
// define('XXX') (only one argument) must not introduce a new symbol
|
||||
$parser = new Parser;
|
||||
$stmts = $parser->parse("<?php\ndefine('TEST_DEFINE');");
|
||||
$stmts[0]->setAttribute('ownerDocument', new MockPhpDocument);
|
||||
|
||||
$index = new Index;
|
||||
$definitionResolver = new DefinitionResolver($index);
|
||||
$fqn = $definitionResolver->getDefinedFqn($stmts[0]);
|
||||
|
||||
$this->assertNull($fqn);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace LanguageServer\Tests;
|
||||
|
||||
/**
|
||||
* A fake document for tests
|
||||
*/
|
||||
class MockPhpDocument
|
||||
{
|
||||
/**
|
||||
* Returns fake uri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return 'file:///whatever';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue