Skip to content

Commit bbf4f8d

Browse files
committed
More tests
1 parent afd1aa5 commit bbf4f8d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

tests/PHPStan/Parser/PhpDocParserTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7623,6 +7623,14 @@ public function testLinesAndIndexes(string $phpDoc, array $childrenLines): void
76237623
$this->assertSame($childrenLines[$i][2], $child->getAttribute(Attribute::START_INDEX));
76247624
$this->assertSame($childrenLines[$i][3], $child->getAttribute(Attribute::END_INDEX));
76257625
}
7626+
7627+
$serialized = var_export($phpDocNode, true);
7628+
$readData = eval('return ' . $serialized . ';');
7629+
$this->assertEquals($phpDocNode, $readData);
7630+
7631+
$serialized = var_export($phpDocNode, true);
7632+
$readData = eval('return ' . $serialized . ';');
7633+
$this->assertEquals($phpDocNode, $readData);
76267634
}
76277635

76287636
/**
@@ -7823,14 +7831,20 @@ public function testVerifyAttributes(string $label, string $input): void
78237831

78247832
$visitor = new NodeCollectingVisitor();
78257833
$traverser = new NodeTraverser([$visitor]);
7826-
$traverser->traverse([$phpDocParser->parse($tokens)]);
7834+
7835+
$phpDocNode = $phpDocParser->parse($tokens);
7836+
$traverser->traverse([$phpDocNode]);
78277837

78287838
foreach ($visitor->nodes as $node) {
78297839
$this->assertNotNull($node->getAttribute(Attribute::START_LINE), sprintf('%s: %s', $label, $node));
78307840
$this->assertNotNull($node->getAttribute(Attribute::END_LINE), sprintf('%s: %s', $label, $node));
78317841
$this->assertNotNull($node->getAttribute(Attribute::START_INDEX), sprintf('%s: %s', $label, $node));
78327842
$this->assertNotNull($node->getAttribute(Attribute::END_INDEX), sprintf('%s: %s', $label, $node));
78337843
}
7844+
7845+
$serialized = var_export($phpDocNode, true);
7846+
$readData = eval('return ' . $serialized . ';');
7847+
$this->assertEquals($phpDocNode, $readData);
78347848
}
78357849

78367850
/**
@@ -7846,7 +7860,9 @@ public function testDoctrine(
78467860
{
78477861
$parser = new DocParser();
78487862
$parser->addNamespace('PHPStan\PhpDocParser\Parser\Doctrine');
7849-
$this->assertEquals($expectedAnnotations, $parser->parse($input, $label), $label);
7863+
7864+
$phpDocNode = $parser->parse($input, $label);
7865+
$this->assertEquals($expectedAnnotations, $phpDocNode, $label);
78507866
}
78517867

78527868
/**

tests/PHPStan/Parser/TypeParserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use PHPUnit\Framework\TestCase;
4141
use function get_class;
4242
use function strpos;
43+
use function var_export;
4344
use const PHP_EOL;
4445

4546
class TypeParserTest extends TestCase
@@ -84,6 +85,10 @@ public function testParse(string $input, $expectedResult, int $nextTokenType = L
8485

8586
$this->assertPrintedNodeViaToString($typeNode);
8687
$this->assertPrintedNodeViaPrinter($typeNode);
88+
89+
$serialized = var_export($typeNode, true);
90+
$readData = eval('return ' . $serialized . ';');
91+
$this->assertEquals($typeNode, $readData);
8792
}
8893

8994
private function assertPrintedNodeViaToString(TypeNode $typeNode): void
@@ -139,6 +144,10 @@ public function testVerifyAttributes(string $input, $expectedResult): void
139144
$this->unsetAllAttributesButComments($expectedResult),
140145
$this->unsetAllAttributesButComments($typeNode),
141146
);
147+
148+
$serialized = var_export($typeNode, true);
149+
$readData = eval('return ' . $serialized . ';');
150+
$this->assertEquals($typeNode, $readData);
142151
}
143152

144153
private function unsetAllAttributes(Node $node): Node
@@ -3443,6 +3452,10 @@ public function testLinesAndIndexes(string $input, array $assertions): void
34433452
}
34443453
$this->assertSame($expectedContent, $content);
34453454
}
3455+
3456+
$serialized = var_export($typeNode, true);
3457+
$readData = eval('return ' . $serialized . ';');
3458+
$this->assertEquals($typeNode, $readData);
34463459
}
34473460

34483461
}

0 commit comments

Comments
 (0)