Skip to content

Commit 8a0bb94

Browse files
committed
More tests
1 parent a2268bb commit 8a0bb94

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/PHPStan/Printer/PrinterTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use PHPStan\PhpDocParser\Ast\PhpDoc\TypeAliasImportTagValueNode;
2929
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
3030
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
31+
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeUnsealedTypeNode;
3132
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
3233
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
3334
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
@@ -51,6 +52,7 @@
5152
use function array_splice;
5253
use function array_unshift;
5354
use function array_values;
55+
use function assert;
5456
use function count;
5557
use const PHP_EOL;
5658

@@ -1740,6 +1742,76 @@ public function enterNode(Node $node)
17401742

17411743
},
17421744
];
1745+
1746+
yield [
1747+
'/** @return array{foo: int, ...} */',
1748+
'/** @return array{foo: int} */',
1749+
new class extends AbstractNodeVisitor {
1750+
1751+
public function enterNode(Node $node)
1752+
{
1753+
if ($node instanceof ArrayShapeNode) {
1754+
$node->sealed = true;
1755+
}
1756+
1757+
return $node;
1758+
}
1759+
1760+
},
1761+
];
1762+
1763+
yield [
1764+
'/** @return array{foo: int, ...} */',
1765+
'/** @return array{foo: int, ...<string>} */',
1766+
new class extends AbstractNodeVisitor {
1767+
1768+
public function enterNode(Node $node)
1769+
{
1770+
if ($node instanceof ArrayShapeNode) {
1771+
$node->unsealedType = new ArrayShapeUnsealedTypeNode(new IdentifierTypeNode('string'), null);
1772+
}
1773+
1774+
return $node;
1775+
}
1776+
1777+
},
1778+
];
1779+
1780+
yield [
1781+
'/** @return array{foo: int, ...<string>} */',
1782+
'/** @return array{foo: int, ...<int, string>} */',
1783+
new class extends AbstractNodeVisitor {
1784+
1785+
public function enterNode(Node $node)
1786+
{
1787+
if ($node instanceof ArrayShapeNode) {
1788+
assert($node->unsealedType !== null);
1789+
$node->unsealedType->keyType = new IdentifierTypeNode('int');
1790+
}
1791+
1792+
return $node;
1793+
}
1794+
1795+
},
1796+
];
1797+
1798+
yield [
1799+
'/** @return array{foo: int, ...<string>} */',
1800+
'/** @return array{foo: int} */',
1801+
new class extends AbstractNodeVisitor {
1802+
1803+
public function enterNode(Node $node)
1804+
{
1805+
if ($node instanceof ArrayShapeNode) {
1806+
$node->sealed = true;
1807+
$node->unsealedType = null;
1808+
}
1809+
1810+
return $node;
1811+
}
1812+
1813+
},
1814+
];
17431815
}
17441816

17451817
/**

0 commit comments

Comments
 (0)