-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composer PHP version appears not to be respected #79
Comments
I've done some digging leading to PR #80 which would solve this, but may not be the best way to go about things. At the very least it should give some idea of solution directions. |
Thank you for reporting this and taking the time and effort to provide a thorough reproduction scenario! I'll try to reproduce things as soon as I have access to a windows environment, that would also give me opportunity to verify #80. |
To confirm this is all envs. Have the exact same issue on linux and mac. |
I just ran into this issue again myself. Would be awesome if the PR could get some attention as it really is pretty annoying/confusing when this happens. |
Huge +1 from me too. When it fails there is hardly any indication of the error. |
FYI: I've added another commit/branch to the POC repo |
Problem/Motivation
Ok, so this is a fairly complicated one to explain, so please bear with me.
First off, I'm not sure if this is a Windows specific problem or a wider problem, but I have been able to consistently reproduce the issue on Windows.
By default, if you call a script in the
vendor/bin
directory, the system default PHP version will be used.Important: This may not be the same PHP version as is used by Composer!
If you want commands to use the same PHP version as Composer uses, you need to define them as
scripts
and prefix them with@php
.See: https://getcomposer.org/doc/articles/scripts.md#executing-php-scripts
For this to work on Windows with PHPCS (though probably the same goes for other tools), you can't point to the script in the
vendor/bin
directory as Windows will just print out that script, so you need to point to the actual script in the dependency.See: composer/composer#7645
Now, given a system default PHP version of 5.4.x and a PHP used by Composer of 7.2.x and having PHPUnit as a project dependency, the DealerDirect PHPCS plugin will appear to work correctly, but in reality will fail to work and the
CodeSniffer.conf
file is not created or updated.The
PHPUnit
dependency is arbitrary, that is just the dependency through which I discovered the bug.The point is to have a dependency which has non-cross-version compatible PHP code and which will autoload at least one file from the dependency.
I've tested this both with v 0.4.4 as well as 0.5.0.
In 0.5.0, this will fail silently.
In 0.4.4, this will fail with error info:
Based on the 0.4.4. output, it seems that the system default PHP version is used as some point - not the PHP version used by Composer - as this is a PHP 5.4 parse error for PHP 7 code.
While I have to say that it is bewildering to me that the referenced - completely unrelated - file would be loaded at this point in the first place (I'd guess that's a misconfigured autoload section in that dependency), it highlights that the default PHP version is used to set the
installed_paths
instead of the Composer version.IMO, a Composer plugin should always respect the PHP version on which Composer is being run, which is why I'm reporting this here as a bug.
System info:
Expected behaviour
That the PHPCS
installed_path
is set properly.Actual behaviour
The plugin echo's to the screen that the
installed_path
has been set, but in reality it hasn't been.Steps to reproduce
I've set up a minimal Proof of Conflict repo here: https://github.com/jrfnl/Dealerdirect-PHPUnit-Conflict-POC
To reproduce, you will need a Windows machine, though it may fail other OS-es as well.
PATH
s in Windows to point to a PHP 5.4.x install.)composer.bat
file to point PHP to a more recent version.master
branch.composer install
and then runphpcs-i
. All should be fine and it will displayThe installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, PHPCompatibility, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra
.composer.lock
and thevendor
directory.POC
branch.composer install
and then runphpcs-i
. Now it will displayThe installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend
.Proposed changes
I haven't dug into the plugin code yet to see what would need to be changed, but I'm guessing that if there are
exec()
commands and such, that will be where problem lies.The text was updated successfully, but these errors were encountered: