Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Oct 27, 2025

No description provided.

@staabm
Copy link
Contributor Author

staabm commented Oct 27, 2025

looking at the PHP 7.x errors:

------ ------------------------------------------------------------------ 
  Line   tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php  
 ------ ------------------------------------------------------------------ 
  44     Named arguments are supported only on PHP 8.0 and later.          
  57     Named arguments are supported only on PHP 8.0 and later.          
  76     Named arguments are supported only on PHP 8.0 and later.          
  95     Named arguments are supported only on PHP 8.0 and later.          
  124    Named arguments are supported only on PHP 8.0 and later.          
  144    Named arguments are supported only on PHP 8.0 and later.          
  180    Named arguments are supported only on PHP 8.0 and later.          
  199    Named arguments are supported only on PHP 8.0 and later.          
  220    Named arguments are supported only on PHP 8.0 and later.          
  241    Named arguments are supported only on PHP 8.0 and later.          
 ------ ------------------------------------------------------------------ 

I think we have these alternatives to fix these errors:
a) check whether parameters are in correct order and don't error in case the named args are in the right order
b) adjust the tests to not use named args

wdyt?

@ondrejmirtes
Copy link
Member

About:

Named arguments are supported only on PHP 8.0 and later.

I'd say this is a phpstan-phpunit bug. The rule should match how PHPUnit behaves. Does it always do basically array_values on the args (so that only the order matters), or does it keep named args on PHP 8+?

@staabm
Copy link
Contributor Author

staabm commented Oct 28, 2025

I'd say this is a phpstan-phpunit bug. The rule should match how PHPUnit behaves. Does it always do basically array_values on the args (so that only the order matters), or does it keep named args on PHP 8+?

see

➜  phpunit git:(9.6) ✗ php -v
PHP 7.4.33 (cli) (built: Oct 11 2025 23:03:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
➜  phpunit git:(9.6) ✗ cat FooTest.php                                                              
<?php

class FooTest extends \PHPUnit\Framework\TestCase
{

    /**
     * @dataProvider dataParseFileClearCache
     */
    public function testParseFileClearCache(
        int $cachedNodesByStringCountMax,
        int $cachedNodesByStringCountExpected
        ): void
        {
        $this->assertTrue(true);
    }

    /**
     * @return Generator<string, array{cachedNodesByStringCountMax: int,cachedNodesByStringCountExpected: int}>
     */
    public static function dataParseFileClearCache(): Generator
    {
        yield 'even' => [
            'cachedNodesByStringCountMax' => 50,
            'cachedNodesByStringCountExpected' => 50,
        ];

        yield 'odd' => [
            'cachedNodesByStringCountMax' => 51,
            'cachedNodesByStringCountExpected' => 51,
        ];
    }
}
➜  phpunit git:(9.6) ✗ php phpunit FooTest.php
PHPUnit 9.6.29-15-g3ee3d102e by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.33
Configuration: /Users/staabm/workspace/phpunit/phpunit.xml

..                                                                  2 / 2 (100%)

Time: 00:00.001, Memory: 6.00 MB

OK (2 tests, 2 assertions)

@staabm
Copy link
Contributor Author

staabm commented Oct 28, 2025

and here a failling one:

➜  phpunit git:(9.6) ✗ php -v                 
PHP 7.4.33 (cli) (built: Oct 11 2025 23:03:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
➜  phpunit git:(9.6) ✗ cat FooTest.php 
<?php

class FooTest extends \PHPUnit\Framework\TestCase
{

    /**
     * @dataProvider dataParseFileClearCache
     */
    public function testParseFileClearCache(
        int $cachedNodesByStringCountMax,
        string $cachedNodesByStringCountExpected
        ): void
        {
        $this->assertTrue(true);
    }

    /**
     * @return Generator<string, array{cachedNodesByStringCountMax: int,cachedNodesByStringCountExpected: int}>
     */
    public static function dataParseFileClearCache(): Generator
    {
        yield 'even' => [
            'cachedNodesByStringCountMax' => 50,
            'cachedNodesByStringCountExpected' => 'abc',
        ];

        yield 'odd' => [
            'cachedNodesByStringCountExpected' => 'def',
            'cachedNodesByStringCountMax' => 51,
        ];
    }
}
➜  phpunit git:(9.6) ✗ php phpunit FooTest.php
PHPUnit 9.6.29-15-g3ee3d102e by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.33
Configuration: /Users/staabm/workspace/phpunit/phpunit.xml

.E                                                                  2 / 2 (100%)

Time: 00:00.002, Memory: 6.00 MB

There was 1 error:

1) FooTest::testParseFileClearCache with data set "odd" ('def', 51)
TypeError: Argument 1 passed to FooTest::testParseFileClearCache() must be of the type int, string given, called in /Users/staabm/workspace/phpunit/src/Framework/TestCase.php on line 1617

/Users/staabm/workspace/phpunit/FooTest.php:9
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:1617
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:1223
/Users/staabm/workspace/phpunit/src/Framework/TestResult.php:729
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:973
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:685
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:685
/Users/staabm/workspace/phpunit/src/TextUI/TestRunner.php:651
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:146
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:99

ERRORS!
Tests: 2, Assertions: 1, Errors: 1.

@staabm
Copy link
Contributor Author

staabm commented Oct 28, 2025

PHP8.3 on PHPUnit 9.6

➜  phpunit git:(9.6) ✗ php phpunit FooTest.php
PHPUnit 9.6.29-15-g3ee3d102e by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.27
Configuration: /Users/staabm/workspace/phpunit/phpunit.xml

.E                                                                  2 / 2 (100%)

Time: 00:00.002, Memory: 6.00 MB

There was 1 error:

1) FooTest::testParseFileClearCache with data set "odd" ('def', 51)
TypeError: FooTest::testParseFileClearCache(): Argument #1 ($cachedNodesByStringCountMax) must be of type int, string given, called in /Users/staabm/workspace/phpunit/src/Framework/TestCase.php on line 1617

/Users/staabm/workspace/phpunit/FooTest.php:9
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:1617
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:1223
/Users/staabm/workspace/phpunit/src/Framework/TestResult.php:729
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:973
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:685
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:685
/Users/staabm/workspace/phpunit/src/TextUI/TestRunner.php:651
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:146
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:99

ERRORS!
Tests: 2, Assertions: 1, Errors: 1.

PHP8.3 on PHPUnit 11.5

➜  phpunit git:(11.5) ✗ php phpunit FooTest.php
PHPUnit 11.5.42-27-g32e5fd8bc by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.27
Configuration: /Users/staabm/workspace/phpunit/phpunit.xml

..                                                                  2 / 2 (100%)

Time: 00:00.002, Memory: 10.00 MB

There was 1 PHPUnit test runner deprecation:

1) Metadata found in doc-comment for method FooTest::testParseFileClearCache(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

OK, but there were issues!
Tests: 2, Assertions: 2, PHPUnit Deprecations: 1.

@ondrejmirtes
Copy link
Member

I don't get it. TableErrorFormatterTest.php works on 7.4.

@staabm
Copy link
Contributor Author

staabm commented Oct 28, 2025

I don't get it. TableErrorFormatterTest.php works on 7.4.

one of my above comments was wrong. I deleted it.

@ondrejmirtes
Copy link
Member

Also "must be of the type int, string given" doesn't look like named arguments error, just argument type mismatch.

@ondrejmirtes
Copy link
Member

The thing is - does PHPUnit try to match cachedNodesByStringCountExpected against parameter name on PHP 8+ or is it always just about key order? The rule should match that.

@staabm
Copy link
Contributor Author

staabm commented Oct 28, 2025

ok, I finally did more testing and have a better idea.

I think PHPUnit 9.x/10.x does not at all support named arguments from data-providers (no matter PHP version).
starting with PHPUnit 11.x named arguments are supported

@ondrejmirtes
Copy link
Member

The rule should reflect that, it'd be very useful!

@ondrejmirtes ondrejmirtes merged commit 3578a23 into phpstan:2.1.x Oct 29, 2025
538 of 552 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the phpunit branch October 29, 2025 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants