Hi, PhpStorm is here! We're working on improving Pest support in PhpStorm and noticed a problem when determining the Pest version via remote interpreter.
When we try to get a Pest version using Pest with version 2.28.1, the pestphp/pest/bin/pest binary and an arbitrary compatible remote interpreter from DockerHub PHP the following output is received:
INFO .
The issue is caused by the incorrect detection of pest-plugins.json location in Loader.php:
private static function getPluginInstances(): array
{
if (! self::$loaded) {
$cachedPlugins = sprintf(
'%s/../pest-plugins.json',
$GLOBALS['_composer_bin_dir'] ?? getcwd().'/vendor/bin',
);
$container = Container::getInstance();
if (! file_exists($cachedPlugins)) {
return [];
}
Remote interpreters from Docker Hub don't specify a working directory, that's why the result of getcwd() might not be the project directory. As far as I understand, it's a root directory by default.
For this reason, mounting a PHP project with Pest not to the root directory (for example, with Docker flag -v /Users/me/myLocalProject:/opt/project) causes the problem, because the Docker execution of /opt/project/vendor/pestphp/pest/bin/pest --version wouldn't be successful since getcwd() would be /, not the /opt/project and we couldn't find pest-plugins.json to execute Version.php plugin.
As a workaround the following code snippet with fallback to vendor directory works fine with both local and remote interpreters:
private static function getPluginInstances(): array
{
if (! self::$loaded) {
$cachedPlugins = sprintf(
'%s/../pest-plugins.json',
$GLOBALS['_composer_bin_dir'] ?? __DIR__.'/../../../../vendor/bin',
);
$container = Container::getInstance();
if (! file_exists($cachedPlugins)) {
return [];
}
How to Reproduce
Select any project with Pest installed in vendor directory (like composer does)
Run docker container from the built image with -v path-to-your-project:/opt/project
The actual output log will be
INFO .
instead of expected one:
Pest Testing Framework 2.28.1.
Sample Repository
No response
Pest Version
2.28.1
PHP Version
8.3.1RC3(from the attached reproducer archive), 8.3.0, 8.2.10
Operation System
Linux
Notes
The base issue is https://github.com/pestphp/pest/issues/925, where the fix for Undefined global variable $_composer_bin_dir was introduced and became a problem from this issue.
What Happened
Hi, PhpStorm is here! We're working on improving Pest support in PhpStorm and noticed a problem when determining the Pest version via remote interpreter.
When we try to get a Pest version using Pest with version 2.28.1, the
pestphp/pest/bin/pest
binary and an arbitrary compatible remote interpreter from DockerHub PHP the following output is received:The issue is caused by the incorrect detection of
pest-plugins.json
location in Loader.php:Remote interpreters from Docker Hub don't specify a working directory, that's why the result of
getcwd()
might not be the project directory. As far as I understand, it's a root directory by default.For this reason, mounting a PHP project with Pest not to the root directory (for example, with Docker flag
-v /Users/me/myLocalProject:/opt/project
) causes the problem, because the Docker execution of/opt/project/vendor/pestphp/pest/bin/pest --version
wouldn't be successful sincegetcwd()
would be/
, not the/opt/project
and we couldn't findpest-plugins.json
to executeVersion.php
plugin.As a workaround the following code snippet with fallback to
vendor
directory works fine with both local and remote interpreters:How to Reproduce
vendor
directory (like composer does)CMD ["php", "/opt/project/vendor/pestphp/pest/bin/pest", "--version"]
)-v path-to-your-project:/opt/project
instead of expected one:
Sample Repository
No response
Pest Version
2.28.1
PHP Version
8.3.1RC3(from the attached reproducer archive), 8.3.0, 8.2.10
Operation System
Linux
Notes
The base issue is https://github.com/pestphp/pest/issues/925, where the fix for
Undefined global variable $_composer_bin_dir
was introduced and became a problem from this issue.