Skip to content

Mark the files of the test suites CLI-only - #288

Merged
alies-dev merged 1 commit into
psalm:masterfrom
alies-dev:cli-only-test-suite-files
Nov 21, 2026
Merged

alies-dev merged 1 commit into
psalm:masterfrom
alies-dev:cli-only-test-suite-files

Conversation

@alies-dev

Copy link
Copy Markdown
Contributor

Psalm reports CliOnlyCall for calls to a test case from top-level code and closures of the phpunit.xml test suites, although they only run under PHPUnit.

Before

<?php // tests/helpers.php, in a test suite
namespace NS;

$basePath = ExampleTest::applicationBasePath(); // CliOnlyCall: The method NS\ExampleTest::applicationBasePath() only runs from the command line
$render = static fn (): string => ExampleTest::applicationBasePath(); // CliOnlyCall: The method NS\ExampleTest::applicationBasePath() only runs from the command line
$nested = static function (): string {
    return (static fn (): string => ExampleTest::applicationBasePath())(); // CliOnlyCall: The method NS\ExampleTest::applicationBasePath() only runs from the command line
};
<?php // tests/ExampleTest.php, in a test suite
namespace NS;

/** @psalm-scope-this ExampleTest */
it(function (): void {
    $this->render(); // CliOnlyCall: The method NS\ExampleTest::render() only runs from the command line
});

After

$basePath = ExampleTest::applicationBasePath(); // no issue
$render = static fn (): string => ExampleTest::applicationBasePath(); // no issue
    return (static fn (): string => ExampleTest::applicationBasePath())(); // no issue
    $this->render(); // no issue

The same code outside the test suites (such as src/) is still reported.

Found while adopting alies-dev/psalm-plugin-pest: alies-dev/psalm-plugin-pest#124

Top-level code and closures in phpunit.xml test-suite files only run under PHPUnit, so calling a test case from them (e.g. Pest tests bound to a TestCase) no longer reports CliOnlyCall.
@alies-dev
alies-dev merged commit 3c29dc0 into psalm:master Nov 21, 2026
8 checks passed
@alies-dev
alies-dev deleted the cli-only-test-suite-files branch November 21, 2026 22:25
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.

1 participant