Skip to content

Commit d36849a

Browse files
committed
[issue 9492] create reproducer for modified array_map args, as creates changed args on print
1 parent 6535bab commit d36849a

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nikic/php-parser": "^5.6.2",
2424
"ondram/ci-detector": "^4.2",
2525
"phpstan/phpdoc-parser": "^2.3",
26-
"phpstan/phpstan": "^2.1.32",
26+
"phpstan/phpstan": "2.1.19 as 2.1.32",
2727
"react/event-loop": "^1.6",
2828
"react/promise": "^3.3",
2929
"react/socket": "^1.17",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Rector\Tests\PhpParser\Printer\Fixture;
4+
5+
$result = array_map(
6+
array: [1, 2, 3],
7+
callback: fn (int $value) => $value
8+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\PhpParser\Printer;
6+
7+
use PhpParser\PrettyPrinter\Standard;
8+
use PHPStan\Parser\Parser;
9+
use PHPStan\Parser\RichParser;
10+
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
11+
12+
/**
13+
* Test case for: https://github.com/rectorphp/rector/issues/9492
14+
* Most likely caused by https://github.com/phpstan/phpstan-src/pull/3763
15+
*/
16+
final class PHPStanPrinterTest extends AbstractLazyTestCase
17+
{
18+
public function testAddingCommentOnSomeNodesFail(): void
19+
{
20+
/** @var RichParser $phpstanParser */
21+
$phpstanParser = $this->make(Parser::class);
22+
23+
$stmts = $phpstanParser->parseFile(__DIR__ . '/Fixture/some_array_map.php');
24+
25+
// get private property "parser"
26+
$parserReflectionProperty = new \ReflectionProperty(RichParser::class, 'parser');
27+
28+
/** @var \PhpParser\Parser $innerParser */
29+
$innerParser = $parserReflectionProperty->getValue($phpstanParser);
30+
$tokens = $innerParser->getTokens();
31+
32+
$standardPrinter = new Standard();
33+
$printerContents = $standardPrinter->printFormatPreserving($stmts, $stmts, $tokens);
34+
35+
$this->assertStringEqualsFile(__DIR__ . '/Fixture/some_array_map.php', $printerContents);
36+
}
37+
}

0 commit comments

Comments
 (0)