Skip to content

Commit 68d46b9

Browse files
committed
Extract creating PhpDocParser to setUp
1 parent 2a022b2 commit 68d46b9

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Diff for: tests/PHPStan/Printer/PrinterTest.php

+18-11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@
4242
class PrinterTest extends TestCase
4343
{
4444

45+
/** @var PhpDocParser */
46+
private $phpDocParser;
47+
48+
protected function setUp(): void
49+
{
50+
$usedAttributes = ['lines' => true, 'indexes' => true];
51+
$constExprParser = new ConstExprParser(true, true, $usedAttributes);
52+
$this->phpDocParser = new PhpDocParser(
53+
new TypeParser($constExprParser, true, $usedAttributes),
54+
$constExprParser,
55+
true,
56+
true,
57+
$usedAttributes
58+
);
59+
}
60+
4561
/**
4662
* @return iterable<array{string, string, NodeVisitor}>
4763
*/
@@ -1153,18 +1169,9 @@ public function enterNode(Node $node)
11531169
*/
11541170
public function testPrintFormatPreserving(string $phpDoc, string $expectedResult, NodeVisitor $visitor): void
11551171
{
1156-
$usedAttributes = ['lines' => true, 'indexes' => true];
1157-
$constExprParser = new ConstExprParser(true, true, $usedAttributes);
1158-
$phpDocParser = new PhpDocParser(
1159-
new TypeParser($constExprParser, true, $usedAttributes),
1160-
$constExprParser,
1161-
true,
1162-
true,
1163-
$usedAttributes
1164-
);
11651172
$lexer = new Lexer();
11661173
$tokens = new TokenIterator($lexer->tokenize($phpDoc));
1167-
$phpDocNode = $phpDocParser->parse($tokens);
1174+
$phpDocNode = $this->phpDocParser->parse($tokens);
11681175
$cloningTraverser = new NodeTraverser([new NodeVisitor\CloningVisitor()]);
11691176
$newNodes = $cloningTraverser->traverse([$phpDocNode]);
11701177

@@ -1179,7 +1186,7 @@ public function testPrintFormatPreserving(string $phpDoc, string $expectedResult
11791186

11801187
$this->assertEquals(
11811188
$this->unsetAttributes($newNode),
1182-
$this->unsetAttributes($phpDocParser->parse(new TokenIterator($lexer->tokenize($newPhpDoc))))
1189+
$this->unsetAttributes($this->phpDocParser->parse(new TokenIterator($lexer->tokenize($newPhpDoc))))
11831190
);
11841191
}
11851192

0 commit comments

Comments
 (0)