Skip to content

Commit ea9a6ad

Browse files
committed
[issue 9492] create reproducer for modified array_map args, as creates changed args on print
1 parent 538dfac commit ea9a6ad

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: PHPStan Printer Test
2+
3+
on:
4+
pull_request: null
5+
push:
6+
branches:
7+
- main
8+
9+
10+
11+
env:
12+
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
13+
COMPOSER_ROOT_VERSION: "dev-main"
14+
15+
jobs:
16+
tests:
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-latest, windows-latest]
21+
php-versions: ['8.2']
22+
23+
runs-on: ${{ matrix.os }}
24+
timeout-minutes: 3
25+
26+
name: PHP ${{ matrix.php-versions }} tests (${{ matrix.os }})
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
-
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php-versions }}
34+
coverage: none
35+
# to display warning when assert() is called, eg: on direct getArgs() on CallLike
36+
# and check against first class callable strlen(...)
37+
ini-values: zend.assertions=1
38+
39+
- uses: "ramsey/composer-install@v3"
40+
41+
- run: vendor/bin/phpunit tests/PhpParser/Printer/PHPStanPrinterTest.php --colors

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace Rector\Tests\PhpParser\Printer\Fixture;
4+
5+
$result = array_map(array: [1, 2, 3], callback: fn(int $value) => $value);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
'newline' => "\n",
34+
]);
35+
$printerContents = $standardPrinter->printFormatPreserving($stmts, $stmts, $tokens);
36+
37+
$this->assertStringEqualsFile(__DIR__ . '/Fixture/some_array_map.php', $printerContents);
38+
}
39+
}

0 commit comments

Comments
 (0)