I'm trying to run phpspec but when I do a command phpspec run inside root project folder it just prints:
-bash: phpspec: command not found
But when I do composer show -i it shows it's installed (because it's in package.json):
phpspec/php-diff v1.0.2 A comprehensive li...
phpspec/phpspec 2.5.3 Specification-orie...
phpspec/prophecy v1.6.1 Highly opinionated...
What's wrong?
You probably need to add the path to the executable to your $PATH or, when you call it...call it by the full path to phpspec (something like ./vendor/bin/phpspec run)
Related
I have a fresh symfony project and I need to install phpunit, so I run composer require --dev symfony/phpunit-bridge to install it. It creating symlink to phpunit executable in bin/ folder. But when I'm running tests using bin/phpuinit tests/ command I'm getting message "No composer.json found in the current directory, showing available packages from packagist.org
" and it starting phpunit installation into bin directory and at the end I have bin/.phpunit folder and all the phpunit related files there. Why it installing php unit there and not into vendor, why it's not see composer??? what I'm doing wrong ? Thanks in advance!
What you are using is the symfony/phpunit-bridge
It basically is way more flexible than just phpunit in the vendor folder, allowing to adapt to multiple versions of PHPUnit based on your environment.
Please read the documentation linked above for more details. You're not doing anything wrong!
Another way would be a plain composer require phpunit/phpunit, which would work the "basic"/"standard" way.
I have a problem running phpunit in my laravel 5.5. I already go to vendor/bin and then execute phpunit using my command prompt in windows. But cmd just give another option or flag as shown in the picture below :
I have read laravel 5.5 documentation for unittest. It's said that we just need to execute phpunit {as shown in https://laravel.com/docs/5.5/testing}
Then I tried this :
How to run single test method with phpunit?
phpunit --filter testBasicTest tests\Unit\ExampleTest
As shown below :
BUt it's said that 'cannot open the file'. Then I Tried
phpunit ExampleTest, but still cannot open the file. So what's wrong here...?
Thanks in advance
Note :
Here's my phpunit.xml :
You need to run phpunit without getting inside the bin folder.
Try this:
vendor/bin/phpunit
This will load your phpunit.xml file. Otherwise it cannot load your configuration file. Unless if you don't give spesific path:
vendor/bin/phpunit --configuration /path/to/laravels/phpunit.xml
Just install phpunit through composer:
composer global require phpunit/phpunit
then all you are set to test your laravel project.
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.
I just installed a fresh Laravel 5 project, my first one on this version. PHPUnit is supposed to be out of the box with the framework and every tutorials I saw just say to type phpunit within the project folder to launch the Unit Tests.
I checked and PHPUnit is in the composer.json, I also did a composer install and composer update just in case it wouldn't be here
website(master)$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing phpunit/phpunit (4.6.1)
- Installing phpunit/phpunit (4.6.2)
Downloading: 100%
But it just doesn't work phpunit isn't recognized at all
website(master)$ phpunit
-bash: phpunit: command not found
Seems like nobody got this problem before as I Googled it. I hope I'm not doing any stupid mistake. Any idea or suggestion ? Thanks guys ;)
I didn't install PHPUnit globally and didn't define the path. So for anyone who would have same problem :
composer global require phpunit/phpunit
composer global require phpunit/dbunit
Then you add this to you ~/.bash_profile or ~/.profile
export PATH=~/.composer/vendor/bin:$PATH
This occurs when you don't have phpunit installed globally.
Run this command to use the local version (installed with composer):
vendor/bin/phpunit
in windows machine the command is different please use this command
php vendor/phpunit/phpunit/phpunit
orignal source
You can run this command in cmd before running phpunit command:
doskey phpunit="vendor/bin/phpunit"
And if you are lazy as I am, you can run this one:
doskey pu="vendor/bin/phpunit"
for people who have WINDOWS 7, use the .\vendor\bin\phpunit command instead of ./vendor/bin/phpunit
Run the command
composer config --list --global | grep -w home
You can find the find the [home] with composer path, similar to this one.
[home] /home/example_username/.config/composer
The path ~/.config/composer is where composer global packages are installed. Next run the command...
export PATH=~/.config/composer/vendor/bin:$PATH
I made a permanent link to my phpunit like this
echo 'alias phpunit=vendor/bin/phpunit' >> ~/.bash_aliases
now phpunit is working by itself and stays even after I restart the terminal
Include this line on your composer.json
"phpunit/phpunit": "4.0.*",
Run composer update.
You should be able to run the following command on your Laravel directory.
vendor/bin/phpunit
I have installed PHP Unit and done everything the instructions tell me.
I'm told that I can just run:
$ phpunit
...and it will work. I may need to specify the config file and I can do that.
I have changed the directory to the PHP Unit folder, but nothing.
I am using Mac's Terminal if this means anything.
I have tried (with the error shown):
$ phpunit - $: command not found
phpunit - phpunit: command not found
php phpunit - ...doesn't return an error, but doesn't do return anything
% phpunit - fg: %: no such job
Also, the folder structure is like this:
- phpunit
- php-code-coverage
- php-file-iterator
- php-text-template
- php-timer
- php-token-stream
- phpunit
- phpunit-mock-objects
phpunit.php
- PHPUnit (folder)
- various things inside
... what am I actually running? The outer folder, inner folder or the phpunit.php file?
I must be doing something wrong?
My question: How'd you install PHPUnit? By "hand" (download it and just unzip it), via PEAR, ...?
Try executing (inside the phpunit folder):
./phpunit
Make sure the path where the phpunit executable lies is added to your $PATH variable.
A similiar question on SO on how to install phpunit can be found here, general installation instructions here.