Fix Incompatibilty With PhpStorm on Windows#995
Conversation
Slamdunk
left a comment
There was a problem hiding this comment.
Instead of a double search, what about a single replace
| $searchForForwardSlash = str_replace('\\', '/', $searchFor); | ||
| $searchForBackwardSlash = str_replace('/', '\\', $searchFor); |
There was a problem hiding this comment.
| $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?
There was a problem hiding this comment.
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_phpstormandC:/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.
|
Please fix the build so we can merge and ship it 💪 |
This is a bug fix for the following error:
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.
Root Cause
When this option is set, the resulting command line contains mixed forward and backward slashes, because PhpStorm inserts the path as is:
Therefore, calling
throws the previously mentioned error, because it tries to find the
paratest_for_phpstormbinary prefixed with a forward slash.The Fix
Search for both
/paratest_for_phpstormand\paratest_for_phpstormin the provided arguments.References
This PR relates to these issues: