2020-03-13 17:40:08 +01:00
|
|
|
<?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;
|
2020-03-13 17:40:08 +01:00
|
|
|
|
|
|
|
class DocCommentTest extends BaseTestCase
|
|
|
|
{
|
|
|
|
public function testNewLineIsAddedBetweenAnnotationsByDefault(): void
|
|
|
|
{
|
2020-05-29 04:14:41 +02:00
|
|
|
$docComment = new ParsedDocblock(
|
|
|
|
'* some desc' . "\n*",
|
|
|
|
[
|
|
|
|
'param' =>
|
|
|
|
[
|
|
|
|
2 => 'string $bli',
|
|
|
|
3 => 'int $bla',
|
|
|
|
],
|
|
|
|
'throws' =>
|
|
|
|
[
|
|
|
|
0 => '\Exception',
|
|
|
|
],
|
|
|
|
'return' =>
|
|
|
|
[
|
|
|
|
0 => 'bool',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
2020-03-13 17:40:08 +01:00
|
|
|
|
|
|
|
$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(''));
|
2020-03-13 17:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNewLineIsNotAddedBetweenAnnotationsIfDisabled(): void
|
|
|
|
{
|
2020-05-29 04:14:41 +02:00
|
|
|
ParsedDocblock::addNewLineBetweenAnnotations(false);
|
2020-03-13 17:40:08 +01:00
|
|
|
|
2020-05-29 04:14:41 +02:00
|
|
|
$docComment = new ParsedDocblock(
|
|
|
|
'* some desc' . "\n*",
|
|
|
|
[
|
|
|
|
'param' =>
|
|
|
|
[
|
|
|
|
2 => 'string $bli',
|
|
|
|
3 => 'int $bla',
|
|
|
|
],
|
|
|
|
'throws' =>
|
|
|
|
[
|
|
|
|
0 => '\Exception',
|
|
|
|
],
|
|
|
|
'return' =>
|
|
|
|
[
|
|
|
|
0 => 'bool',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
2020-03-13 17:40:08 +01:00
|
|
|
|
|
|
|
$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(''));
|
2020-03-13 17:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNewLineIsAddedBetweenAnnotationsIfEnabled(): void
|
|
|
|
{
|
2020-05-29 04:14:41 +02:00
|
|
|
ParsedDocblock::addNewLineBetweenAnnotations(true);
|
2020-03-13 17:40:08 +01:00
|
|
|
|
2020-05-29 04:14:41 +02:00
|
|
|
$docComment = new ParsedDocblock(
|
|
|
|
'* some desc' . "\n*",
|
|
|
|
[
|
|
|
|
'param' =>
|
|
|
|
[
|
|
|
|
2 => 'string $bli',
|
|
|
|
3 => 'int $bla',
|
|
|
|
],
|
|
|
|
'throws' =>
|
|
|
|
[
|
|
|
|
0 => '\Exception',
|
|
|
|
],
|
|
|
|
'return' =>
|
|
|
|
[
|
|
|
|
0 => 'bool',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
2020-03-13 17:40:08 +01:00
|
|
|
|
|
|
|
$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(''));
|
2020-03-13 17:40:08 +01:00
|
|
|
}
|
|
|
|
}
|