Currently my system installed phpunit is on 4.3.1
Doing phpunit --self-update will update to the latest version of phpunit which is 5.3.* at the moment.
I like to update it to a specific version (4.8.24)
How am I suppose to do this?
Note: I know about the composer option, but I would like to do it on my system installed phpunit.
I ended up changing the phpunit.phar file on my /usr/local/share/phpunit/ folder
This dev environment is set up via this http://vccw.cc/ and it installs phpunit 4.3.1, I need 4.8.24 coz I'm doing wordpress plugin unit testing http://wp-cli.org/docs/plugin-unit-tests/ it says there 4.8.* is required.
So here is what I did.
Download latest 4.8.* version of phpunit here https://phpunit.de/
Rename the phar file to phpunit.phar ( I remove the version section )
Execute this chmod +x phpunit.phar to make the phar file executable
Copy the phpunit.phar to /usr/local/share/phpunit/ folder
Note: I remove the old phpunit.phar ( that is the 4.3.1 ) and replace with this new one
Also their is already a symbolic link on /usr/local/bin/phpunit for /usr/local/share/phpunit/phpunit.phar setup by vccw.
I think changing phpunit version can be done too via modifying the provisioning files provided by vccw but I'm not that in to provisioning scripts, only basic knowledge.
I hope this helps other devs, specially windows devs like me working on unix based dev env.
PS. This dev env is only used by me, it isn't version controlled so its ok for me if I make changes to the dev env directly ( not via provisioning scripts provided by vccw )
Related
I installed phpunit via composer but if I typed phpunit into cmd It would use old phpunit that was installed with PEAR. So I deleted all phpunit files from PEAR folder and It is still trying to use old phpunit path. How do I change the variable path so It uses the new phpunit installed via composer ?
phpunit is not properly install, there might be a version conflict.
Use like this: In windows, if you using wamp and blog being my root folder
c:/wamp/www/blog/>"vendor/bin/phpunit"
I came from frontend stack so I can misanderstand something when I'm learning symfony3.
I downloaded Symfony according to documentation with:
php -r "readfile('https://symfony.com/installer');" > symfony
To make php command available i added some values to the enviroment PATH variable (according to this tutorial: https://seiler.it/installing-symfony-framework-into-xampp-for-windows/ - step 2.3) like this:
c:\xampp\mysql\bin;c:\xampp\php;c:\xampp\php\PEAR;C:\xampp\php\symfony
As you see I'm using xampp for PHP development. I added that last, because i copied that downloaded symfony file to c:\xampp\php\symfony directory.
OK, now if i want to use symfony command, like
symfony new project
I need to go to directory where there is that symfony file and add 'php' before, like
php symfony new project
Because simple 'symfony new project' doesn't work (error msg tells about that command isn't known by Windows). How can i fix it?
In frontend there is something like npm (node package manager) with which you can install library/tool locally in directory or globally (to run it in terminal from any place on the computer). Is there is any equivalent in PHP development? I tried to install this by pear (from mentioned tutorial in step 7), but it installed me symfony 1.x version (and error of running that command was that there is no task like 'new') and i want to learn 3, not 1.
I tried to get composer, but i don't see where can i install there symfony globally.
So, how to run symfony globally? What am I missing?
From this doc:
In Windows, move the symfony file to a directory that's included in the PATH environment variable to create the global command or move it to any other directory convenient for you
idea
Install and use Git Bash. Gives you more futures then the windows CLI.
Performance
To run a ten times more fast environment for Symfony i prefer a Linux OS.
I followed the instructions on the official PHPUnit page to install PHPUnit 6.
composer require --dev phpunit/phpunit ^6.0
However, If I go to the project folder and execute phpunit --version then I get PHPUnit 3.7.21 by Sebastian Bergmann..
Why is PHPUnit 3.7.21 installed instead of PHPUnit 6?
I suppose you have xampp installed? It comes with PHPUnit 3.x.x preinstalled with PEAR which strangely can not be uninstalled with pear uninstall. And since its config is in php root folder, that 3-ish version has priority when running phpunit command (even if you have phpunit installed globally) in CMD or PS. How to fix:
Go to xampp/php folder and delete two files phpunit (with no extension) and phpunit.bat. Usually it's enough to prevent older PHPUnit version from being run but let's be on the safer side:
Go to xampp/php/PEAR dir and delete two folders PHPUnit and PHPUnit2.
Go to Control Panel, then navigate System and Security->System and click "Advanced system settings" link on the left. This will open Advanced tab in System Properties window. Click "Environment Variables" button, then under System Variables select "Path" variable and click "Edit..." button. In the new window, click "New" button and type your path to vendor/bin folder (if you already installed PHPUnit for your project there will be phpunit.bat file). By default for xamp it looks like this: C:\xampp\htdocs\yourprojectname\vendor\bin.
Restart your Command Prompt (or PowerShell) window, then type phpunit --version to see the that it's PHPUnit 6.x.x now.
P.S. (If you want latest PHPUnit do not use ^6.0 in require string, since it will install v6.0.0, write it in composer.lock file that will never update PHPunit to the latest e.g. 6.2.1 version atm). Just use
composer require --dev phpunit/phpunit
to install the latest stable version for your project.
You run your global PHPUnit version which is installed in another folder. To get the installed version you have to go to the vendor/bin folder.
vendor/bin/phpunit --version
PHPUnit 6.0.8 by Sebastian Bergmann and contributors.
In newer versions you can run it with bin/phpunit there should be the executable. When you need another PHP-Version then define it before php74 bin/phpunit.
If you use XAMPP, why don't you update XAMPP version of global PHPUnit to desired.
1.
Read this post, which quickly explains what to do:
StackOverflow post
2.
You can get phar file for version you need here:
proper PHPUnit phar file
3.
Which version of PHPUnit you need depends on your PHP version and you can identify it here:
which phar file version you need
Just click on links: PHPUnit 9 - PHPUnit 8 - PHPUnit 7 - PHPUnit 6 - PHPUnit 5 - PHPUnit 4 and read description explaining which PHP version it works with.
I am trying to run unit tests in a new laravel 5 application, using the phpunit framework. In the root path of my laravel application I ru the following command:
./vendor/bin/phpunit /tests/ExampleTest.php
And then I get the following message:
You need to set up the project dependencies using the following commands:
wget http://getcomposer.org/composer,phar
php composer.phar install
I already have composer installed in may system and I install Laravel 5 using composer. Isn't phpunit installed when I install a new laravel 5 application? If not, how can I install it in a existent laravel 5 application?
I known that I can also install phpunit globaly and resolve the problem. But maybe it will be a duplication since I have all the phpunit code already in may laravel application.
I had the same problem and it had a specific solution that may apply to other people. I store my files in Dropbox, and the vendor/bin/phpunit file should be an symlink like this
$ ls -lo vendor/bin/phpunit
lrwxr-xr-x vendor/bin/phpunit -> ../phpunit/phpunit/phpunit
However, Dropbox will occasionally replace symlinks with the original file, and this will cause the error above. The behaviour is inconsistent, and with relative symlinks seems to break when 2 machines are accessing Dropbox at the same time. Fixing the symlink worked for me or you could make a new symlink directly to the vendor/phpunit/phpunit/phpunit outside of Dropbox and run that.
Edit: Nowadays I exclude Vendor and node_modules from Dropbox - and simply run composer install when necessary. This works really well, and also deals with the hassle of syncing so many files on Dropbox. What you can do is go into the folder and delete all the files. Wait for Dropbox to sync. Then mark the folder as excluded. Finally, run composer install and you get the contents as you need. (Delete + composer install often solves other issues too).
Running composer install did nothing in my case. However, removing vendor folder and then calling composer install fixed it.
You need to have Composer installed and run composer install or composer update in your application to install the different packages listed in your composer.json.
When you install your Laravel application it doesn't install the packages right away.
You can verify the packages are installed by looking in the vendor directory of your application and check that phpunit is in there.
did you install phpunit globally? I recommend you do it.
just type in your laravel's root directory (e.g. /var/www)
cd /var/www
phpunit
if you what to test just one file, you can do something like this:
phpunit tests/ExampleTest.php
Unit Test:
D:\xampp\htdocs\Samplemed\vendor\bin>
phpunit ../../tests/Unit/Company/CompanyUnitTest
Feature Test:
D:\xampp\htdocs\Samplemed\vendor\bin>phpunit
../../tests/Feature/Company/CompanyFeatureTest
Please try this. its working fine.
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