vscode-phpunit icon indicating copy to clipboard operation
vscode-phpunit copied to clipboard

Wrong php version used

Open wave-light opened this issue 5 years ago • 6 comments

When I run the extension, it uses php located at 'usr/bin/php' instead of 'usr/local/bin/php'. This causes an error, because phpunit requires a more recent version of php. I have tried to set the php path explicitly using "phpunit.php": "/usr/local/bin/php",, but it has no effect, and still uses the one at 'usr/bin/php'

wave-light avatar May 05 '20 13:05 wave-light

I guess you have /usr/bin/php in your environment path and that's how it gets picked up somehow even though it shouldn't. Could you remove it and add /usr/local/bin/php instead as an easy fix?

Are you running local or remote? Could you paste the output from the OUTPUT and TERMINAL -> Task panes and your settings?

The extension should use the phpunit.php setting for most cases unless we're in a docker container or use phpunit.command.

elonmallin avatar May 05 '20 14:05 elonmallin

Thanks for your suggestions. I already had /usr/local/bin/php in my path unfortunately. My setting are as follows:

    "phpunit.php": "/usr/local/bin/php",
    "phpunit.paths": {
    
    },

Here is the output from the Terminal tab:

Executing task: '/Users/main/Documents/projects/blog/vendor/bin/phpunit' --colors=always '/Users/main/Documents/projects/blog/tests/Feature/Api/V1/Controllers/Auth/RegisterControllerTest.php' --filter testRegisterSuccessfully <

This version of PHPUnit is supported on PHP 7.2, PHP 7.3, and PHP 7.4.
You are using PHP 7.1.23 ().
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Here is the output from the Output tab:

Running phpunit with driver: Composer
'/Users/main/Documents/projects/blog/vendor/bin/phpunit' --colors=always --colors=always --colors=always '/Users/main/Documents/projects/blog/tests/Feature/Api/V1/Controllers/Auth/RegisterControllerTest.php'

I should add, that I also tried another phpunit extension - https://github.com/calebporzio/better-phpunit - and I experienced the same issue with that one too - i.e. it is using /usr/bin/php and not /usr/local/bin/php

wave-light avatar May 06 '20 14:05 wave-light

Okey, I see you're running locally and it's running the ComposerDriver. Unfortunately it seems like if the OS is not windows I just use the phpunit executable in that case.

As seen in the output:

'/Users/main/Documents/projects/blog/vendor/bin/phpunit' --colors=always --colors=always --colors=always '/Users/main/Documents/projects/blog/tests/Feature/Api/V1/Controllers/Auth/RegisterControllerTest.php'

So it will use whatever php that /Users/main/Documents/projects/blog/vendor/bin/phpunit finds.

It should be possible to do a complete override though if we use the command setting, could you try this in your settings:

{
    "phpunit.command": "/usr/local/bin/php",

    // Try without `phpunit.phpunit` first then the below one by one
    "phpunit.phpunit": "/Users/main/Documents/projects/blog/vendor/phpunit/phpunit/phpunit",
    "phpunit.phpunit": "/Users/main/Documents/projects/blog/vendor/bin/phpunit"
}

This might also work, but this is really hacking it (skipping the phpunit setting by letting it eval to truthy to allow the command driver to still run):

{
    "phpunit.command": "/usr/local/bin/php /Users/main/Documents/projects/blog/vendor/phpunit/phpunit/phpunit",
    "phpunit.phpunit": " "
}

elonmallin avatar May 06 '20 15:05 elonmallin

Thanks for your reply. I tried your suggestions and it turns out that this line in settings fixes the issue:

"phpunit.command": "/usr/local/bin/php"

So basically it was just a matter of substituting phpunit.command for phpunit.php

Many thanks for your help in resolving this issue

wave-light avatar May 06 '20 16:05 wave-light

Glad that worked :) I'll see if it can be fixed so it just works as expected.

Would you mind sending the OUTPUT again so I can see which command actually works?

elonmallin avatar May 06 '20 19:05 elonmallin

Sorry for the delay - sure it's:

Running phpunit with driver: Command
/usr/local/bin/php '/Users/main/Documents/projects/blog/vendor/bin/phpunit' --colors=always '/Users/main/Documents/projects/blog/tests/Feature/Api/V1/Controllers/Auth/RegisterControllerTest.php'

wave-light avatar May 12 '20 10:05 wave-light