vendor/bin/phpunit not working for Lumen - php

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

Related

How to run phpunit in laravel 5.5

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.

bash: laravel: command not found

I am Using my own Machine Kali Linux 2.0 Debian x64 . Now, i have Installed Laravel in my directory structure like
/opt/lampp/htdocs/learning-larvel/
Inside the Learning-laravel folder i have Installed my Laravel files, and also i installed composer. So when i go to http://127.0.0.1/learning-laravel/public . I see a See a White Screen and in Between it is written "Laravel 5", which means the Laravel GUI Setup is fine.
Now, to create a new file for Laravel, when i open my Terminal and type
laravel new xyz
then it gives me a error which says bash: laravel: command not found
Now, how can i fix the error.. I have researched about it by setting PATH to bashrc. But i am not getting it fixed right. Additionally when i type in my command composer -version then also it says bash: composer: command not found but i have Installed composer on the folder learning-laravel itself.
I could also see files like composer.phar there in /opt/lampp/htdocs/learning-larvel/
Any help would be extremely thankful.
As the composer official getting started page points out:
There are in short, two ways to install Composer. Locally as part of
your project, or globally as a system wide executable.
if you wanna do composer -- or laravel -- in command line, you wanna install them globally.
Check out the following links:
https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
https://laravel.com/docs/4.2#install-laravel
I encountered the same problem. Apparently, the composer exists in path ~/.config/composer/vendor/bin when running as super user. Therefore, replacing the paths which were described above by this, and it should work. Hope it helps.

Laravel 5 phpunit is not running tests

I'm been at this for days with no success. Running Laravel 5.1.
As I understand according to the Laravel doc.
An ExampleTest.php file is provided in the tests directory. After installing a new Laravel application, simply run phpunit on the command line to run your tests.
Ok so after running phpunit I found it is not globally installed and is located in vendor/bin/phpunit. Proceeding to run vendor/bin/phpunit gives me a screen with all the command options for phpunit. Its does not actually run any tests.
I searched more and came across a post that mentioned it could be a symlink issue. I followed the instructions in the post with no success. From memory I installed Laravel from composer so the symlink should not be an issue anyway.
These instructions involved deleting various files. I did notice that composer was pulling files from its cache when updating. So I cleared its cache and followed the process again. Still no success.
What are the tests not running? I'm at my wits end. Especially since its is supposed to run easily out the box.
In the end I was not calling the bat file correctly. I was running
C:\localhost\myProject\vendor\bin> phpunit
Instead I needed to run
C:\localhost\myproject> call vendor\bin\phpunit
Hence it now is referencing the phpunit.xml file with the test location information.
You need to install phpunit globally:
composer global require phpunit/phpunit
Then you can run phpunit from your project root.
You could just run the phpunit that comes with the project, just go to your project root and run ./vendor/bin/phpunit, that way the tests will execute the way they should be and you could get feedback in case it fails.
For some reason I haven't figure out yet if you install phpunit globally in your computer you won't get feedback of your tests.

Executing path for PHPUnit

I have installed PHPunit using composer. The application has unit test cases. from my project folder when i do a "phpunit" it gives me an error saying phpunit not found..but if i do a "./vendor/bin/phpunit" it will work. Any idea how to fix this ?
You need to add PHPUnit to your path. Include the ./vendor/bin/phpunit into your PATH environment (to be searched when looking for programs) in your OS.
I had the same problem and got tired of fiddling with PATHs on all my machines, so I wrote a small tool that makes composer behave a bit more like PEAR did:
https://github.com/flack/poser
You can use it to install Composer packages globally by running:
poser require phpunit/phpunit
Afterwards, calling phpunit on the shell will work as expected.

Unable to update Laravel 4 with Composer (Update: bug?)

Today, I pulled down the laravel/laravel repository from Github. I then ran php composer.phar install (as I normally would on my system, with a command window in the project directory). However, when I ran php composer.phar update, I received this error:
Everything installed just fine, and Laravel works as it should.
Any ideas what could be causing this issue?
Edit 1
artisan exists in the root of the project, but it throws an exception when I attempt to run php artisan optimize:
Side Note 1
If I try the alternative method (quicker) of installing Laravel (php composer.phar create-project laravel/laravel), I get the following:
Edit 2
Upon installation, I also get the same error, where it claims it cannot find artisan. Therefore, the installation does not fully complete. I believe that it is stopping when it wants to compile classes (or something to that effect), and then write bootstrap/compiled.php. That file doesn't exist.
Here's the snap from the install:
Edit 3
It seems that Composer is looking for artisan in the drive root (C:\). Why is it doing this? Even if I specify -d on the update, it throws the error. (I picked this up from a hunch - simply copied artisan to the root of the drive and it found it - albeit, it obviously did not run...)
Solution Found:
Composer makes calls to php artisan <command> (as per the instruction in composer.json > scripts), but it does not see what directory it is running from (perhaps because it is an external command?).
So, I solved my initial problem by using an absolute path to artisan in composer.json.
Everything is working now. I just wish I knew how to get Composer to know that it is running from C:\LocalServer\lab\laravel, and not just C:\.
As i can see, your artisan file is missing. Can you post the exact steps on how you install it ?
Also, please follow http://laravel.com/docs/installation and http://niallobrien.me/2013/03/installing-and-updating-laravel-4/
I had this problem today too. My laravel folder inside the vendor was deleted after composer update. I ran composer install again and problem resolved.

Categories