Change path of phpunit command - php

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"

Related

vendor/bin/phpunit not working for Lumen

I'm new to Lumen (and Laravel). I've created a project with Composer and now I'm trying to get PHPUnit to work.
I'm following a book, where it should be possible to run a default passing test by typing vendor/bin/phpunit in the terminal, but it gives the error:
'vendor' is not recognized as an internal or external command,
operable program or batch file
I've checked that the phpunit file is actually there and that phpunit is added as dependency in my composer.json file. I've also tried ./vendor/bin/phpunit and vendor/bin/phpunit/phpunit, but with the same result.
I've searched Google to find a solution, but everyone else seem to have issues when running phpunit (wihout vendor/bin) and the solution is to use the full path vendor/bin/phpunit, but since I'm already doing that, it does not fix my problem.
I'm using PHPStorm on a Windows machine and running the PHP server via PHPStorm. I've not modified the default Lumen project.
Any help is greatly appreciated!
UPDATE:
Trying php vendor/bin/phpunit gives the following error:
You need to set up the project dependencies using the following
commands:
wget http://getcomposer.org/composer.phar
php composer.phar install
I'm not sure what that means, since I've already installed Composer. I used Composer to create the project and I haven't changed the dependencies from the default.
I had the same problem, for Windows it's vendor\bin\phpunit ;)
It turned out that some symlinks and permissions were not installed properly in the default project. I tried deleting the entire vendor/ directory and run composer install.
Now I can run phpunit with the command vendor\bin\phpunit (because I'm running on Windows - thanks Nizarii)
try this:
php vendor/bin/phpunit
Try putting php in front of the phpunit path like so:
php vendor/bin/phpunit

Update to a specific version of PHPUnit

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 )

Can't run phpunit tests from command line

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.

Running PHPUnit in Laravel's Homestead

I'm using Homestead to serve my Laravel application. I'm trying to run PHPUnit. According to the docs:
An example test file is provided in the app/tests directory. After
installing a new Laravel application, simply run phpunit on the
command line to run your tests.
Well, when I'm "simply running" phpunit in my project root (inside the Homestead environment) I get this:
The program 'phpunit' is currently not installed.
Do I need to install PHPUnit separately then? The documentation does not mention it. What am I doing wrong?
You can install it globally on the system using.
composer global require phpunit/phpunit
However, if you need different versions for different projects this can cause issues.
The alternative option is to use the version installed as part of your dependencies by referencing the path to your vendor directory.
./vendor/bin/phpunit
You could even add an alias to your aliases file in your ~/Homestead directory. That way you're always using the phpunit version that is installed with your project dependencies.
alias phpunit=./vendor/bin/phpunit
You'll need to restart the homestead box to make use of the alias.
You can install it globally with:
$ composer global require "phpunit/phpunit=4.4.*"
# then use
$ phpunit
or you can use it with your local composer:
$ composer require "phpunit/phpunit=4.4.*"
# then
$ vendor/bin/phpunit
Since it's a package required for development, Laravel provide PHPunit(require-dev section in composer), you should find it in vendor's folder :
$ your_app/vendor/bin/
You can run the command from the root of your app folder by typing :
$ vendor/bin/phpunit
I hope it will help !

Is there a default location for phpunit? or do I have to keep on exporting path in command line when I wish to use it?

Is there a default location to store the PHPUNIT extension?
I'm using symfony2 and each time I want to use phpunit I have to run this in terminal export PATH=$PATH:/usr/local/zend/apache2/htdocs/symfony/app
Is this normal? or is there a way to make it always work, even if I update and rename my symfony folder to something else.
Is there a way to make it always work?
I'm using zend server ce and snow leopard 10.6+
When I installed PHPUnit using the PEAR installer, it put phpunit in /usr/bin which was already on my path. This way I could type phpunit anywhere to run in the current directory.
What platform?
Ubuntu for me
How did you install PHPUnit?
pear install phpunit/PHPUnit
How does Symphony2 relate here?
Are you trying to run its tests or your own tests that use Symphony?

Categories