Skip to content

Commit 169bc33

Browse files
committed
Replace args with VariadicPlaceholder should remove trailing comma
1 parent 3a454ca commit 169bc33

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/PhpParser/PrettyPrinterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Scalar\Int_;
1111
use PhpParser\Node\Scalar\String_;
1212
use PhpParser\Node\Stmt;
13+
use PhpParser\Node\VariadicPlaceholder;
1314
use PhpParser\PrettyPrinter\Standard;
1415

1516
class PrettyPrinterTest extends CodeTestAbstract {
@@ -305,4 +306,29 @@ public function testInvalidIndent(): void {
305306
$this->expectExceptionMessage('Option "indent" must either be all spaces or a single tab');
306307
new PrettyPrinter\Standard(['indent' => "\t "]);
307308
}
309+
310+
public function testTrailingCommaArgToFirstClassCallable(): void {
311+
$parser = (new ParserFactory())->createForNewestSupportedVersion();
312+
$traverser = new NodeTraverser(new NodeVisitor\CloningVisitor());
313+
314+
$oldStmts = $parser->parse(<<<'CODE'
315+
<?php strlen("test",);
316+
CODE
317+
);
318+
$oldTokens = $parser->getTokens();
319+
$newStmts = $traverser->traverse($oldStmts);
320+
321+
$funcCall = $newStmts[0]->expr;
322+
$funcCall->args = [new VariadicPlaceholder()];
323+
324+
$prettyPrinter = new PrettyPrinter\Standard();
325+
$expected = <<<'CODE'
326+
<?php strlen(...);
327+
CODE;
328+
329+
$this->assertEquals(
330+
$expected,
331+
$prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens)
332+
);
333+
}
308334
}

0 commit comments

Comments
 (0)