Can someone help me solve a small problem with Windows? I've always used Linux or Apple and have never had this problem.
Issue Type: Bug
phpcs: Request workspace/configuration failed with message: Unable to locate phpcs. Please add phpcs to your global path or use composer dependency manager to install it in your project locally.
VS Code version: Code 1.29.1
OS version: Windows 10
As you say it says phpcs not located which can mean one of two things either you don't have phpcs installed or you haven't specified the path in VS Code
If you do have it installed you may follow these instructions.
Press CTRL + P to open the VS Quick Dialog.
Type ext install phpcs to find the extension.
Press Enter.
Restart VS Code when prompted to.
If you haven't installed it yet.
1. Install Composer.
2. Require PHPCs by typing
composer global require squizlabs/php_codesniffer
in the terminal.
3.Follow steps above.
Information found at Visual Studio
NetBeans does not seem to locate the PHPUnit sources, therefore I can not use autocompletion on for instance PHPUnit_Framework_TestCase.
I run PHPUnit from within NetBeans using a cmd, on Windows using EasyPHP, generated with:
echo #php "%~dp0phpunit.phar" %* > phpunit.cmd
Note that this is the recommended way, older variants are not longer supported as I noticed.
Where are the PHPUnit sources located and how can I tell NetBeans to account for support?
I came up with a workaround:
Install the sources of PHPUnit globally using Composer:
composer global require "phpunit/phpunit=4.7.7"
And finally add the following path to the include directory of the project:
%APPDATA%\Composer\vendor\phpunit\phpunit\src
This will do the trick. However make sure the installation of PHPUnit and the sources are of the same version to prevent complications.
Note that the sources can be installed using a lot of different ways, but keep in mind to use the right include directory.
I have installed Netbeans together with PHPUnit and phpunit-skeleton-generator from homebrew. I can generate a testfile from the terminal by running phpunit-skelgen --test -- "UrlDecoder" classes/UrlDecoder.class.php, however Netbeans refuses when I right-click the file, select tools > Create tests.
This is the error I get:
And this is the output from the log:
"/usr/local/opt/php55/bin/php" "/usr/local/bin/phpunit-skelgen" "--ansi" "generate-test" "--bootstrap=/Users/paulp/Sites/fortv/tests/bootstrap.php" "UrlDecoder" "/Users/paulp/Sites/fortv/classes/UrlDecoder.class.php" "UrlDecoderTest" "/Users/paulp/Sites/fortv/tests/classes/UrlDecoder.classTest.php"
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/phpunit-skeleton-generator/1.2.1/libexec/phpunit-skelgen-1.2.1.phar $*
Done.
Most tutorials and help I find online are for Netbeans 7.x, which makes things harder. I have tried with different bootstrap files and xml files, but no different result. The Output tells me nothing, and nothing happens.
I have googled this for a bit, but found nothing similar to my problem.
The only thing I notice is the --ansi part, which the skeleton generator documentation doesn't seem to offer.
My question: How can I get Netbeans to generate tests using phpunit skeleton generator?
I've installed phpunit on my Mac manually following the manual's instructions (it is pretty easy so you don't need brew script).
Then in Netbeans (8.0.2) preferences (PHP->Frameworks&Tools->PHPUnit) I have set up paths to sctipts.
In the project properties phpunit should be switched on (I know that's obvious). And then Tools->Create tests works just out-of-the-box. :)
However my first experience with phpunit installation was not so funny. So I can understand that users could be frustrated at the begining. It was because I have expected full automation through plugin installation and such things which not worked. That's why I describe full process (phpunit+netbeans on osx)on my [blog][1].
I know it seems like a duplicate, but my problem is different:
Since I installed PHP from source, some folders are not there. I installed PHPUnit the usual way using pear.
Normally I would add /usr/share/php to the include path of the IDE or project and be done. But that folder doesn't exist.
$ updatedb
$ locate phpunit
/usr/local/bin/phpunit
/usr/local/lib/php/.channels/pear.phpunit.de.reg
/usr/local/lib/php/.channels/.alias/phpunit.txt
/usr/local/lib/php/.registry/.channel.pear.phpunit.de
/usr/local/lib/php/.registry/.channel.pear.phpunit.de/phpunit.reg
$ locate PHPUnit
/usr/local/lib/php/doc/PHPUnit
/usr/local/lib/php/doc/PHPUnit/LICENSE
/usr/local/lib/php/doc/PHPUnit/README.md
I tried including /usr/local/lib/php, but I still get "undefined class PHPUnit_Framework_TestCase"
Note that php and phpunit work fine, I only need help with IDE autocompletion.
What can I do?
As of PHPUnit v4 PEAR distribution now contains PHAR version instead of lots of individual files. And there is one file (phpunit) instead of launcher + php files (on installation phpunit.phar gets renamed into phpunit).
Because it now has no .phar extension, IDE will not be able to recognize it accordingly.
The easiest option is to download actual PHAR version of PHPUnit and place in anywhere in your project (e.g. inside vendors folder).
Cannot find PHPUnit in include path is the error message I get when I try to run my code in phpstorm.
In the PHP Settings, my PHP level language is 5.4 (traits, short array syntax, etc.) and interpreter is Name(5.4.7) where Name is user defined.
The error appears when I try to run the code and the exact message is this:
C:\xampp2\php\php.exe C:\Users\DELL\AppData\Local\Temp\ide-phpunit.php --no-configuration
C:\xampp2\htdocs\ft-website
Testing started at 2:34 PM ...
Process finished with exit code 1
Cannot find PHPUnit in include path (.;C:\xampp2\php\PEAR)`
Just encountered this problem myself.
I'm unsure why it is unable to find PHPUnit in the include path (despite the fact that it is there, albeit in all lowercase).
I got around this by changing my IntelliJ Preferences for PHPUnit (under PHP --> PHPUnit). I changed the PHPUnit library settings to Use custom loader and then specified the path to the phpunit executable. On my mac, that was /usr/local/Cellar/php54/5.4.26/bin/phpunit.
UPDATE:
I just discovered that pear now installs PHPUnit as a phar named phpunit. It previously installed the PHPUnit source, which was really nice for reference and code completion in PHPStorm. I think that this is the reason things aren't working any longer with PHPStorm, because it's expecting a php executable and not a php archive.
So, I'm moving away from using pear to install PHPUnit, and I'm using composer instead. This bundles PHPUnit directly as a dependency of my project, which makes it more portable than a system dependency. You'll need to add vendor/phpunit/phpunit as a PHP include path in your PHPStorm preferences. This will serve two purposes:
PHPStorm can find the phpunit executable now
PHPStorm will index all the PHPUnit classes now, so you'll get auto-complete. Yay!
To do this, go to Languages and Frameworks in the PhpStorm settings.
If you click on PHP, on the right you have your include paths
I had this problem after adding PHPUnit via composer.
I fixed this by choosing use custom autoloader in Settings -> Languages and Frameworks -> PHP -> PHPUnit, then adding /vendor/autoload.php as the location of the custom autoloader.
In addition to Ben's answer, in phpStorm 7.1.3 it works by specifying the phpunit.phar location under the "use custom loader" option, for example:
"Path to script: /usr/share/php/phpunit.phar"
This is the way to do it without using composer, and using your global phpunit.
Phpunit now comes with a phar file. My path was /usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar
PhpStorm Preferences -> Path to phpunit.phar -> select the phpunit phar
That's all, good stuff.
I had this same problem for PHPStorm 2017 using Vagrant. First go to Settings -> Languages and Frameworks -> PHP and Add a remote interpreter, then go to Settings -> Languages and Frameworks -> PHP -> PHPUnit click the + on top and click by Remote Interpreter. If you're using Composer autoloader, then enter your full Vagrant path to your autoloader file.
For future readers, to fix the same issue when using PHPStorm + Vagrant + PHPUnit by defining path to the global phpunit.phar (not composer)
While the tests runned successfully, I was missing the code completion. I had confirmed that phpunit was in the PATH on my local machine, and to make sure, I had added /usr/local/bin to the PHP Include paths in PHP Settings. Still no code completion.
The reason: PHPstorm was looking for phpunit.phar, not just phpunit. To fix, on my local machine I established a symlink phpunit.phar pointing to phpunit:
$ cd /usr/local/bin/
$ sudo ln -s phpunit phpunit.phar
Then I reindexed the project, and code completion started working.
For those that are looking at it in 2020, starting from PHPStorm 2019 this is under:
Languages and Frameworks->PHP->Test Frameworks
Choose to add a new library
Select "PHPUnit"
Select "Path to phpunit.phar" radio
You'll have an automatic option to download PHPUnit