Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Init container before DataProvider is called #4342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
ondrejmirtes merged 8 commits into phpstan:2.1.x from staabm:fix-tests
Sep 18, 2025

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Sep 18, 2025
edited
Loading

without this fix we saw errors like

➜ phpstan-src git:(fix-tests) ✗ time vendor/bin/phpunit tests/PHPStan/Type/Generic/TemplateTypeMapTest.php --debug
PHPUnit Started (PHPUnit 11.5.39 using PHP 8.3.25 (cli) on Darwin)
Test Runner Configured
Bootstrap Finished (/Users/staabm/workspace/phpstan-src/tests/bootstrap.php)
Event Facade Sealed
Data Provider Method Called (PHPStan\Type\Generic\TemplateTypeMapTest::dataUnionWithLowerBoundTypes for test method PHPStan\Type\Generic\TemplateTypeMapTest::testUnionWithLowerBoundTypes)
An error occurred inside PHPUnit.
Message: (no message)
Location: /Users/staabm/workspace/phpstan-src/src/Reflection/ReflectionProviderStaticAccessor.php:22
#0 /Users/staabm/workspace/phpstan-src/src/Type/ObjectType.php(1720): PHPStan\Reflection\ReflectionProviderStaticAccessor::getInstance()
#1 /Users/staabm/workspace/phpstan-src/src/Type/ObjectType.php(561): PHPStan\Type\ObjectType->getClassReflection()
#2 /Users/staabm/workspace/phpstan-src/src/Type/TypeCombinator.php(1213): PHPStan\Type\ObjectType->isSuperTypeOf(Object(PHPStan\Type\ObjectType))
#3 /Users/staabm/workspace/phpstan-src/src/Type/Generic/TemplateTypeMap.php(133): PHPStan\Type\TypeCombinator::intersect(Object(PHPStan\Type\ObjectType), Object(PHPStan\Type\ObjectType))
#4 /Users/staabm/workspace/phpstan-src/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php(34): PHPStan\Type\Generic\TemplateTypeMap->union(Object(PHPStan\Type\Generic\TemplateTypeMap))
#5 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Metadata/Api/DataProvider.php(183): PHPStan\Type\Generic\TemplateTypeMapTest::dataUnionWithLowerBoundTypes()
#6 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Metadata/Api/DataProvider.php(69): PHPUnit\Metadata\Api\DataProvider->dataProvidedByMethods('PHPStan\\Type\\Ge...', 'dataUnionWithLo...', Object(PHPUnit\Metadata\MetadataCollection))
#7 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestBuilder.php(47): PHPUnit\Metadata\Api\DataProvider->providedData('PHPStan\\Type\\Ge...', 'testUnionWithLo...')
#8 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(508): PHPUnit\Framework\TestBuilder->build(Object(ReflectionClass), 'testUnionWithLo...', Array)
#9 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(109): PHPUnit\Framework\TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod), Array)
#10 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(121): PHPUnit\Framework\TestSuite::fromClassReflector(Object(ReflectionClass))
#11 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(58): PHPUnit\TextUI\Configuration\TestSuiteBuilder->testSuiteFromPath('/Users/staabm/w...', Array)
#12 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/TextUI/Application.php(412): PHPUnit\TextUI\Configuration\TestSuiteBuilder->build(Object(PHPUnit\TextUI\Configuration\Configuration))
#13 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/TextUI/Application.php(182): PHPUnit\TextUI\Application->buildTestSuite(Object(PHPUnit\TextUI\Configuration\Configuration))
#14 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/phpunit(104): PHPUnit\TextUI\Application->run(Array)
#15 /Users/staabm/workspace/phpstan-src/vendor/bin/phpunit(122): include('/Users/staabm/w...')
#16 {main}

Comment on lines 3 to 5
<extensions>
<bootstrap class="PHPStan\Testing\PHPUnit\PHPUnitExtension"/>
</extensions>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case extension developer have to deal with the same race condition problems, we could instruct them to use the extension, which takes care of bootstrapping/re-building the container for them

Copy link
Contributor Author

staabm commented Sep 18, 2025

I think we should instruct PHPStan to not scan the files in src/Testing/PHPUnit/ for all PHPVersion which use old-phpunit.

have no idea yet how todo the php version specific config

@staabm staabm marked this pull request as ready for review September 18, 2025 09:11
Copy link
Collaborator

This pull request has been marked as ready for review.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it excluded from analysis? It ships with the PHAR, it should pass the analysis.

use PHPUnit\Runner\Extension\ParameterCollection;
use PHPUnit\TextUI\Configuration\Configuration;

final class PHPUnitExtension implements Extension
Copy link
Member

@ondrejmirtes ondrejmirtes Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name should be PHPStanPHPUnitExtension

Copy link
Member

PHP version specific config is already happening, check the files in build/. There's ignore-by-php-version...

Copy link
Contributor Author

staabm commented Sep 18, 2025
edited
Loading

There's ignore-by-php-version...

see https://github.com/phpstan/phpstan-src/actions/runs/17822286344/job/50667691251?pr=4342

there are non-ignorable errors.. it seems PHPStan is smart enough to realize that PHPUnit 9.x does not contain the interface the extension is using

Copy link
Member

You can put excludePaths into a new neon file and add it to includes if the PHPUnit version is older than 10.

Copy link
Contributor Author

staabm commented Sep 18, 2025

You can put excludePaths into a new neon file

used the already existing old-phpunit.neon for that.

@ondrejmirtes ondrejmirtes merged commit 086ee29 into phpstan:2.1.x Sep 18, 2025
455 of 457 checks passed
Copy link
Member

Super nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /