mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
dabfb16e34
* Run tests in random order Being able to run tests in any order is a pre-requisite for being able to run them in parallel. * Reset type coverage between tests, fix affected tests * Reset parser and lexer between test runs and on php version change Previously lexer was reset, but parser kept the reference to the old one, and reference to the parser was kept by StatementsProvider. This resulted in order-dependent tests - if the parser was first initialized with phpVersion set to 7.4 then arrow functions worked fine, but were failing when the parser was initially constructed with settings for 7.3 This can be demonstrated on current master by upgrading to nikic/php-parser:4.9 and running: ``` vendor/bin/phpunit --no-coverage --filter="inferredArgArrowFunction" tests/ClosureTest.php ``` Now all tests using PHP 7.4 features must set the PHP version accordingly. * Marked more tests using 7.4 syntax * Reset newline-between-annotation flag between tests * Resolve real paths before passing them to checkPaths When checkPaths is called from psalm.php the paths are resolved, so we just mimicking SUT behaviour here. * Restore newline-between-annotations in DocCommentTest * Tweak Appveyor caches * Tweak TravisCI caches * Tweak CircleCI caches * Run tests in parallel Use `vendor/bin/paratest` instead of `vendor/bin/phpunit` * Use default paratest runner on Windows WrapperRunner is not supported on Windows. * TRAVIS_TAG could be empty * Restore appveyor conditional caching
194 lines
4.2 KiB
PHP
194 lines
4.2 KiB
PHP
<?php
|
|
namespace Psalm\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase;
|
|
use Psalm\DocComment;
|
|
use Psalm\Internal\RuntimeCaches;
|
|
use Psalm\Internal\Scanner\ParsedDocblock;
|
|
|
|
class DocCommentTest extends BaseTestCase
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
RuntimeCaches::clearAll();
|
|
}
|
|
|
|
public function testNewLineIsAddedBetweenAnnotationsByDefault(): void
|
|
{
|
|
$docComment = new ParsedDocblock(
|
|
'some desc',
|
|
[
|
|
'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
|
|
*/
|
|
';
|
|
|
|
$this->assertSame($expectedDoc, $docComment->render(''));
|
|
}
|
|
|
|
public function testNewLineIsNotAddedBetweenAnnotationsIfDisabled(): void
|
|
{
|
|
ParsedDocblock::addNewLineBetweenAnnotations(false);
|
|
|
|
$docComment = new ParsedDocblock(
|
|
'some desc',
|
|
[
|
|
'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
|
|
*/
|
|
';
|
|
|
|
$this->assertSame($expectedDoc, $docComment->render(''));
|
|
}
|
|
|
|
public function testNewLineIsAddedBetweenAnnotationsIfEnabled(): void
|
|
{
|
|
ParsedDocblock::addNewLineBetweenAnnotations(true);
|
|
|
|
$docComment = new ParsedDocblock(
|
|
'some desc',
|
|
[
|
|
'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
|
|
*/
|
|
';
|
|
|
|
$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(''));
|
|
}
|
|
}
|