[CodingStyle] Skip NameImporter change when the name is already written as is - #8512
GErpeldinger wants to merge 1 commit into
Conversation
25b7090 to
f29dbe4
Compare
|
The PHP 8.4 tests failed on an unrelated flaky test: since #6110, This race is rare: both classes must be in different fast-unit chunks and on the same fixture at the same time. In the 70 failed test runs since fast-unit was added (2026-08-14), it happened 4 times: this run, and 3 times on The same logs have many other vendor/bin/phpunit rules-tests/TypeDeclaration/Rector/Function_/AddFunctionVoidReturnTypeWhereNoReturnRector/AddFunctionVoidReturnTypeWhereNoReturnRectorTest.php tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php🤖 Drafted with AI assistance. |
|
Thanks for the numbers 👌 |
|
imo, it is not worth the effort, checking the token is only when we need some quirk that not easy to catch by ast, eg: detecting parentheses start/end. please create separate PR for unrelated change on fixture directory rename fix. |
|
@samsonasik i opened #8517 for the bug in the tests, i check if i find a better solution for this branch |
ca0dcd5 to
e8ed9eb
Compare
|
@samsonasik Done: the check now compares the 🤖 Drafted with AI assistance. |
| public function testShortNameNextToSameShortNameAliasIsCachedAsUnchanged(): void | ||
| { | ||
| self::$rectorConfig = null; | ||
| $this->bootFromConfigFiles([__DIR__ . '/config-import-names.php']); | ||
| $applicationFileProcessor = $this->make(ApplicationFileProcessor::class); | ||
| $changedFilesDetector = $this->make(ChangedFilesDetector::class); | ||
| $changedFilesDetector->clear(); | ||
|
|
||
| $filePath = __DIR__ . '/Source/ImportedNextToSameShortNameAlias.php'; | ||
|
|
||
| $applicationFileProcessor->processFiles([$filePath], new Configuration(isDryRun: true)); | ||
|
|
||
| $this->assertFalse($changedFilesDetector->hasFileChanged($filePath)); | ||
| } |
There was a problem hiding this comment.
This is pretty hard to read. Instead, better use a Rector-like before/after tests. There are already import names rules in place, inspire there.
There was a problem hiding this comment.
Changed: the test now has its own small class, ImportNamesCacheTest, with the setup in setUp(), so the test itself is three lines.
I tried a before/after fixture in ImportFullyQualifiedNamesRector first, but it passes on main: the output is identical, and fixture tests don't see that the file is recorded as changed. That only shows in the cache (and the dry run's changed_files), so the test checks the cache.
🤖 Drafted with AI assistance.
There was a problem hiding this comment.
Honestly, i'm not sure if we can do better in this case, but i found already better the readability, wdyt ?
e8ed9eb to
b9af79d
Compare
Fixes rectorphp/rector#9911
resolveNameInUse()returns the short name when another import with the same short name is aliased. When the code already uses that short name, the returned name is identical, yet it is reported as a change, so a--dry-runnever caches the file.importNameAndCollectNewUseStatement()now returnsnullin that case, as it already does at its end when the original token matches.The new
ApplicationFileProcessorTestcase fails without the fix: the file is not cached after a dry run.Second commit, for the CI:
ReturnNullableTypeRectorPhp82TestreadFixture/with the default config, soFixturePhp82/never ran and both test classes wrote the same temporary files, which made the PHP 8.4 tests fail randomly here. It now usesFixturePhp82/andconfigured_rule_php82.php.🤖 Drafted with AI assistance.