Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix Incompatibilty With PhpStorm on Windows#995

Merged
Slamdunk merged 3 commits into
paratestphp:7.xfrom
FeBe95:patch-1
Aug 19, 2025
Merged

Fix Incompatibilty With PhpStorm on Windows#995
Slamdunk merged 3 commits into
paratestphp:7.xfrom
FeBe95:patch-1

Conversation

@FeBe95
Copy link
Copy Markdown
Contributor

@FeBe95 FeBe95 commented Aug 15, 2025

This is a bug fix for the following error:

Fatal error: Uncaught RuntimeException
Missing path to '/paratest_for_phpstorm' in C:\repos\some_repo\vendor\brianium\paratest\src\Util\PhpstormHelper.php:60

Detailed Description

This error occurred when trying to use the "Rerun Failed Test" functionality in PhpStorm on a Windows machine. This only happened if the run configuration option "Use ParaTest" is set by the user and contains backward slashes. On Windows this is very common, since the native Windows Explorer "Select Path" dialog can be used.

grafik

Root Cause

When this option is set, the resulting command line contains mixed forward and backward slashes, because PhpStorm inserts the path as is:

C:\php\php.exe C:\repos\some_project\vendor\bin\paratest_for_phpstorm C:/repos/some_project/vendor/phpunit/phpunit/phpunit --configuration C:\repos\some_project\phpunit.xml --filter "..." C:\xampp\htdocs\bidX\tests\Unit --teamcity

Therefore, calling

self::getArgvKeyFor($argv, '/paratest_for_phpstorm')

throws the previously mentioned error, because it tries to find the paratest_for_phpstorm binary prefixed with a forward slash.

The Fix

Search for both /paratest_for_phpstorm and \paratest_for_phpstorm in the provided arguments.

References

This PR relates to these issues:

@FeBe95 FeBe95 changed the title Fix Incompatibilty for PhpStorm on Windows Fix Incompatibilty With PhpStorm on Windows Aug 15, 2025
Copy link
Copy Markdown
Member

@Slamdunk Slamdunk left a comment

Choose a reason for hiding this comment

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

Instead of a double search, what about a single replace

Comment thread src/Util/PhpstormHelper.php Outdated
Comment on lines +51 to +52
$searchForForwardSlash = str_replace('\\', '/', $searchFor);
$searchForBackwardSlash = str_replace('/', '\\', $searchFor);
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.

Suggested change
$searchForForwardSlash = str_replace('\\', '/', $searchFor);
$searchForBackwardSlash = str_replace('/', '\\', $searchFor);
$searchFor = str_replace('/', DIRECTORY_SEPARATOR, $searchFor);

Instead of a double search, what about a single search with the os-aware DIRECTORY_SEPARATOR constant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, both forward and backward slashes can be used within one single command line on Windows, as you can see in the example I provided above. The command line contains:

  • C:\repos\some_project\vendor\bin\paratest_for_phpstorm and
  • C:/repos/some_project/vendor/phpunit/phpunit/phpunit.

The getArgvKeyFor() method must support both types. Therefore, it cannot rely on DIRECTORY_SEPARATOR as a replacement in $searchFor because $argv might contain non-OS-standard slashes. Users have the "freedom of choice" to use any type of slash when providing the configuration path.

P.S. Why did I use str_replace() twice? On Windows, a single path can contain both types of slashes at the same time and still be valid, e.g., C:\repos\some_project\vendor\bin/paratest_for_phpstorm. Using str_replace() twice normalizes all paths to contain only one type of slash for easier comparison.

@Slamdunk
Copy link
Copy Markdown
Member

Please fix the build so we can merge and ship it 💪

@Slamdunk Slamdunk merged commit 521aa38 into paratestphp:7.x Aug 19, 2025
8 checks passed
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