1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00
psalm/tests/DocCommentTest.php

188 lines
4.1 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Tests;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Psalm\DocComment;
2020-05-29 04:14:41 +02:00
use Psalm\Internal\Scanner\ParsedDocblock;
class DocCommentTest extends BaseTestCase
{
public function testNewLineIsAddedBetweenAnnotationsByDefault(): void
{
2020-05-29 04:14:41 +02:00
$docComment = new ParsedDocblock(
'some desc',
2020-05-29 04:14:41 +02:00
[
'param' =>
[
2 => 'string $bli',
3 => 'int $bla',
],
'throws' =>
[
0 => '\Exception',
],
'return' =>
[
0 => 'bool',
],
]
);
$expectedDoc = '/**
* some desc
*
* @param string $bli
* @param int $bla
*
* @throws \Exception
*
* @return bool
*/
';
2020-05-29 04:14:41 +02:00
$this->assertSame($expectedDoc, $docComment->render(''));
}
public function testNewLineIsNotAddedBetweenAnnotationsIfDisabled(): void
{
2020-05-29 04:14:41 +02:00
ParsedDocblock::addNewLineBetweenAnnotations(false);
2020-05-29 04:14:41 +02:00
$docComment = new ParsedDocblock(
'some desc',
2020-05-29 04:14:41 +02:00
[
'param' =>
[
2 => 'string $bli',
3 => 'int $bla',
],
'throws' =>
[
0 => '\Exception',
],
'return' =>
[
0 => 'bool',
],
]
);
$expectedDoc = '/**
* some desc
*
* @param string $bli
* @param int $bla
* @throws \Exception
* @return bool
*/
';
2020-05-29 04:14:41 +02:00
$this->assertSame($expectedDoc, $docComment->render(''));
}
public function testNewLineIsAddedBetweenAnnotationsIfEnabled(): void
{
2020-05-29 04:14:41 +02:00
ParsedDocblock::addNewLineBetweenAnnotations(true);
2020-05-29 04:14:41 +02:00
$docComment = new ParsedDocblock(
'some desc',
2020-05-29 04:14:41 +02:00
[
'param' =>
[
2 => 'string $bli',
3 => 'int $bla',
],
'throws' =>
[
0 => '\Exception',
],
'return' =>
[
0 => 'bool',
],
]
);
$expectedDoc = '/**
* some desc
*
* @param string $bli
* @param int $bla
*
* @throws \Exception
*
* @return bool
*/
';
2020-05-29 04:14:41 +02:00
$this->assertSame($expectedDoc, $docComment->render(''));
}
public function testParsingRoundtrip(): void
{
ParsedDocblock::addNewLineBetweenAnnotations(true);
$expectedDoc = '/**
* some desc
*
* @param string $bli
* @param int $bla
*
* @throws \Exception
*
* @return bool
*/
';
$docComment = DocComment::parsePreservingLength(
new \PhpParser\Comment\Doc($expectedDoc)
);
$this->assertSame($expectedDoc, $docComment->render(''));
}
public function testParsingWithIndentation(): void
{
ParsedDocblock::addNewLineBetweenAnnotations(true);
$expectedDoc = '/**
* some desc
*
* @param string $bli
* @param int $bla
*
* @throws \Exception
*
* @return bool
*/
';
$docComment = DocComment::parsePreservingLength(
new \PhpParser\Comment\Doc($expectedDoc)
);
$this->assertSame($expectedDoc, $docComment->render(' '));
}
public function testParsingWithCommonPrefixes(): void
{
ParsedDocblock::addNewLineBetweenAnnotations(true);
$expectedDoc = '/**
* some self-referential desc with " * @return bool
* " as part of it.
*
* @param string $bli
* @param string $bli_this_suffix_is_kept
* @param int $bla
*
* @throws \Exception
*
* @return bool
*/
';
$docComment = DocComment::parsePreservingLength(
new \PhpParser\Comment\Doc($expectedDoc)
);
$this->assertSame($expectedDoc, $docComment->render(''));
}
}