Skip to content

[dx] Set Option::SOURCE parameter from the resolved paths - #8424

Open
SanderMuller wants to merge 1 commit into
rectorphp:mainfrom
SanderMuller:feature/publish-source-paths-parameter
Open

[dx] Set Option::SOURCE parameter from the resolved paths#8424
SanderMuller wants to merge 1 commit into
rectorphp:mainfrom
SanderMuller:feature/publish-source-paths-parameter

Conversation

@SanderMuller

@SanderMuller SanderMuller commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Option::SOURCE is only written to SimpleParameterProvider by AbstractRectorTestCase. A real run leaves it empty, so an extension reading the processed paths from the parameter works under the test harness and gets [] in production.

I hit this in a rules package that reads Option::PATHS and falls back to Option::SOURCE to learn which paths a run covers. The fallback works in its tests and never fires in a real run.

ConfigurationFactory::resolvePaths() now sets it to the paths it resolved: the command line when given, Option::PATHS otherwise. It already sets IS_RUN_NARROWED and FILES_WITHOUT_EXTENSION there.

Option::SOURCE is also in CACHE_IGNORED_PARAMETER_NAMES: the resolved paths change per invocation, so hashing them would drop the cache whenever the target changes.

AbstractRectorTestCase sets it, a real run never does, so code reading the
parameter works under the test harness and is empty in production.

Excluded from the cache invalidation hash: the paths change per invocation, so
hashing them would drop the cache whenever the target changes.
Comment on lines +57 to +71
try {
SimpleParameterProvider::setParameter(Option::PATHS, [__DIR__ . '/config']);

$this->make(ConfigurationFactory::class)
->createFromInput($this->createInput([__DIR__ . '/Source']));

$this->assertSame(
[__DIR__ . '/Source'],
SimpleParameterProvider::provideArrayParameter(Option::SOURCE)
);
} finally {
SimpleParameterProvider::setParameter(Option::PATHS, $originalPaths);
SimpleParameterProvider::setParameter(Option::SOURCE, $originalSource);
SimpleParameterProvider::setParameter(Option::IS_RUN_NARROWED, $originalIsRunNarrowed);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please try a more straighfoward way of testing. try/finally hides the intent

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants