1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 02:47:02 +01:00
psalm/tests/CommentAnalyzerTest.php

79 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Tests;
use PHPUnit\Framework\TestCase as BaseTestCase;
2021-12-03 20:11:20 +01:00
use PhpParser\Comment\Doc;
2021-06-08 04:55:21 +02:00
use Psalm\Aliases;
use Psalm\Internal\Analyzer\CommentAnalyzer;
2021-06-08 04:55:21 +02:00
use Psalm\Internal\RuntimeCaches;
use Psalm\Internal\Scanner\FileScanner;
class CommentAnalyzerTest extends BaseTestCase
{
public function setUp(): void
{
RuntimeCaches::clearAll();
}
public function testDocblockVarDescription(): void
{
$doc = '/**
* @var string Some Description
*/
';
2021-12-03 20:11:20 +01:00
$php_parser_doc = new Doc($doc);
$comment_docblock = CommentAnalyzer::getTypeFromComment($php_parser_doc, new FileScanner('somefile.php', 'somefile.php', false), new Aliases);
$this->assertSame('Some Description', $comment_docblock[0]->description);
}
public function testDocblockVarDescriptionWithVarId(): void
{
$doc = '/**
* @var string $foo Some Description
*/
';
2021-12-03 20:11:20 +01:00
$php_parser_doc = new Doc($doc);
$comment_docblock = CommentAnalyzer::getTypeFromComment($php_parser_doc, new FileScanner('somefile.php', 'somefile.php', false), new Aliases);
$this->assertSame('Some Description', $comment_docblock[0]->description);
}
public function testDocblockVarDescriptionMultiline(): void
{
$doc = '/**
* @var string $foo Some Description
* with a long description.
*/
';
2021-12-03 20:11:20 +01:00
$php_parser_doc = new Doc($doc);
$comment_docblock = CommentAnalyzer::getTypeFromComment($php_parser_doc, new FileScanner('somefile.php', 'somefile.php', false), new Aliases);
$this->assertSame('Some Description with a long description.', $comment_docblock[0]->description);
}
public function testDocblockDescription(): void
{
$doc = '/**
* Some Description
*
* @var string
*/
';
2021-12-03 20:11:20 +01:00
$php_parser_doc = new Doc($doc);
$comment_docblock = CommentAnalyzer::getTypeFromComment($php_parser_doc, new FileScanner('somefile.php', 'somefile.php', false), new Aliases);
$this->assertSame('Some Description', $comment_docblock[0]->description);
}
public function testDocblockDescriptionWithVarDescription(): void
{
$doc = '/**
* Some Description
*
* @var string Use a string
*/
';
2021-12-03 20:11:20 +01:00
$php_parser_doc = new Doc($doc);
$comment_docblock = CommentAnalyzer::getTypeFromComment($php_parser_doc, new FileScanner('somefile.php', 'somefile.php', false), new Aliases);
$this->assertSame('Use a string', $comment_docblock[0]->description);
}
}