diff --git a/.github/workflows/phpstan_printer_test.yaml b/.github/workflows/phpstan_printer_test.yaml new file mode 100644 index 00000000000..ff080c000c9 --- /dev/null +++ b/.github/workflows/phpstan_printer_test.yaml @@ -0,0 +1,41 @@ +name: PHPStan Printer Test + +on: + pull_request: null + push: + branches: + - main + + + +env: + # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 + COMPOSER_ROOT_VERSION: "dev-main" + +jobs: + tests: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + php-versions: ['8.2'] + + runs-on: ${{ matrix.os }} + timeout-minutes: 3 + + name: PHP ${{ matrix.php-versions }} tests (${{ matrix.os }}) + steps: + - uses: actions/checkout@v4 + + - + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + # to display warning when assert() is called, eg: on direct getArgs() on CallLike + # and check against first class callable strlen(...) + ini-values: zend.assertions=1 + + - uses: "ramsey/composer-install@v3" + + - run: vendor/bin/phpunit tests/PhpParser/Printer/PHPStanPrinterTest.php --colors diff --git a/rules-tests/CodeQuality/Rector/FuncCall/SortNamedParamRector/Fixture/array_map_named_params.php.inc b/rules-tests/CodeQuality/Rector/FuncCall/SortNamedParamRector/Fixture/array_map_named_params.php.inc new file mode 100644 index 00000000000..de77b5f1b0b --- /dev/null +++ b/rules-tests/CodeQuality/Rector/FuncCall/SortNamedParamRector/Fixture/array_map_named_params.php.inc @@ -0,0 +1,17 @@ + $item * 2); + +?> +----- + $item * 2, array: $items); + +?> diff --git a/tests/PhpParser/Printer/Fixture/some_array_map.php b/tests/PhpParser/Printer/Fixture/some_array_map.php new file mode 100644 index 00000000000..824ecfc90d8 --- /dev/null +++ b/tests/PhpParser/Printer/Fixture/some_array_map.php @@ -0,0 +1,5 @@ + $value); diff --git a/tests/PhpParser/Printer/PHPStanPrinterTest.php b/tests/PhpParser/Printer/PHPStanPrinterTest.php new file mode 100644 index 00000000000..15a021fa855 --- /dev/null +++ b/tests/PhpParser/Printer/PHPStanPrinterTest.php @@ -0,0 +1,40 @@ +make(Parser::class); + + $stmts = $phpstanParser->parseFile(__DIR__ . '/Fixture/some_array_map.php'); + + // get private property "parser" + $parserReflectionProperty = new ReflectionProperty(RichParser::class, 'parser'); + + /** @var \PhpParser\Parser $innerParser */ + $innerParser = $parserReflectionProperty->getValue($phpstanParser); + $tokens = $innerParser->getTokens(); + + $standard = new Standard([]); + $printerContents = $standard->printFormatPreserving($stmts, $stmts, $tokens); + + $newlineNormalizedContents = str_replace("\r\n", PHP_EOL, $printerContents); + + $this->assertStringEqualsFile(__DIR__ . '/Fixture/some_array_map.php', $newlineNormalizedContents); + } +}